-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmulti_arb_bot.py
More file actions
68 lines (53 loc) · 1.72 KB
/
Copy pathmulti_arb_bot.py
File metadata and controls
68 lines (53 loc) · 1.72 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
"""
Multi-asset arbitrage with candle-window entry + BTC volatility guard.
Strategy:
1. Hub discovers BTC, ETH, SOL on 15m timeframe
2. Per-asset strategies calculate arb spread (UP vs DOWN pricing gap)
3. Candle gate: only trade in first 300s of 900s (15m) candle
4. BTC volatility guard: if BTC.roc(5) > 5% => skip ALL trades
5. Entry: when spread > threshold AND BTC calm => buy undervalued side
6. Output: per-strategy stats table (P&L, trades, win rate)
Usage:
python examples/multi_arb_bot.py
"""
import polyalpha
hub = polyalpha.BotHub("BTC", "15m", default_balance=1000)
def btc_is_calm(ctx, max_roc_pct=5.0):
roc = ctx.indicators.roc(5)
if roc is None:
return True
return abs(roc) < max_roc_pct
def calc_spread(ctx):
if ctx.price.up and ctx.price.down:
return abs(ctx.price.up - ctx.price.down) / max(ctx.price.up, ctx.price.down) * 100
return 0.0
@hub.strategy("btc_arb")
def btc_arb(ctx):
if not btc_is_calm(ctx):
return
if ctx.seconds_in > 300:
return
spread = calc_spread(ctx)
if spread > 2.0 and ctx.price.up > 0.9:
ctx.buy_in_window("UP", 30, 0, 300)
@hub.strategy("eth_arb")
def eth_arb(ctx):
if not btc_is_calm(ctx):
return
if ctx.seconds_in > 300:
return
spread = calc_spread(ctx)
if spread > 3.0 and ctx.price.down < 0.15:
ctx.buy_in_window("DOWN", 25, 0, 300)
@hub.strategy("sol_arb")
def sol_arb(ctx):
if not btc_is_calm(ctx):
return
if ctx.seconds_in > 300:
return
spread = calc_spread(ctx)
if spread > 2.5:
side = "UP" if ctx.price.up > ctx.price.down else "DOWN"
ctx.buy_in_window(side, 20, 0, 300)
hub.run()
print(f"\nFinal stats: {hub.stats}")