def test_public_subscriptions(self): client = BcexClient( [Symbol.ETHBTC, Symbol.ALGOUSD], channels=[Channel.HEARTBEAT, Channel.SYMBOLS], channel_kwargs={ Channel.SYMBOLS: { "dummy_arg": "dummy_val" }, Channel.HEARTBEAT: { "t": 5 }, }, ) client._wait_for_confirmation = Mock() # will test separately ws_mock = Mock() ws_mock.send = Mock() client.ws = ws_mock client._public_subscription() assert ws_mock.send.call_count == 3 # 2 for the 2 symbols and 1 for heartbeat subscriptions = [args[0][0] for args in ws_mock.send.call_args_list] assert set(subscriptions) == { json.dumps({ "action": Action.SUBSCRIBE, "channel": Channel.SYMBOLS, "symbol": Symbol.ALGOUSD, "dummy_arg": "dummy_val", }), json.dumps({ "action": Action.SUBSCRIBE, "channel": Channel.SYMBOLS, "symbol": Symbol.ETHBTC, "dummy_arg": "dummy_val", }), json.dumps({ "action": Action.SUBSCRIBE, "channel": Channel.HEARTBEAT, "t": 5 }), } assert (client.channel_status[Channel.HEARTBEAT] == ChannelStatus.WAITING_CONFIRMATION) assert (client.channel_status[Channel.SYMBOLS][Symbol.ETHBTC] == ChannelStatus.WAITING_CONFIRMATION) assert (client.channel_status[Channel.SYMBOLS][Symbol.ALGOUSD] == ChannelStatus.WAITING_CONFIRMATION) # make sure we will wait for the correct channels assert client._wait_for_confirmation.call_count == 1 assert set(client._wait_for_confirmation.call_args[0][0]) == { (Channel.HEARTBEAT, None), (Channel.SYMBOLS, Symbol.ETHBTC), (Channel.SYMBOLS, Symbol.ALGOUSD), }
def test_subscribe_channels(self): client = BcexClient( [Symbol.ETHBTC, Symbol.ALGOUSD], channels=[Channel.HEARTBEAT, Channel.SYMBOLS], api_secret="my_api_key", ) client._public_subscription = Mock() client._private_subscription = Mock() client._subscribe_channels() assert client._public_subscription.call_count == 1 assert client._private_subscription.call_count == 1 client._api_secret = None client._subscribe_channels() assert client._public_subscription.call_count == 2 assert client._private_subscription.call_count == 1