-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
123 lines (104 loc) · 3.75 KB
/
Copy pathconfig.py
File metadata and controls
123 lines (104 loc) · 3.75 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
"""
config.py
---------
Loads and validates all configuration from environment variables.
Single source of truth for all agent parameters.
"""
import os
from dataclasses import dataclass
from dotenv import load_dotenv
load_dotenv()
def _get(key: str, default=None, cast=str, required=False):
val = os.getenv(key, default)
if required and val is None:
raise EnvironmentError(f"Required environment variable '{key}' is not set.")
if val is None:
return None
try:
return cast(val)
except (ValueError, TypeError) as e:
raise ValueError(f"Invalid value for {key}='{val}': {e}")
@dataclass
class Config:
# API
HL_API_KEY: str
HL_API_SECRET: str
HL_WALLET_ADDRESS: str
HL_REST_URL: str
HL_WS_URL: str
# Trading
SYMBOL: str
PRIMARY_TF: int
FILTER_TF: int
ENTRY_TF: int
CANDLE_LOOKBACK: int
LEVERAGE: int
# Risk
MAX_POSITION_SIZE_USD: float
RISK_PER_TRADE_PCT: float
STOP_LOSS_PCT: float
TAKE_PROFIT_PCT: float
DAILY_LOSS_CAP_USD: float
MAX_OPEN_POSITIONS: int
# Indicators
RSI_PERIOD: int
RSI_OVERSOLD: float
RSI_OVERBOUGHT: float
MACD_FAST: int
MACD_SLOW: int
MACD_SIGNAL: int
# Logging
LOG_FILE_PATH: str
LOG_LEVEL: str
LOG_MAX_SIZE_MB: int
LOG_BACKUP_COUNT: int
# MCP
MCP_HOST: str
MCP_PORT: int
MCP_AUTH_TOKEN: str
# Agent
POLL_INTERVAL_SECONDS: int
DRY_RUN: bool
@classmethod
def from_env(cls) -> "Config":
return cls(
# API
HL_API_KEY=_get("HL_API_KEY", "", required=False),
HL_API_SECRET=_get("HL_API_SECRET", "", required=False),
HL_WALLET_ADDRESS=_get("HL_WALLET_ADDRESS", "0x0000000000000000000000000000000000000000"),
HL_REST_URL=_get("HL_REST_URL", "https://api.hyperliquid.xyz"),
HL_WS_URL=_get("HL_WS_URL", "wss://api.hyperliquid.xyz/ws"),
# Trading
SYMBOL=_get("SYMBOL", "BTC"),
PRIMARY_TF=_get("PRIMARY_TF", "15", cast=int),
FILTER_TF=_get("FILTER_TF", "60", cast=int),
ENTRY_TF=_get("ENTRY_TF", "5", cast=int),
CANDLE_LOOKBACK=_get("CANDLE_LOOKBACK", "100", cast=int),
LEVERAGE=_get("LEVERAGE", "5", cast=int),
# Risk
MAX_POSITION_SIZE_USD=_get("MAX_POSITION_SIZE_USD", "500", cast=float),
RISK_PER_TRADE_PCT=_get("RISK_PER_TRADE_PCT", "1.0", cast=float),
STOP_LOSS_PCT=_get("STOP_LOSS_PCT", "1.5", cast=float),
TAKE_PROFIT_PCT=_get("TAKE_PROFIT_PCT", "3.0", cast=float),
DAILY_LOSS_CAP_USD=_get("DAILY_LOSS_CAP_USD", "100.0", cast=float),
MAX_OPEN_POSITIONS=_get("MAX_OPEN_POSITIONS", "3", cast=int),
# Indicators
RSI_PERIOD=_get("RSI_PERIOD", "14", cast=int),
RSI_OVERSOLD=_get("RSI_OVERSOLD", "30", cast=float),
RSI_OVERBOUGHT=_get("RSI_OVERBOUGHT", "70", cast=float),
MACD_FAST=_get("MACD_FAST", "12", cast=int),
MACD_SLOW=_get("MACD_SLOW", "26", cast=int),
MACD_SIGNAL=_get("MACD_SIGNAL", "9", cast=int),
# Logging
LOG_FILE_PATH=_get("LOG_FILE_PATH", "logs/trades.log"),
LOG_LEVEL=_get("LOG_LEVEL", "INFO"),
LOG_MAX_SIZE_MB=_get("LOG_MAX_SIZE_MB", "10", cast=int),
LOG_BACKUP_COUNT=_get("LOG_BACKUP_COUNT", "5", cast=int),
# MCP
MCP_HOST=_get("MCP_HOST", "127.0.0.1"),
MCP_PORT=_get("MCP_PORT", "9000", cast=int),
MCP_AUTH_TOKEN=_get("MCP_AUTH_TOKEN", "changeme"),
# Agent
POLL_INTERVAL_SECONDS=_get("POLL_INTERVAL_SECONDS", "10", cast=int),
DRY_RUN=_get("DRY_RUN", "true").lower() in ("true", "1", "yes"),
)