saving
This commit is contained in:
13
ws_user.py
13
ws_user.py
@@ -246,7 +246,7 @@ async def insert_user_orders_table(
|
||||
|
||||
### Helpers ###
|
||||
def live_orders_only(orders: list[dict]) -> list[dict]:
|
||||
return [d for d in orders if d.get('status')=='LIVE']
|
||||
return [d for d in orders if d.get('status') in ['LIVE','MATCHED']]
|
||||
|
||||
def upsert_list_of_dicts_by_id(list_of_dicts, new_dict):
|
||||
for index, item in enumerate(list_of_dicts):
|
||||
@@ -284,7 +284,6 @@ async def polymarket_stream():
|
||||
await websocket.send(json.dumps(subscribe_msg))
|
||||
print("Subscribed to User Data")
|
||||
|
||||
|
||||
try:
|
||||
async for message in websocket:
|
||||
ts_arrival = round(datetime.now().timestamp()*1000)
|
||||
@@ -294,8 +293,8 @@ async def polymarket_stream():
|
||||
await websocket.send(json.dumps({}))
|
||||
print('SENT HEARTBEAT PING')
|
||||
continue
|
||||
data['timestamp_arrival'] = ts_arrival
|
||||
|
||||
data['timestamp_arrival'] = ts_arrival
|
||||
event_type = data.get('event_type', None)
|
||||
match event_type:
|
||||
case 'trade':
|
||||
@@ -326,15 +325,15 @@ async def polymarket_stream():
|
||||
LOOKBACK_MIN_TS_MS = ts_arrival-LOCAL_RECENT_TRADES_LOOKBACK_SEC*1000
|
||||
LOCAL_RECENT_TRADES = [t for t in LOCAL_RECENT_TRADES if t.get('timestamp_arrival', 0) >= LOOKBACK_MIN_TS_MS]
|
||||
|
||||
# print("---------------------")
|
||||
# print(LOCAL_RECENT_TRADES)
|
||||
# print("---------------------")
|
||||
|
||||
VAL_KEY_OBJ = json.dumps(LOCAL_RECENT_TRADES)
|
||||
# VAL_KEY.publish(VK_CHANNEL, VAL_KEY_OBJ)
|
||||
logging.info("----------LOCAL_RECENT_TRADES-VK-----------")
|
||||
logging.info(VAL_KEY_OBJ)
|
||||
logging.info("-------------------------------------------")
|
||||
VAL_KEY.set(VK_RECENT_TRADES, VAL_KEY_OBJ)
|
||||
|
||||
logging.info(f'User Trade Update: {data}')
|
||||
# logging.info(f'User Trade Update: {data}')
|
||||
|
||||
### Insert into DB ###
|
||||
await insert_user_trades_table(
|
||||
|
||||
Reference in New Issue
Block a user