def test_on_price_updates(self): client = BcexClient(symbols=["BTC-USD"]) # error message msg = { "seqnum": 18, "event": "rejected", "channel": "prices", "text": "No granularity set", } client._on_price_updates(msg) msg = { "seqnum": 2, "event": "updated", "channel": "prices", "symbol": "BTC-USD", "price": [1559039640, 8697.24, 8700.98, 8697.27, 8700.98, 0.431], } client._on_price_updates(msg) assert client.candles["BTC-USD"] == [[ 1559039640, 8697.24, 8700.98, 8697.27, 8700.98, 0.431 ]]
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)