-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
146 lines (125 loc) · 5.37 KB
/
Copy pathconfig.py
File metadata and controls
146 lines (125 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
Configuration management for Hyperliquid trading bot
"""
import os
from typing import Dict, Any
from dataclasses import dataclass
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
@dataclass
class APIConfig:
"""API configuration"""
api_key: str
secret_key: str
base_url: str = "https://api.hyperliquid.xyz"
websocket_url: str = "wss://api.hyperliquid.xyz/ws"
@dataclass
class TradingConfig:
"""Trading configuration"""
default_symbol: str = "ETH"
default_side: str = "long"
default_size: float = 0.1
default_size_usdc: float = 100.0 # Default size in USDC
default_leverage: float = 1.0
max_position_size: float = 1.0
max_position_size_usdc: float = 1000.0 # Max position in USDC
stop_loss_percentage: float = 5.0
take_profit_percentage: float = 10.0
use_usdc_sizing: bool = True # Use USDC amounts instead of token amounts
@dataclass
class MonitoringConfig:
"""Monitoring configuration"""
monitoring_interval: int = 5
enable_websocket: bool = True
max_price_history: int = 1000
max_volume_history: int = 100
@dataclass
class RiskConfig:
"""Risk management configuration"""
max_daily_loss: float = 100.0
max_position_percentage: float = 0.1 # 10% of account
max_leverage: float = 10.0
emergency_stop_loss: float = 20.0 # 20% loss triggers emergency stop
class Config:
"""Main configuration class"""
def __init__(self):
self.api = APIConfig(
api_key=os.getenv('HYPERLIQUID_API_KEY', ''),
secret_key=os.getenv('HYPERLIQUID_SECRET_KEY', ''),
base_url=os.getenv('HYPERLIQUID_BASE_URL', 'https://api.hyperliquid.xyz')
)
self.trading = TradingConfig(
default_symbol=os.getenv('DEFAULT_SYMBOL', 'ETH'),
default_side=os.getenv('DEFAULT_SIDE', 'long'),
default_size=float(os.getenv('DEFAULT_SIZE', '0.1')),
default_leverage=float(os.getenv('DEFAULT_LEVERAGE', '1.0')),
max_position_size=float(os.getenv('MAX_POSITION_SIZE', '1.0')),
stop_loss_percentage=float(os.getenv('STOP_LOSS_PERCENTAGE', '5.0')),
take_profit_percentage=float(os.getenv('TAKE_PROFIT_PERCENTAGE', '10.0'))
)
self.monitoring = MonitoringConfig(
monitoring_interval=int(os.getenv('MONITORING_INTERVAL', '5')),
enable_websocket=os.getenv('ENABLE_WEBSOCKET', 'true').lower() == 'true'
)
self.risk = RiskConfig(
max_daily_loss=float(os.getenv('MAX_DAILY_LOSS', '100.0')),
max_position_percentage=float(os.getenv('MAX_POSITION_PERCENTAGE', '0.1')),
max_leverage=float(os.getenv('MAX_LEVERAGE', '10.0')),
emergency_stop_loss=float(os.getenv('EMERGENCY_STOP_LOSS', '20.0'))
)
def validate(self) -> bool:
"""Validate configuration"""
if not self.api.api_key or not self.api.secret_key:
print("Error: API key and secret key must be provided")
return False
if self.trading.default_size <= 0:
print("Error: Default size must be positive")
return False
if self.trading.default_leverage <= 0 or self.trading.default_leverage > self.risk.max_leverage:
print(f"Error: Leverage must be between 0 and {self.risk.max_leverage}")
return False
if self.trading.stop_loss_percentage <= 0 or self.trading.take_profit_percentage <= 0:
print("Error: Stop loss and take profit percentages must be positive")
return False
return True
def to_dict(self) -> Dict[str, Any]:
"""Convert configuration to dictionary"""
return {
"api": {
"api_key": self.api.api_key[:8] + "..." if self.api.api_key else None,
"secret_key": "***" if self.api.secret_key else None,
"base_url": self.api.base_url
},
"trading": {
"default_symbol": self.trading.default_symbol,
"default_side": self.trading.default_side,
"default_size": self.trading.default_size,
"default_leverage": self.trading.default_leverage,
"max_position_size": self.trading.max_position_size,
"stop_loss_percentage": self.trading.stop_loss_percentage,
"take_profit_percentage": self.trading.take_profit_percentage
},
"monitoring": {
"monitoring_interval": self.monitoring.monitoring_interval,
"enable_websocket": self.monitoring.enable_websocket
},
"risk": {
"max_daily_loss": self.risk.max_daily_loss,
"max_position_percentage": self.risk.max_position_percentage,
"max_leverage": self.risk.max_leverage,
"emergency_stop_loss": self.risk.emergency_stop_loss
}
}
def print_config(self):
"""Print current configuration"""
config_dict = self.to_dict()
print("Current Configuration:")
print("=" * 50)
for section, values in config_dict.items():
print(f"\n{section.upper()}:")
for key, value in values.items():
print(f" {key}: {value}")
print("=" * 50)
# Global config instance
config = Config()