From a662380e65205b2ca772fa3bb282c96fa3ea5a1f Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 7 Nov 2025 20:02:14 +0100 Subject: [PATCH] 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 --- poly_data/data_processing.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/poly_data/data_processing.py b/poly_data/data_processing.py index 888ca63..4dea873 100644 --- a/poly_data/data_processing.py +++ b/poly_data/data_processing.py @@ -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") \ No newline at end of file + print(f"User date received for {market} but its not in")