How to use jwt token in WSClient
I am trying to use the WSClient to get data, however, I am getting {"type":"error","message":"authentication failure"}.
My understanding is that I need a jwt token, which I got from
jwt_token = jwt_generator.build_ws_jwt(api_key, api_secret)
However, I do not know how to use this token in my WSClient, my code is as follows
self.ws_client = WSClient(api_key=api_key, api_secret=api_secret, on_message=self.on_message, verbose=True)
self.ws_client.open()
self.ws_client.subscribe(product_ids=[product_id], channels=channels)
Could anyone please help me with this?
Thank you for reporting! If this is an SDK specific issue, we will look into it and get back to you soon. If this is an API related request, report it in our Advanced API Discord instead (use this invite link if it's your first time accessing the Discord).
The JWT token will be automatically generated when you subscribe to channels using the WSClient. There is no need to generate it yourself. What channels are you trying to subscribe to? Are you able to make REST requests using the same API key and secret?
I realized I will get {"type":"error","message":"authentication failure"} if I try to subscribe to the 'heartbeat' channel, subscribing to other channels is fine.
Could you please explain why this is? What does the 'heartbeat' channel do, and why the auth failure?
I can use the REST requests just fine.
Heartbeats channel does not require authentication. More details in our docs here: https://docs.cdp.coinbase.com/advanced-trade/docs/ws-channels#heartbeats-channel
It's possible you have a typo. Try using 'heartbeats' rather than 'heartbeat'