Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use jwt token in WSClient #92

Open
hearthewind opened this issue Dec 27, 2024 · 4 comments
Open

How to use jwt token in WSClient #92

hearthewind opened this issue Dec 27, 2024 · 4 comments

Comments

@hearthewind
Copy link

hearthewind commented Dec 27, 2024

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?

Copy link

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

@urischwartz-cb
Copy link
Contributor

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?

@hearthewind
Copy link
Author

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.

@urischwartz-cb
Copy link
Contributor

urischwartz-cb commented Jan 8, 2025

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants