-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
120 lines (102 loc) · 5.43 KB
/
config.py
File metadata and controls
120 lines (102 loc) · 5.43 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
"""
Configuration for Crypto Backtesting Bot
=========================================
Data Source: Coinalyze API (free, aggregated across 10+ exchanges)
Fallback: Bybit API for exchange-specific data
"""
import os
from dotenv import load_dotenv
load_dotenv()
# ─────────────────────────────────────────────
# API KEYS
# ─────────────────────────────────────────────
# Get your free key: https://coinalyze.net/account/api-key/
COINALYZE_API_KEY = os.getenv("COINALYZE_API_KEY", "YOUR_API_KEY_HERE")
# Bybit (no key needed for public market data)
BYBIT_BASE_URL = "https://api.bybit.com"
# ─────────────────────────────────────────────
# COINALYZE API CONFIG
# ─────────────────────────────────────────────
COINALYZE_BASE_URL = "https://api.coinalyze.net/v1"
# Symbol format: {BASE}{QUOTE}_PERP.{EXCHANGE_CODE}
# .A = Aggregated across ALL exchanges (Binance, Bybit, OKX, Deribit, BitMEX, etc.)
# .6 = Bybit only
# Exchange codes: 0=BitMEX, 1=Binance, 2=Bitfinex, 4=Deribit, 6=Bybit, 7=Huobi, B=OKX
EXCHANGE_SUFFIX = ".A" # Aggregated (recommended)
# ─────────────────────────────────────────────
# SYMBOLS TO BACKTEST
# ─────────────────────────────────────────────
# Major coins - perps (USDT-margined) aggregated
SYMBOLS = {
"BTC": {
"perp": f"BTCUSDT_PERP{EXCHANGE_SUFFIX}",
"spot": "BTCUSDT.C", # Coinbase spot (for CVD divergence)
},
"ETH": {
"perp": f"ETHUSDT_PERP{EXCHANGE_SUFFIX}",
"spot": "ETHUSDT.C",
},
"SOL": {
"perp": f"SOLUSDT_PERP{EXCHANGE_SUFFIX}",
"spot": "SOLUSDT.C",
},
}
# Default symbol for quick testing
DEFAULT_SYMBOL = "BTC"
# ─────────────────────────────────────────────
# DATA SETTINGS
# ─────────────────────────────────────────────
# Intervals: 1min, 5min, 15min, 30min, 1hour, 2hour, 4hour, 6hour, 12hour, daily
DEFAULT_INTERVAL = "1hour"
DEFAULT_LOOKBACK_DAYS = 62 # How many days of history to fetch
# NOTE: Coinalyze keeps ~1500-2000 bars for intraday. Daily data is unlimited.
# For 4h candles: ~1500 bars ≈ 250 days
# For 1h candles: ~1500 bars ≈ 62 days
# For daily candles: unlimited history
# ─────────────────────────────────────────────
# STRATEGY PARAMETERS
# ─────────────────────────────────────────────
STRATEGY_PARAMS = {
# ── OI Signal ──
"oi_change_period": 6, # Bars to measure OI % change
"oi_spike_threshold": 0.05, # 5% OI increase = significant
"oi_drop_threshold": -0.03, # 3% OI decrease = significant
# ── CVD Signal ──
"cvd_lookback": 12, # Bars for CVD trend
"cvd_divergence_bars": 6, # Bars to check price vs CVD divergence
# ── Long/Short Ratio Signal ──
"ls_extreme_long": 0.65, # Above this = crowded long (bearish)
"ls_extreme_short": 0.35, # Below this = crowded short (bullish)
"ls_lookback": 6, # Bars for L/S ratio smoothing
# ── Funding Rate Signal ──
"funding_extreme_pos": 0.0005, # Very positive = overheated longs
"funding_extreme_neg": -0.0003,# Very negative = overheated shorts
# ── Liquidation Signal ──
"liq_spike_multiplier": 2.0, # Liq volume > 2x avg = spike
# ── Composite Score ──
"signal_weights": {
"oi": 0.25,
"cvd": 0.25,
"long_short": 0.20,
"funding": 0.15,
"liquidation": 0.15,
},
"entry_threshold": 0.15, # Score > 0.15 → entry signal
"exit_threshold": 0.0, # Score crosses 0 → exit
# ── Risk Management ──
"stop_loss_pct": 0.01, # 1% stop loss
"take_profit_pct": 0.05, # 3% take profit (3:1 R:R)
"position_size_pct": 1, # 100% of equity → 1% * 100% = 1% risk
"max_positions": 1, # Max simultaneous positions per symbol
}
# ─────────────────────────────────────────────
# BACKTESTING SETTINGS
# ─────────────────────────────────────────────
INITIAL_CAPITAL = 10_000 # Starting capital in USD
COMMISSION_PCT = 0.0006 # 0.06% taker fee (Bybit perps)
SLIPPAGE_PCT = 0 # 0.02% slippage estimate
# ─────────────────────────────────────────────
# OUTPUT SETTINGS
# ─────────────────────────────────────────────
DATA_DIR = "data" # Cached data directory
RESULTS_DIR = "results" # Backtest results output