Add update_signed_orders_cache method to OrderBook for managing signed orders
This commit is contained in:
@@ -16,7 +16,8 @@ from config import (
|
|||||||
MAX_TRADES,
|
MAX_TRADES,
|
||||||
MAX_TRADING_BPS_THRESHOLD,
|
MAX_TRADING_BPS_THRESHOLD,
|
||||||
MIN_DELAY_BETWEEN_TRADES_SECONDS,
|
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_ask_price = 1 - up_bid_price
|
||||||
down_bid_price = 1 - up_ask_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
|
trading_side = book.last_signal
|
||||||
|
|
||||||
if trading_side == SIGNALES.UP:
|
if trading_side == SIGNALES.UP:
|
||||||
@@ -92,6 +97,9 @@ def main():
|
|||||||
signed_orders_cache=book.signed_orders_cache,
|
signed_orders_cache=book.signed_orders_cache,
|
||||||
)
|
)
|
||||||
current_trades = increment_trades()
|
current_trades = increment_trades()
|
||||||
|
book.update_signed_orders_cache(
|
||||||
|
[round(up_bid_price, 2), round(1 - up_bid_price - PROFIT_MARGIN, 2)]
|
||||||
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Placed UP anchor and hedge orders. Total trades: {current_trades}, Order IDs: {order_ids}"
|
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,
|
signed_orders_cache=book.signed_orders_cache,
|
||||||
)
|
)
|
||||||
current_trades = increment_trades()
|
current_trades = increment_trades()
|
||||||
|
book.update_signed_orders_cache(
|
||||||
|
[round(down_bid_price, 2), round(1 - down_bid_price - PROFIT_MARGIN, 2)]
|
||||||
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Placed DOWN anchor and hedge orders. Total trades: {current_trades}, Order IDs: {order_ids}"
|
f"Placed DOWN anchor and hedge orders. Total trades: {current_trades}, Order IDs: {order_ids}"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -259,6 +259,20 @@ class OrderBook:
|
|||||||
f"Pre-created signed orders cache for tokens in {round((end - start) * 1000)} milliseconds"
|
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):
|
def clear_screen(self):
|
||||||
os.system("cls" if os.name == "nt" else "clear")
|
os.system("cls" if os.name == "nt" else "clear")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user