Skip to content

Commit

Permalink
Cache tickers that don't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
j-waters authored and edeng23 committed Jun 8, 2021
1 parent 80ef5fe commit dbdd052
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion binance_trade_bot/binance_api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ def get_ticker_price(self, ticker_symbol: str):
Get ticker price of a specific coin
"""
price = self.cache.ticker_values.get(ticker_symbol, None)
if price is None:
if price is None and ticker_symbol not in self.cache.non_existent_tickers:
self.cache.ticker_values = {
ticker["symbol"]: float(ticker["price"]) for ticker in self.binance_client.get_symbol_ticker()
}
price = self.cache.ticker_values.get(ticker_symbol, None)
if price is None:
self.cache.non_existent_tickers.add(ticker_symbol)

return price

Expand Down
3 changes: 2 additions & 1 deletion binance_trade_bot/binance_stream_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from typing import Dict
from typing import Dict, Set

from autobahn.twisted.websocket import connectWS
from binance.client import Client
Expand Down Expand Up @@ -33,6 +33,7 @@ def _start_socket(self, path, callback, prefix="ws/"):
class BinanceCache: # pylint: disable=too-few-public-methods
ticker_values: Dict[str, float] = {}
balances: Dict[str, float] = {}
non_existent_tickers: Set[str] = set()


class BinanceStreamManager:
Expand Down

0 comments on commit dbdd052

Please sign in to comment.