fix critical

This commit is contained in:
2026-05-09 14:12:59 +09:00
parent 4d6a2dc0ac
commit 5a931485f1
2 changed files with 9 additions and 9 deletions

10
bot.py
View File

@@ -62,15 +62,13 @@ def main():
def on_book(message: dict, state: StateManager): def on_book(message: dict, state: StateManager):
symbol = message["symbol"] symbol = message["symbol"]
def best_price(side) -> int: def best_price(side) -> int | None:
if message[side]: if message[side]:
return message[side][0][0] return message[side][0][0]
else:
return None
bid_price = int(best_price("buy")) state.update_bid_ask_price(symbol, best_price("buy"), best_price("sell"))
ask_price = int(best_price("sell"))
print(message)
state.update_bid_ask_price(symbol, bid_price, ask_price)
def on_fill(message: dict, orderman: OrderManager, state: StateManager): def on_fill(message: dict, orderman: OrderManager, state: StateManager):
symbol = message["symbol"] symbol = message["symbol"]

View File

@@ -34,7 +34,9 @@ class StateManager:
self.positions[symbol] = self.positions.get(symbol, 0) + quantity self.positions[symbol] = self.positions.get(symbol, 0) + quantity
def update_bid_ask_price(self, symbol: str, bid_price: int, ask_price: int): def update_bid_ask_price(self, symbol: str, bid_price: int, ask_price: int):
if bid_price is not None:
self.bid_prices[symbol] = bid_price self.bid_prices[symbol] = bid_price
if ask_price is not None:
self.ask_prices[symbol] = ask_price self.ask_prices[symbol] = ask_price
def get_position(self, symbol: str) -> int: def get_position(self, symbol: str) -> int: