-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_imbalance.py
More file actions
56 lines (44 loc) · 1.73 KB
/
check_imbalance.py
File metadata and controls
56 lines (44 loc) · 1.73 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
#!/usr/bin/env python3
"""Check position imbalance calculation."""
import asyncio
from decimal import Decimal
from dotenv import load_dotenv
import os
load_dotenv('.env')
os.environ['NADO_MODE'] = 'MAINNET'
import sys
sys.path.insert(0, '.')
from hedge.DN_pair_eth_sol_nado import DNPairBot
async def test():
bot = DNPairBot(
target_notional=Decimal('100'),
iterations=1,
sleep_time=0
)
# Test the balanced calculation directly
eth_price = Decimal('2757')
sol_price = Decimal('115.86')
eth_tick = Decimal('0.001')
sol_tick = Decimal('0.1')
print('Testing calculate_balanced_quantities:')
eth_qty, sol_qty, imbalance = bot.calculate_balanced_quantities(
Decimal('100'), eth_price, sol_price, eth_tick, sol_tick
)
eth_notional = eth_qty * eth_price
sol_notional = sol_qty * sol_price
print(f'ETH: {eth_qty} × ${eth_price} = ${eth_notional:.2f}')
print(f'SOL: {sol_qty} × ${sol_price} = ${sol_notional:.2f}')
print(f'Imbalance: {imbalance * 100:.4f}%')
if eth_notional > 0:
print(f'Ratio: {sol_notional/eth_notional:.2f}x')
# Check what the old calculation would give
print('\n--- Old Calculation (for comparison) ---')
old_eth_qty = (Decimal('100') / eth_price).quantize(eth_tick)
old_sol_qty = (Decimal('100') / sol_price).quantize(sol_tick)
old_eth_notional = old_eth_qty * eth_price
old_sol_notional = old_sol_qty * sol_price
old_imbalance = abs(old_sol_notional - old_eth_notional) / old_eth_notional
print(f'ETH: {old_eth_qty} × ${eth_price} = ${old_eth_notional:.2f}')
print(f'SOL: {old_sol_qty} × ${sol_price} = ${old_sol_notional:.2f}')
print(f'Imbalance: {old_imbalance * 100:.4f}%')
asyncio.run(test())