moving to extravm

This commit is contained in:
2026-05-08 03:02:02 +00:00
parent e4bdb3f6a0
commit f5f43be1a1
4 changed files with 517 additions and 447 deletions

43
main.py
View File

@@ -1,3 +1,20 @@
'''
Atwater Trading: Perpetual Futures Funding Rate
TODO:
- Update switch signal to account for diff in leverage (right now its just pure rate)
- Can do by calculating based on expected alpha in dollar terms and then back over the collateral for percent - be careful fees are correctly accounted for in dollar terms.
- WS Stability
- Make sure every WS has reconnect and can handle failure scenarios
- Create health service (or add to orchestrator) to check that WS outputs are recent and not delayed, kill algo and alert if delayed.
- GUI
- NG basic dashboard to show algo summary, bfr, grid of trades/positions/orders/pnl, graph of ratios, prices, orders, fills, pnl, etc.
- Infra
- Move off AWS to a cheaper option (NYCServers, QuantVPS)
- Shutdown old VPS in NYC
'''
from x10.utils.http import WrappedApiResponse
from x10.perpetual.trading_client.trading_client import PerpetualTradingClient
import asyncio
@@ -28,6 +45,7 @@ import modules.aster_auth as aster_auth
import modules.extended_auth as extend_auth
import modules.structs as structs
### Clients ###
EXTEND_CLIENT: PerpetualTradingClient
CON: AsyncContextManager
@@ -535,6 +553,10 @@ async def handle_order_updates(exch: str, local_open_orders: list[dict], ws_open
if order_update_status in ['CANCELLED','CANCELED']:
logging.info(f'{exch} ORDER CANCELLED: {order_id}')
local_open_orders.pop(idx)
if exch=='ASTER':
Aster.cancel_request_pending = False
else:
Extend.cancel_request_pending = False
# utils.send_tg_alert(f'FR_ALGO - {exch} REJECTED ({order_id})')
elif order_update_status in ['EXPIRED','REJECTED']:
logging.info(f'{exch} ORDER REJECTED or EXPIRED: {order_id}')
@@ -542,9 +564,11 @@ async def handle_order_updates(exch: str, local_open_orders: list[dict], ws_open
if exch=='ASTER':
Aster.just_rejected_count = Aster.just_rejected_count + 1
Config.Config.Price_Worsener_Aster=1
Aster.cancel_request_pending = False
else:
Extend.just_rejected_count = Extend.just_rejected_count + 1
# Config.Config.Price_Worsener_Extend=1
Extend.cancel_request_pending = False
if Aster.just_rejected_count > 1 or Extend.just_rejected_count > 1:
time.sleep(1)
Aster.just_rejected_count = 0
@@ -556,8 +580,10 @@ async def handle_order_updates(exch: str, local_open_orders: list[dict], ws_open
if exch=='ASTER':
await get_aster_notional_position(resp=ws_pos_updates)
Last_Aster_Fill_Time_Ts = datetime.now().timestamp()*1000
Aster.cancel_request_pending = False
else:
await get_extend_notional(resp=ws_pos_updates)
Extend.cancel_request_pending = False
utils.send_tg_alert(f'FR_ALGO - {exch} PARTIALLY FILLED ({order_id})')
elif order_update_status in ['FILLED']:
logging.info(f'{exch} ORDER FILLED: {order_id}')
@@ -567,8 +593,10 @@ async def handle_order_updates(exch: str, local_open_orders: list[dict], ws_open
# await aster_cancel_all_orders()
await get_aster_notional_position(resp=ws_pos_updates)
Last_Aster_Fill_Time_Ts = datetime.now().timestamp()*1000
Aster.cancel_request_pending = False
else:
await extend_cancel_all_orders()
Extend.cancel_request_pending = False
await get_extend_notional()
utils.send_tg_alert(f'FR_ALGO - {exch} FILLED ({order_id})')
else:
@@ -796,6 +824,9 @@ async def get_extend_exch_info(symbol_override: str | None = None):
### CANCEL ORDERS ###
async def aster_cancel_all_orders():
global Aster
global Aster_Open_Orders
cancel_all_open_orders = {
"url": "/fapi/v3/allOpenOrders",
"method": "DELETE",
@@ -803,7 +834,12 @@ async def aster_cancel_all_orders():
'symbol': Aster.symbol,
}
}
r = await aster_auth.post_authenticated_url(cancel_all_open_orders)
r: dict = await aster_auth.post_authenticated_url(cancel_all_open_orders) # ty:ignore[invalid-assignment]
if r.get('code') == 200 and Aster_Open_Orders:
Aster_Open_Orders.pop(0)
Aster.cancel_request_pending = False
else:
Aster.cancel_request_pending = True
logging.info(f'ASTER CANCEL ALL OPEN ORDERS RESP: {r}')
async def extend_cancel_all_orders():
@@ -1082,7 +1118,10 @@ async def run_algo():
if not(aster_target.is_orderable(price=price)) and Aster_Open_Orders:
logging.info('ASTER HAS NO TAIL BUT OPEN ORDERS - CANCELLING OPEN ORDERS; SKIPPING')
skip = True
await aster_cancel_all_orders()
if not Aster.cancel_request_pending:
await aster_cancel_all_orders()
print_summary(use_logging=True)
if aster_target.is_orderable(price=price) and aster_target.base_tail(price=price) == Decimal('0.00'):
logging.info(f'ASTER TRYNG TO ORDER 0.00 BASE QTY, SKIPPING: base_qty: {aster_target.base_tail(price=price)}; {aster_target}')
skip = True