danpaquin / coinbasepro-python

The unofficial Python client for the Coinbase Pro API
MIT License
1.82k stars 738 forks source link

Heartbeat last id is always zero #356

Closed nazariyv closed 3 years ago

nazariyv commented 5 years ago

When using authenticated WebsocketClient and heartbeat channel, is everyone also getting last trade id: 0? (starting the socket, and then making trades, obviously).

import datetime as dt
import cbpro
import time
import json

sandbox_url = 'wss://ws-feed-public.sandbox.pro.coinbase.com'
pro_url = "wss://ws-feed.pro.coinbase.com/"

SOCKET_CONFIG = {'products': ['BTC-USD'],
                 'auth': True,
                 'api_key': api_key,
                 'api_secret': api_secret,
                 'api_passphrase': api_pass,
                 'channels': ['heartbeat'],
                 'url': sandbox_url}

class MyWebsocketClient(cbpro.WebsocketClient):
    def on_open(self):
        self.message_count = 0
        self.most_recent_message = ''

    def on_message(self, msg):
        print(json.dumps(msg, indent=4, sort_keys=True))
        self.message_count += 1
        self.most_recent_message = msg

    def on_close(self):
        print("-- Goodbye! --")

    def __repr__(self):
        pass

wsClient = MyWebsocketClient(**SOCKET_CONFIG)

wsClient.start()
print(wsClient.url, wsClient.products)

run_for_seconds = 60
start_time = dt.datetime.now()

while start_time + dt.timedelta(seconds=run_for_seconds) > dt.datetime.now():
#   print(wsClient)
    time.sleep(1)

wsClient.close()

if wsClient.error:
    sys.exit(1)
else:
    sys.exit(0)

and the output:

{
    "last_trade_id": 0,
    "product_id": "BTC-USD",
    "sequence": 40010849,
    "time": "2019-02-24T21:36:27.952326Z",
    "type": "heartbeat"
}
{
    "last_trade_id": 0,
    "product_id": "BTC-USD",
    "sequence": 40010856,
    "time": "2019-02-24T21:36:28.952355Z",
    "type": "heartbeat"
}
{
    "last_trade_id": 0,
    "product_id": "BTC-USD",
    "sequence": 40010862,
    "time": "2019-02-24T21:36:29.952290Z",
    "type": "heartbeat"
}
{
    "last_trade_id": 0,
    "product_id": "BTC-USD",
    "sequence": 40010862,
    "time": "2019-02-24T21:36:30.952335Z",
    "type": "heartbeat"
}
[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:2471) - data: None

that ssl error is worrisome too.

nazariyv commented 5 years ago

and, yes, I have tried this on the normal market (non-sandbox). Same story

nazariyv commented 5 years ago

new SSL error, 2 out of 2 times now wsClient exits with an error:

[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2471) - data: None
nazariyv commented 5 years ago

The heartbeat has this last_trade_id, which I was assuming, was my last order id? The issue is not in getting the trade ids. That I can get. The problem is in pinpointing when we have missed to get the match message because it was dropped. Coinbase API tells us that we should use heartbeat for that. But I do not understand how.

nazariyv commented 5 years ago

One can for example get done before match, then we would we have dropped a match message. But what if we drop both the match and done. There must be a good way to pinpoint the dropped messages. And I was under the impression that heartbeat is such a mechanism.

noah222 commented 5 years ago

from coinbase pro docs: " Authenticated feed messages do not increment the sequence number. It is currently not possible to detect if an authenticated feed message was dropped. "

I check each order manually until it is filled or I cancel it, since i have not found another reliable method to 100% verify the order being filled. I think the feeds are set up to give a house advantage, and it takes some creativity to work around it.

nazariyv commented 5 years ago

You mean you use REST? Do you do that to check if you missed match potentially? At what point would you do this though?

nazariyv commented 5 years ago

This is not patronizing at all! Thank you. It may be useful for me.

mcardillo55 commented 3 years ago

Seems like others have seen this as well: https://github.com/preichenberger/go-coinbasepro/issues/89

A user in that thread opened a bug report with Coinbase support, but it seems the issue is still there.

Closing this for now, as it seems to be on the Coinbase side.