From 5a931485f1a4ea08c04316fde548cbd77fd3d1ca Mon Sep 17 00:00:00 2001 From: yenru0 Date: Sat, 9 May 2026 14:12:59 +0900 Subject: [PATCH] fix critical --- bot.py | 12 +++++------- state.py | 6 ++++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bot.py b/bot.py index 8c0ee37..44b1f47 100644 --- a/bot.py +++ b/bot.py @@ -62,15 +62,13 @@ def main(): def on_book(message: dict, state: StateManager): symbol = message["symbol"] - def best_price(side) -> int: + def best_price(side) -> int | None: if message[side]: return message[side][0][0] - - bid_price = int(best_price("buy")) - ask_price = int(best_price("sell")) - print(message) - - state.update_bid_ask_price(symbol, bid_price, ask_price) + else: + return None + + state.update_bid_ask_price(symbol, best_price("buy"), best_price("sell")) def on_fill(message: dict, orderman: OrderManager, state: StateManager): symbol = message["symbol"] diff --git a/state.py b/state.py index e223741..3fec2ca 100644 --- a/state.py +++ b/state.py @@ -34,8 +34,10 @@ class StateManager: self.positions[symbol] = self.positions.get(symbol, 0) + quantity def update_bid_ask_price(self, symbol: str, bid_price: int, ask_price: int): - self.bid_prices[symbol] = bid_price - self.ask_prices[symbol] = ask_price + if bid_price is not None: + self.bid_prices[symbol] = bid_price + if ask_price is not None: + self.ask_prices[symbol] = ask_price def get_position(self, symbol: str) -> int: return self.positions.get(symbol, 0)