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

Coinbase now requires authentication #990

Closed
SpaceMonkeyForever opened this issue Aug 17, 2023 · 13 comments
Closed

Coinbase now requires authentication #990

SpaceMonkeyForever opened this issue Aug 17, 2023 · 13 comments

Comments

@SpaceMonkeyForever
Copy link

Coinbase requires auth now:

2023-08-17 13:38:18,706 : WARNING : COINBASE: Invalid message type {'type': 'error', 'message': 'Failed to subscribe', 'reason': 'level2, level3, and full channels now require authentication. https://docs.cloud.coinbase.com/exchange/docs/websocket-auth'}

https://docs.cloud.coinbase.com/exchange/docs/websocket-auth

Somewhat of a duplicate of #937

@uweheldt
Copy link

Did you try to implement that by your own. I'm trying but getting issues. See the attached screenshot. Any idea what might be wrong?
Bildschirmfoto 2023-09-19 um 16 52 06

@bmoscon
Copy link
Owner

bmoscon commented Sep 19, 2023

the passphrase is not your password, its used when creating the api key

@uweheldt
Copy link

the passphrase is not your password, its used when creating the api key

Man. I'm so stupid ;) I used the Coinbase API Key and not the Coinbase Pro API Key. Using the right API key, this approach posted in the image works well for me (consuming a L2 Book channel).

@SpaceMonkeyForever
Copy link
Author

SpaceMonkeyForever commented Sep 19, 2023 via email

@jibanes
Copy link

jibanes commented Oct 25, 2023

Where did you get this key from? I only see wallet api keys being available to me.

@twoletters
Copy link

Coinbase Pro met its end. No way to create Coinbase Pro API keys anymore now.

Screenshot 2023-12-02 at 7 24 07 PM

@bmoscon Do you plan on updating the Coinbase client to use the new Coinbase API? Any chance you could enable API authentication using global variables, so it is easy to use? It is mandatory now, as reported in the original issue.

@bmoscon
Copy link
Owner

bmoscon commented Dec 3, 2023

@twoletters unless I am mistaken what they call "cloud" or "exchange" now has the same API as Pro, its just a matter of changing the websocket URL

@kzk2000
Copy link

kzk2000 commented Jan 1, 2024

@uweheldt what did you end up using for "passphrase" - just an empty string?
I'm trying to replicate your solution above with this code but cannot get it work. Getting
{'type': 'error', 'message': 'Failed to subscribe', 'reason': 'level2, level3, and full channels now require authentication. https://docs.cloud.coinbase.com/exchange/docs/websocket-auth'}

errors.

Any pointers highly appreciated

        import base64
        import hashlib
        import hmac

        method = "GET"
        request_path = "/users/self/verify"
        key = ...
        secret_key = ...
        passphrase = ""

        timestamp = str(int(time.time()))
        message = timestamp + method + request_path
        hmac_key = base64.b64decode(secret_key)
        signature = hmac.new(hmac_key, message.encode(), hashlib.sha256)
        signature_b64 = base64.b64encode(signature.digest())

        ws.send(
            json.dumps(
                {
                    "type": "subscribe",
                    "product_ids": [
                        "BTC-USD",
                    ],
                    "channels": ["level2"],
                    "signature": signature_b64.decode(),
                    "key": key,
                    "passphrase": passphrase,
                    "timestamp": timestamp
                }
            )
        )

@thomasbs17
Copy link
Contributor

I am working on updating the Coinbase module to reflect the new authentication requirements. I am hoping to open a PR soon.

@kzk2000
Copy link

kzk2000 commented Jan 15, 2024

@thomasbs17 thank you!

FWIW, I found there's a non-authlevel2_batch so all you have to do is
https://github.com/kzk2000/deephaven-clickhouse/blob/master/docker/cryptofeed/src/coinbase.py#L381

and avoid throwing errors here by adding and (price in self._l2_book[pair].book[side]): here
https://github.com/kzk2000/deephaven-clickhouse/blob/master/docker/cryptofeed/src/coinbase.py#L189

My understanding is that the previous Coinbase PRO api key is no longer available to Retail customers (but still exists for Institutions), and there's a new Advanced Trading API for retail with details here: https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-auth -- however, those payloads look very different.

Anyway, curious to hear what you figure out.

@thomasbs17
Copy link
Contributor

Hi @kzk2000 , you can check out this PR (my cryptofeed fork).
I have 90% of things ready and functional in there, I should be able to open a PR within this repo by end of week

@kzk2000
Copy link

kzk2000 commented Jan 16, 2024

@thomasbs17 this is very cool, I see you are switching everything to the wss://advanced-trade-ws.coinbase.com which is the new Advanced Trading API. Thanks for doing this work! I had looked at it but then didn't have the time to go all in.

I see you also used this extra check to see we don't remove price levels that don't exist - nice!
https://github.com/thomasbs17/cryptofeed/pull/1/files#diff-e8cf1e2e86d9c37da0539f64eff8c4fe971b718b1d73855632ebecf7288a98adR125-R128

@thomasbs17
Copy link
Contributor

I have opened the PR here: #1005

@bmoscon bmoscon closed this as completed Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants