nicegui initial

This commit is contained in:
2026-05-07 06:13:43 +00:00
parent f45c035ebb
commit 1bbb4797ce
10 changed files with 1221 additions and 1377 deletions

21
main.py
View File

@@ -61,7 +61,9 @@ Flags = structs.Flags()
async def output_algo_status(status: str) -> None:
global Algo_Status
Algo_Status.last_update_ts_ms = int(round(datetime.now().timestamp()*1000, 2))
Algo_Status.status = status
VAL_KEY.set('algo_status', json.dumps(Algo_Status.model_dump()))
def create_exchange_objs_from_dict(exchanges_dict: dict) -> tuple[structs.Perpetual_Exchange, structs.Perpetual_Exchange]:
@@ -497,7 +499,7 @@ async def post_extend_order(
await kill_algo()
### OPEN ORDERS ###
async def handle_order_updates(exch: str, local_open_orders: list[dict], ws_open_orders: list[dict]) -> list[dict]: # exch = 'ASTER' | 'EXTEND'
async def handle_order_updates(exch: str, local_open_orders: list[dict], ws_open_orders: list[dict], ws_pos_updates: list[dict]) -> list[dict]: # exch = 'ASTER' | 'EXTEND'
global Aster
global Extend
global Last_Aster_Fill_Time_Ts
@@ -550,18 +552,18 @@ async def handle_order_updates(exch: str, local_open_orders: list[dict], ws_open
logging.info(f'{exch} ORDER PARTIALLY FILLED: {order_id}')
# await get_aster_collateral()
if exch=='ASTER':
await get_aster_notional_position()
await get_aster_notional_position(resp=ws_pos_updates)
Last_Aster_Fill_Time_Ts = datetime.now().timestamp()*1000
else:
await get_extend_notional()
await get_extend_notional(resp=ws_pos_updates)
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}')
local_open_orders.pop(idx)
# await get_aster_collateral()
if exch=='ASTER':
await aster_cancel_all_orders()
await get_aster_notional_position()
# await aster_cancel_all_orders()
await get_aster_notional_position(resp=ws_pos_updates)
Last_Aster_Fill_Time_Ts = datetime.now().timestamp()*1000
else:
await extend_cancel_all_orders()
@@ -939,8 +941,8 @@ async def run_algo():
extend_ws_order_updates: list = json.loads(extend_ws_order_updates) if extend_ws_order_updates is not None else []
### Update Local Open Orders w Changes from WS ###
Aster_Open_Orders = await handle_order_updates(exch='ASTER', local_open_orders=Aster_Open_Orders, ws_open_orders=aster_ws_order_updates)
Extend_Open_Orders = await handle_order_updates(exch='EXTEND', local_open_orders=Extend_Open_Orders, ws_open_orders=extend_ws_order_updates)
Aster_Open_Orders = await handle_order_updates(exch='ASTER', local_open_orders=Aster_Open_Orders, ws_open_orders=aster_ws_order_updates, ws_pos_updates=aster_ws_pos_updates)
Extend_Open_Orders = await handle_order_updates(exch='EXTEND', local_open_orders=Extend_Open_Orders, ws_open_orders=extend_ws_order_updates, ws_pos_updates=extend_ws_pos_updates)
### CHECK NO MORE THAN 1 OPEN ORDER ON EITHER EXCHANGE ###
if len(Aster_Open_Orders) > 1 or len(Extend_Open_Orders) > 1:
@@ -968,6 +970,8 @@ async def run_algo():
alpha_hurdle_adj=Decimal(str(Config.Config.Min_Fund_Rate_Pct_To_Trade)),
)
Algo_Status.expected_alpha = float(signal.expected_alpha)
Algo_Status.model_ratio = float(signal.model_ratio)
Algo_Status.current_ratio = float(signal.current_ratio)
if signal.signal:
### True signal, standard target
alpha_target_notional = Decimal(str(Config.Config.Max_Target_Notional))
@@ -1267,7 +1271,10 @@ async def main():
last_update_ts_ms = int(round(datetime.now().timestamp()*1000, 2)),
status = 'WORKING',
expected_alpha = 0.00,
model_ratio = 0.00,
current_ratio = 0.00,
)
await output_algo_status('WORKING')
async with engine.connect() as CON:
### ASTER SETUP ###