-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvalidate_config.py
More file actions
executable file
·173 lines (135 loc) · 5.16 KB
/
validate_config.py
File metadata and controls
executable file
·173 lines (135 loc) · 5.16 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python3
"""
Validate config.json for common errors and provide recommendations
"""
import json
import sys
from pathlib import Path
from app import Config, load_json
CONFIG_PATH = Path("data/config.json")
def validate_config():
"""Validate configuration file"""
print("=" * 60)
print("Configuration Validation")
print("=" * 60)
print()
# Load config
print(f"Loading {CONFIG_PATH}...")
try:
config = load_json(CONFIG_PATH, Config)
if not config:
print("❌ Failed to load config.json")
return False
except Exception as e:
print(f"❌ Error loading config: {e}")
return False
print("✓ Config file loaded successfully")
print()
# Validation checks
errors = []
warnings = []
# Check 1: Buy ladder
print("Checking buy ladder...")
if not config.buy_ladder:
errors.append("Buy ladder is empty")
else:
print(f" ✓ {len(config.buy_ladder)} buy rungs defined")
# Check strictly increasing
drops = [r.drop_pct for r in config.buy_ladder]
if drops != sorted(drops):
errors.append("Buy ladder drop_pct must be strictly increasing")
# Check amounts
total_buy = sum(r.usdt_amount for r in config.buy_ladder)
print(f" ✓ Total potential buy: ${total_buy:,.2f} USDT")
if total_buy > 10000:
warnings.append(f"Large total buy amount: ${total_buy:,.2f}")
# Display ladder
for i, rung in enumerate(config.buy_ladder):
print(f" Rung {i}: Drop {rung.drop_pct}% → Buy ${rung.usdt_amount:.2f}")
print()
# Check 2: Sell ladder
print("Checking sell ladder...")
if not config.sell_ladder:
errors.append("Sell ladder is empty")
else:
print(f" ✓ {len(config.sell_ladder)} sell rungs defined")
# Check strictly increasing
rises = [r.rise_pct for r in config.sell_ladder]
if rises != sorted(rises):
errors.append("Sell ladder rise_pct must be strictly increasing")
# Check percentages sum
total_sell_pct = sum(r.pct_btc for r in config.sell_ladder)
print(f" ✓ Total sell allocation: {total_sell_pct}%")
if total_sell_pct > 100:
errors.append(f"Sell ladder pct_btc sum ({total_sell_pct}%) exceeds 100%")
elif total_sell_pct < 80:
warnings.append(f"Sell ladder only sells {total_sell_pct}% of position")
# Display ladder
for i, rung in enumerate(config.sell_ladder):
print(f" Rung {i}: Rise {rung.rise_pct}% → Sell {rung.pct_btc}% of BTC")
print()
# Check 3: Exposure limits
print("Checking exposure limits...")
if config.max_btc_exposure_pct > 90:
warnings.append(f"High max exposure: {config.max_btc_exposure_pct}%")
print(f" ✓ Max BTC exposure: {config.max_btc_exposure_pct}%")
print(f" ✓ Max buy rungs: {config.max_buy_rungs}")
print()
# Check 4: Timing
print("Checking timing parameters...")
print(f" ✓ Loop interval: {config.loop_seconds}s")
print(f" ✓ Cooldown: {config.cooldown_seconds}s")
if config.loop_seconds < 30:
warnings.append(f"Short loop interval ({config.loop_seconds}s) may hit rate limits")
if config.cooldown_seconds < 60:
warnings.append(f"Short cooldown ({config.cooldown_seconds}s) may cause rapid trading")
print()
# Check 5: Fees and offsets
print("Checking fees and offsets...")
print(f" ✓ Limit offset: {config.limit_offset_bps} bps")
print(f" ✓ Fee buffer: {config.fee_buffer_bps} bps")
if config.fee_buffer_bps < 50:
warnings.append("Fee buffer may be too small to guarantee profit")
print()
# Check 6: Trading status
print("Checking trading status...")
print(f" {'✓' if config.enabled_trading else '⚠'} Trading: {'ENABLED' if config.enabled_trading else 'DISABLED'}")
print(f" {'✓' if config.paper_mode else '⚠'} Mode: {'PAPER' if config.paper_mode else 'LIVE'}")
if not config.paper_mode:
warnings.append("LIVE TRADING MODE - real money at risk!")
print()
# Summary
print("=" * 60)
if errors:
print("❌ ERRORS FOUND:")
for err in errors:
print(f" - {err}")
print()
if warnings:
print("⚠️ WARNINGS:")
for warn in warnings:
print(f" - {warn}")
print()
if not errors and not warnings:
print("✅ Configuration is valid!")
print()
print("Summary:")
print(f" - {len(config.buy_ladder)} buy rungs")
print(f" - {len(config.sell_ladder)} sell rungs")
print(f" - Max exposure: {config.max_btc_exposure_pct}%")
print(f" - Mode: {'PAPER' if config.paper_mode else 'LIVE'}")
print()
print("=" * 60)
return len(errors) == 0
if __name__ == "__main__":
try:
valid = validate_config()
sys.exit(0 if valid else 1)
except KeyboardInterrupt:
print("\n\nValidation interrupted")
sys.exit(1)
except Exception as e:
print(f"\n❌ Error: {e}")
import traceback
traceback.print_exc()
sys.exit(1)