def test_private_subscriptions(self): client = BcexClient( [Symbol.ETHBTC, Symbol.ALGOUSD], channels=[Channel.TRADING], api_secret="my_api_tokennn", ) client._wait_for_confirmation = Mock() # will test separately client._wait_for_authentication = Mock() # will test separately ws_mock = Mock() ws_mock.send = Mock() client.ws = ws_mock client._private_subscription() assert ws_mock.send.call_count == 2 # one for authentication, one for channel # auth message sent auth = ws_mock.send.call_args_list[0][0][0] assert auth == json.dumps({ "channel": Channel.AUTH, "action": Action.SUBSCRIBE, "token": "my_api_tokennn", }) # subscription channel message sent subscriptions = ws_mock.send.call_args_list[1][0][0] assert subscriptions == json.dumps({ "action": Action.SUBSCRIBE, "channel": Channel.TRADING }) assert (client.channel_status[Channel.TRADING] == ChannelStatus.WAITING_CONFIRMATION) # make sure we will wait for the correct channels assert client._wait_for_confirmation.call_count == 1 assert client._wait_for_authentication.call_count == 1 assert set(client._wait_for_confirmation.call_args[0][0]) == { (Channel.TRADING, None) }
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