def test_on_market_trade_updates(self): client = BcexClient(symbols=["BTC-USD"]) msg = { "seqnum": 21, "event": "updated", "channel": "trades", "symbol": "BTC-USD", "timestamp": "2019-08-13T11:30:06.100140Z", "side": "sell", "qty": 8.5e-5, "price": 11252.4, "trade_id": "12884909920", } client._on_market_trade_updates(msg) trade = client.market_trades["BTC-USD"][0] assert trade.symbol == "BTC-USD" assert trade.quantity == 8.5e-5 assert trade.side == "sell" assert trade.timestamp == "2019-08-13T11:30:06.100140Z" assert trade.trade_id == "12884909920" assert trade.price == 11252.4
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)