coinbase-advanced-py icon indicating copy to clipboard operation
coinbase-advanced-py copied to clipboard

How to use jwt token in WSClient

Open hearthewind opened this issue 11 months ago • 4 comments

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?

hearthewind avatar Dec 27 '24 23:12 hearthewind

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).

github-actions[bot] avatar Dec 27 '24 23:12 github-actions[bot]

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?

urischwartz-cb avatar Jan 06 '25 17:01 urischwartz-cb

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.

hearthewind avatar Jan 08 '25 01:01 hearthewind

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'

urischwartz-cb avatar Jan 08 '25 01:01 urischwartz-cb