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

The LastTradeID field of a heartbeat message is always 0. #89

Closed
lukehollenback opened this issue May 5, 2020 · 6 comments
Closed

The LastTradeID field of a heartbeat message is always 0. #89

lukehollenback opened this issue May 5, 2020 · 6 comments

Comments

@lukehollenback
Copy link

Consider the following snippet, which closely resembles the websocket example from the readme:

	var wsDialer ws.Dialer
	wsConn, _, err := wsDialer.Dial("wss://ws-feed.pro.coinbase.com", nil)
	if err != nil {
		log.Fatal(err.Error())
	}

	subscribe := coinbasepro.Message{
		Type: "subscribe",
		Channels: []coinbasepro.MessageChannel{
			coinbasepro.MessageChannel{
				Name: "heartbeat",
				ProductIds: []string{
					"BTC-USD",
				},
			},
			coinbasepro.MessageChannel{
				Name: "matches",
				ProductIds: []string{
					"BTC-USD",
				},
			},
		},
	}
	if err := wsConn.WriteJSON(subscribe); err != nil {
		log.Fatal(err.Error())
	}

	for true {
		message := coinbasepro.Message{}
		if err := wsConn.ReadJSON(&message); err != nil {
			log.Fatal(err.Error())
			break
		}

		log.Printf(
			"Type: %s, Product: %s, Amount: %s, Trade ID: %d, Last Trade ID: %d",
			message.Type,
			message.ProductID,
			message.Price,
			message.TradeID,
			message.LastTradeID,
		)
	}

Note that I am subscribed to the BTC-USD heartbeat and matches channels. I would expect that every time a new match occurs, the next heartbeat would hold the said match's trade identifier. However, I am seeing output like the following:

▶ go run .
2020/05/05 08:17:07 Type: subscriptions, Product: , Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:07 Type: last_match, Product: BTC-USD, Amount: 8874.68, Trade ID: 90477204, Last Trade ID: 0
2020/05/05 08:17:07 Type: match, Product: BTC-USD, Amount: 8876.6, Trade ID: 90477205, Last Trade ID: 0
2020/05/05 08:17:07 Type: match, Product: BTC-USD, Amount: 8876.97, Trade ID: 90477206, Last Trade ID: 0
2020/05/05 08:17:07 Type: match, Product: BTC-USD, Amount: 8877.2, Trade ID: 90477207, Last Trade ID: 0
2020/05/05 08:17:07 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:08 Type: match, Product: BTC-USD, Amount: 8875.71, Trade ID: 90477208, Last Trade ID: 0
2020/05/05 08:17:08 Type: match, Product: BTC-USD, Amount: 8875.62, Trade ID: 90477209, Last Trade ID: 0
2020/05/05 08:17:08 Type: match, Product: BTC-USD, Amount: 8877.2, Trade ID: 90477210, Last Trade ID: 0
2020/05/05 08:17:08 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:09 Type: match, Product: BTC-USD, Amount: 8877.2, Trade ID: 90477211, Last Trade ID: 0
2020/05/05 08:17:09 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:10 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:11 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:12 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:13 Type: match, Product: BTC-USD, Amount: 8877.17, Trade ID: 90477212, Last Trade ID: 0
2020/05/05 08:17:13 Type: match, Product: BTC-USD, Amount: 8877.17, Trade ID: 90477213, Last Trade ID: 0
2020/05/05 08:17:13 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:14 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:15 Type: match, Product: BTC-USD, Amount: 8878.59, Trade ID: 90477214, Last Trade ID: 0
2020/05/05 08:17:15 Type: match, Product: BTC-USD, Amount: 8878.67, Trade ID: 90477215, Last Trade ID: 0
2020/05/05 08:17:15 Type: match, Product: BTC-USD, Amount: 8879.29, Trade ID: 90477216, Last Trade ID: 0
2020/05/05 08:17:15 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:17 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:17 Type: match, Product: BTC-USD, Amount: 8877.53, Trade ID: 90477217, Last Trade ID: 0
2020/05/05 08:17:17 Type: match, Product: BTC-USD, Amount: 8877.52, Trade ID: 90477218, Last Trade ID: 0
2020/05/05 08:17:17 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:17 Type: match, Product: BTC-USD, Amount: 8877.52, Trade ID: 90477219, Last Trade ID: 0
2020/05/05 08:17:17 Type: match, Product: BTC-USD, Amount: 8877.49, Trade ID: 90477220, Last Trade ID: 0
2020/05/05 08:17:18 Type: match, Product: BTC-USD, Amount: 8879, Trade ID: 90477221, Last Trade ID: 0
2020/05/05 08:17:18 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:19 Type: match, Product: BTC-USD, Amount: 8879, Trade ID: 90477222, Last Trade ID: 0
2020/05/05 08:17:19 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0
2020/05/05 08:17:20 Type: heartbeat, Product: BTC-USD, Amount: , Trade ID: 0, Last Trade ID: 0

Notice that the LastTradeID field of the heartbeat messages is always 0. Is my understanding of the semantics of the heartbeat message wrong? Or am I possibly using it wrong? Or could this be a real bug – with either this library or with the Coinbase Pro API?

@lukehollenback lukehollenback changed the title The LastTradeID field of a heartbeat message is always 0. The LastTradeID field of a heartbeat message is always 0. May 5, 2020
@preichenberger
Copy link
Owner

preichenberger commented May 12, 2020

When I output the raw json, the last_trade_id field is indeed always 0 from the heartbeat channel

`%v {"type":"heartbeat","last_trade_id":0,"product_id":"BTC-USD","sequence":14011426656,"time":"2020-05-12T05:20:06.782635Z"}
%v {"type":"heartbeat","last_trade_id":0,"product_id":"BTC-USD","sequence":14011426829,"time":"2020-05-12T05:20:07.782685Z"}
%v {"type":"heartbeat","last_trade_id":0,"product_id":"BTC-USD","sequence":14011427058,"time":"2020-05-12T05:20:08.782611Z"}
%v {"type":"heartbeat","last_trade_id":0,"product_id":"BTC-USD","sequence":14011427214,"time":"2020-05-12T05:20:09.782698Z"}
%v {"type":"heartbeat","last_trade_id":0,"product_id":"BTC-USD","sequence":14011427423,"time":"2020-05-12T05:20:10.782719Z"}
%v {"type":"heartbeat","last_trade_id":0,"product_id":"BTC-USD","sequence":14011427575,"time":"2020-05-12T05:20:11.782732Z"}
%v {"type":"heartbeat","last_trade_id":0,"product_id":"BTC-USD","sequence":14011427861,"time":"2020-05-12T05:20:12.782737Z"}
%v {"type":"heartbeat","last_trade_id":0,"product_id":"BTC-USD","sequence":14011428462,"time":"2020-05-12T05:20:13.782732Z"}`

@lukehollenback
Copy link
Author

Interesting. Likely the Coinbase Pro websocket feed itself then. I've opened a support issue (Case #02118345 - Heartbeat Message Last Trade ID Always Zero) with their team. We'll see.

@Zinfandel-al-Citadel
Copy link

I have same issue (not authorized, so not using api-keys atm, btw). Maybe cbp changed smth in their protocol and didnt update their website, yet? Perhaps they send strings instead of numbers? Did you check the raw response, bytewise, too?

@lukehollenback
Copy link
Author

I received this response a while back, but have not heard from them sense.

Hi Luke, thanks for this report. I'll share with our developers and see if they have any suggestions. In the meantime I'd ask that you continue troubleshooting on your end and let me know if you've come to a solution.

Kind regards,
Coinbase Support

@preichenberger
Copy link
Owner

Closing for now, feel free to reopen

@shrimpceviche
Copy link

This is 6 month later, still the trade_id from heartbeat is 0.

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

No branches or pull requests

4 participants