Add update_signed_orders_cache method to OrderBook for managing signed orders

This commit is contained in:
Nawaz Haider
2026-01-15 19:57:59 +06:00
parent 5657b087c5
commit ef4cb47d06
2 changed files with 27 additions and 2 deletions
+13 -2
View File
@@ -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}"
)
+14
View File
@@ -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")