Refactor hedge order placement logic to use a retry mechanism for improved reliability

This commit is contained in:
Nawaz Haider
2026-01-02 16:41:29 +06:00
parent af2c5e1a88
commit 7c75648ef3
+25 -23
View File
@@ -83,31 +83,33 @@ async def send_hedge(anchor_id, anchor_side, anchor_price, anchor_size):
hedge_price = min(max(round(1 - anchor_price - PROFIT_MARGIN, 2), 0.01), 0.99)
logger.info(f"⚡ SENDING HEDGE {hedge_side} @ ${hedge_price:.2f} ")
try:
args = OrderArgs(
price=hedge_price,
size=5,
side=BUY,
token_id=hedge_token,
)
signed = client.create_order(args)
res = client.post_order(signed, OrderType.GTC)
hedge_order_id = res.get("orderID")
hedge_order_id = None
while not hedge_order_id:
try:
args = OrderArgs(
price=hedge_price,
size=5,
side=BUY,
token_id=hedge_token,
)
signed = client.create_order(args)
res = client.post_order(signed, OrderType.GTC)
hedge_order_id = res.get("orderID")
async with state.lock:
state.processing_anchors.discard(anchor_id)
state.hedged_anchors.add(anchor_id)
if hedge_order_id:
state.hedged_orders.add(hedge_order_id)
async with state.lock:
state.processing_anchors.discard(anchor_id)
state.hedged_anchors.add(anchor_id)
if hedge_order_id:
state.hedged_orders.add(hedge_order_id)
logger.info(f"✅ Hedge placed: {hedge_order_id}")
return hedge_order_id
except Exception as e:
logger.error(f"Hedge Order Error: {e}")
async with state.lock:
state.processing_anchors.discard(anchor_id)
state.hedged_anchors.add(anchor_id)
await asyncio.sleep(0.05)
logger.info(f"✅ Hedge placed: {hedge_order_id}")
return hedge_order_id
except Exception as e:
logger.error(f"Hedge Order Error: {e}")
async with state.lock:
state.processing_anchors.discard(anchor_id)
state.hedged_anchors.add(anchor_id)
await asyncio.sleep(0.05)
async def handle_message(message):