Repository navigation
Expand file tree
/
Copy pathconfig.py
More file actions
68 lines (58 loc) · 3.15 KB
/
Copy pathconfig.py
File metadata and controls
68 lines (58 loc) · 3.15 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
import os
from pydantic import BaseModel, Field
from typing import Optional, List, Tuple
from dotenv import load_dotenv
load_dotenv()
class MexcCredentials(BaseModel):
api_key: str = Field(..., description="MEXC API Key")
secret_key: str = Field(..., description="MEXC Secret Key")
passphrase: Optional[str] = Field(None, description="MEXC Passphrase if required")
class TradingParams(BaseModel):
symbol: str = Field(..., description="Trading pair symbol (e.g., XRPUSDT)")
quantity: float = Field(..., gt=0, description="Order quantity (in USDT if quantity_is_usdt=True, otherwise base currency)")
quantity_is_usdt: bool = Field(default=True, description="Whether quantity is specified in USDT value")
stop_loss_percentage: float = Field(default=2.0, ge=0.1, le=50.0, description="Stop loss percentage")
take_profit_percentage: Optional[float] = Field(None, ge=0.1, le=100.0, description="Take profit percentage")
max_orders_per_day: int = Field(default=10, ge=1, le=100, description="Maximum orders per day")
class TimeWindow(BaseModel):
start_time: str = Field(..., description="Start time in HH:MM format")
end_time: str = Field(..., description="End time in HH:MM format")
timezone: str = Field(default="UTC", description="Timezone for trading window")
class BotConfig(BaseModel):
credentials: MexcCredentials
trading_params: TradingParams
trading_windows: List[TimeWindow] = Field(default=[], description="Active trading time windows")
dry_run: bool = Field(default=True, description="Enable dry run mode for testing")
log_level: str = Field(default="INFO", description="Logging level")
rate_limit_requests_per_second: float = Field(default=10.0, description="Rate limiting")
class Config:
env_file = ".env"
def load_config() -> BotConfig:
"""Load configuration from environment variables and defaults"""
credentials = MexcCredentials(
api_key=os.getenv("MEXC_API_KEY", ""),
secret_key=os.getenv("MEXC_SECRET_KEY", ""),
passphrase=os.getenv("MEXC_PASSPHRASE", "")
)
trading_params = TradingParams(
symbol=os.getenv("TRADING_SYMBOL", "XRPUSDT"),
quantity=float(os.getenv("TRADING_QUANTITY", "2.0")),
quantity_is_usdt=os.getenv("QUANTITY_IS_USDT", "true").lower() == "true",
stop_loss_percentage=float(os.getenv("STOP_LOSS_PERCENTAGE", "2.0")),
take_profit_percentage=float(os.getenv("TAKE_PROFIT_PERCENTAGE", "5.0")) if os.getenv("TAKE_PROFIT_PERCENTAGE") else None,
)
trading_windows = []
if os.getenv("TRADING_START_TIME") and os.getenv("TRADING_END_TIME"):
trading_windows.append(TimeWindow(
start_time=os.getenv("TRADING_START_TIME"),
end_time=os.getenv("TRADING_END_TIME"),
timezone=os.getenv("TRADING_TIMEZONE", "UTC")
))
return BotConfig(
credentials=credentials,
trading_params=trading_params,
trading_windows=trading_windows,
dry_run=os.getenv("DRY_RUN", "true").lower() == "true",
log_level=os.getenv("LOG_LEVEL", "INFO"),
rate_limit_requests_per_second=float(os.getenv("RATE_LIMIT_RPS", "10.0"))
)