Fixed Code to handle the new WS price_change logic
details about the changes: https://docs.polymarket.com/developers/CLOB/websocket/market-channel-migration-guide
This commit is contained in:
@@ -10,6 +10,7 @@ from poly_data.data_utils import set_position, set_order, update_positions
|
||||
|
||||
def process_book_data(asset, json_data):
|
||||
global_state.all_data[asset] = {
|
||||
'asset_id': json_data['asset_id'], # token_id for the Yes token
|
||||
'bids': SortedDict(),
|
||||
'asks': SortedDict()
|
||||
}
|
||||
@@ -18,6 +19,8 @@ def process_book_data(asset, json_data):
|
||||
global_state.all_data[asset]['asks'].update({float(entry['price']): float(entry['size']) for entry in json_data['asks']})
|
||||
|
||||
def process_price_change(asset, side, price_level, new_size):
|
||||
if asset_id != global_state.all_data[asset]['asset_id']:
|
||||
return # skip updates for the No token to prevent duplicated updates
|
||||
if side == 'bids':
|
||||
book = global_state.all_data[asset]['bids']
|
||||
else:
|
||||
@@ -42,7 +45,7 @@ def process_data(json_datas, trade=True):
|
||||
asyncio.create_task(perform_trade(asset))
|
||||
|
||||
elif event_type == 'price_change':
|
||||
for data in json_data['changes']:
|
||||
for data in json_data['price_changes']:
|
||||
side = 'bids' if data['side'] == 'BUY' else 'asks'
|
||||
price_level = float(data['price'])
|
||||
new_size = float(data['size'])
|
||||
@@ -146,4 +149,4 @@ def process_user_data(rows):
|
||||
asyncio.create_task(perform_trade(market))
|
||||
|
||||
else:
|
||||
print(f"User date received for {market} but its not in")
|
||||
print(f"User date received for {market} but its not in")
|
||||
|
||||
Reference in New Issue
Block a user