From ef4cb47d06151fcbdc7b70d03f28752d7a1aa509 Mon Sep 17 00:00:00 2001 From: Nawaz Haider Date: Thu, 15 Jan 2026 19:57:59 +0600 Subject: [PATCH] Add update_signed_orders_cache method to OrderBook for managing signed orders --- main.py | 15 +++++++++++++-- utils/orderbook.py | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index c3cfb11..a8cc479 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,8 @@ from config import ( MAX_TRADES, MAX_TRADING_BPS_THRESHOLD, MIN_DELAY_BETWEEN_TRADES_SECONDS, - MAX_INVENTORY + MAX_INVENTORY, + PROFIT_MARGIN, ) @@ -79,7 +80,11 @@ def main(): down_ask_price = 1 - up_bid_price down_bid_price = 1 - up_ask_price - if (get_trades_count() < MAX_TRADES) and (get_period_elapsed_seconds() < 500) and (book.inventory < MAX_INVENTORY): + if ( + (get_trades_count() < MAX_TRADES) + and (get_period_elapsed_seconds() < 500) + and (book.inventory < MAX_INVENTORY) + ): trading_side = book.last_signal if trading_side == SIGNALES.UP: @@ -92,6 +97,9 @@ def main(): signed_orders_cache=book.signed_orders_cache, ) current_trades = increment_trades() + book.update_signed_orders_cache( + [round(up_bid_price, 2), round(1 - up_bid_price - PROFIT_MARGIN, 2)] + ) logger.info( f"Placed UP anchor and hedge orders. Total trades: {current_trades}, Order IDs: {order_ids}" ) @@ -107,6 +115,9 @@ def main(): signed_orders_cache=book.signed_orders_cache, ) current_trades = increment_trades() + book.update_signed_orders_cache( + [round(down_bid_price, 2), round(1 - down_bid_price - PROFIT_MARGIN, 2)] + ) logger.info( f"Placed DOWN anchor and hedge orders. Total trades: {current_trades}, Order IDs: {order_ids}" ) diff --git a/utils/orderbook.py b/utils/orderbook.py index cf84ee4..9319046 100644 --- a/utils/orderbook.py +++ b/utils/orderbook.py @@ -259,6 +259,20 @@ class OrderBook: f"Pre-created signed orders cache for tokens in {round((end - start) * 1000)} milliseconds" ) + def update_signed_orders_cache(self, prices): + client = get_client() + for price in prices: + for token_id in [self.up_token_id, self.down_token_id]: + order_args = OrderArgs( + token_id=token_id, + price=price, + size=5, + side=BUY, + ) + signed_order = client.create_order(order_args) + self.signed_orders_cache[(token_id, price)] = signed_order + logger.info(f"Updated signed orders cache for new prices: {prices}") + def clear_screen(self): os.system("cls" if os.name == "nt" else "clear")