def test_on_on_symbols_updates(self): client = BcexClient(symbols=["BTC-USD"]) # error message msg = { "seqnum": 1, "event": "snapshot", "channel": "symbols", "symbol": "BTC-USD", "base_currency": "BTC", "base_currency_scale": 8, "counter_currency": "USD", "counter_currency_scale": 2, "min_price_increment": 10, "min_price_increment_scale": 0, "min_order_size": 50, "min_order_size_scale": 2, "max_order_size": 0, "max_order_size_scale": 8, "lot_size": 5, "lot_size_scale": 2, "status": "halt", "id": 1, "auction_price": 0.0, "auction_size": 0.0, "auction_time": "", "imbalance": 0.0, } client._on_symbols_updates(msg) assert client.symbol_details["BTC-USD"] == msg msg.update({"event": "updated"}) client._on_symbols_updates(msg) assert client.symbol_details["BTC-USD"] == msg
def test_on_message(self): client = BcexClient([Symbol.ALGOUSD]) client._check_message_seqnum = Mock() channels = [ "dummy_channel", Channel.TRADES, Channel.TICKER, Channel.PRICES, Channel.AUTH, Channel.BALANCES, Channel.HEARTBEAT, Channel.SYMBOLS, Channel.L2, Channel.L3, ] # set up the mocks mocks = [Mock() for _ in range(len(channels))] client._on_message_unsupported = mocks[0] client._on_market_trade_updates = mocks[1] client._on_ticker_updates = mocks[2] client._on_price_updates = mocks[3] client._on_auth_updates = mocks[4] client._on_balance_updates = mocks[5] client._on_heartbeat_updates = mocks[6] client._on_symbols_updates = mocks[7] client._on_l2_updates = mocks[8] client._on_l3_updates = mocks[9] # checks msg = {} for i, ch in enumerate(channels): msg.update({"channel": ch}) client.on_message(json.dumps(msg)) assert client._check_message_seqnum.call_count == i + 1 for j in range(i): assert mocks[j].call_count == 1 for j in range(i + 1, len(channels)): assert mocks[j].call_count == 0 assert mocks[i].call_args[0][0] == msg client.on_message(None)