Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions poly_data/data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ def process_book_data(asset, json_data):
global_state.all_data[asset]['bids'].update({float(entry['price']): float(entry['size']) for entry in json_data['bids']})
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
def process_price_change(asset, side, price_level, new_size, asset_id=None):
# Skip updates for the No token to prevent duplicated updates
# Only process if asset_id matches the stored asset_id for this market
if asset_id and asset in global_state.all_data and asset_id != global_state.all_data[asset]['asset_id']:
return

if side == 'bids':
book = global_state.all_data[asset]['bids']
else:
Expand All @@ -33,7 +36,10 @@ def process_price_change(asset, side, price_level, new_size):
book[price_level] = new_size

def process_data(json_datas, trade=True):

# Ensure input is always a list
if isinstance(json_datas, dict):
json_datas = [json_datas]

for json_data in json_datas:
event_type = json_data['event_type']
asset = json_data['market']
Expand All @@ -49,7 +55,9 @@ def process_data(json_datas, trade=True):
side = 'bids' if data['side'] == 'BUY' else 'asks'
price_level = float(data['price'])
new_size = float(data['size'])
process_price_change(asset, side, price_level, new_size)
# Pass asset_id if available in the data
asset_id = data.get('asset_id', None)
process_price_change(asset, side, price_level, new_size, asset_id)

if trade:
asyncio.create_task(perform_trade(asset))
Expand Down
6 changes: 6 additions & 0 deletions poly_data/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ def update_markets():
received_df, received_params = get_sheet_df()

if len(received_df) > 0:
# Ensure multiplier column exists and fill NaN values with empty string
if 'multiplier' not in received_df.columns:
received_df['multiplier'] = ''
else:
received_df['multiplier'] = received_df['multiplier'].fillna('')

global_state.df, global_state.params = received_df.copy(), received_params


Expand Down
7 changes: 4 additions & 3 deletions poly_data/trading_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ def get_buy_sell_amount(position, bid_price, row, other_token_position=0):

# Apply multiplier for low-priced assets
if bid_price < 0.1 and buy_amount > 0:
if row['multiplier'] != '':
print(f"Multiplying buy amount by {int(row['multiplier'])}")
buy_amount = buy_amount * int(row['multiplier'])
multiplier = row.get('multiplier', '')
if multiplier != '':
print(f"Multiplying buy amount by {int(multiplier)}")
buy_amount = buy_amount * int(multiplier)

return buy_amount, sell_amount