bmoscon / cryptofeed

Cryptocurrency Exchange Websocket Data Feed Handler
Other
2.14k stars 666 forks source link

Coinbase now requires authentication #990

Closed SpaceMonkeyForever closed 5 months ago

SpaceMonkeyForever commented 10 months ago

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 https://github.com/bmoscon/cryptofeed/issues/937

uweheldt commented 9 months ago

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 commented 9 months ago

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

uweheldt commented 9 months ago

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 commented 9 months ago

I made the exact same mistake recently. They make it confusing so don't blame yourself.

On Tue, Sep 19, 2023, 8:01 PM uweheldt @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/bmoscon/cryptofeed/issues/990#issuecomment-1726317953, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFONGISH4UKHQNU4LOPAP5DX3HTYFANCNFSM6AAAAAA3T4B3ZM . You are receiving this because you authored the thread.Message ID: @.***>

jibanes commented 8 months ago

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

twoletters commented 7 months ago

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 commented 7 months ago

@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 commented 6 months ago

@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 commented 5 months ago

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

kzk2000 commented 5 months ago

@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 commented 5 months ago

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 commented 5 months ago

@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 commented 5 months ago

I have opened the PR here: https://github.com/bmoscon/cryptofeed/pull/1005