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

No option for heartbeat subscription #28

Closed
its-sarin opened this issue May 14, 2017 · 6 comments
Closed

No option for heartbeat subscription #28

its-sarin opened this issue May 14, 2017 · 6 comments

Comments

@its-sarin
Copy link

Are there any plans to extend the class to include the ability to subscribe to heartbeats? As of now I see no way to handle this.

@danpaquin
Copy link
Owner

Great callout @trecchia . I will get working on this after all additional endpoints are supported.

danpaquin added a commit that referenced this issue May 17, 2017
@danpaquin
Copy link
Owner

Please see the commit mentioned here. I have added this functionality, but when I send the message to the websocket server, no responses are received.

@danpaquin
Copy link
Owner

Hi @trecchia -- After making this change, I am still having trouble receiving messages. I attempted this in my original testing, but have committed this for your review. I apologize for the late response and not tagging the most recent commit with this issue.

@its-sarin
Copy link
Author

Hey @danpaquin, so I think the problem is using "is" for equality comparison. Because "is" is an identity comparison, I believe it won't consider those two strings to be True and thus neither condition is actually met. Try changing it to:

        if self.type == "subscribe":
            sub_params['product_ids'] = self.products
        elif self.type == "heartbeat":
            sub_params['on'] = "true"

That said, another thing I noticed when attempting to get this to work myself was that you need to send two separate messages to GDAX in order for it to work. So you'd need to do a self.ws.send(json.dumps(sub_params)) twice- once for the product subscription and another for the heartbeat. Let me know if this makes sense/helps!

@danpaquin
Copy link
Owner

This has been completed. Thank you for your help @trecchia. See below for my implementation. I will be closing this out in 48 hours if there are no more issues.

import GDAX, time
class myWebsocketClient(GDAX.WebsocketClient):
    def onOpen(self):
        self.type = "heartbeat"
        self.url = "wss://ws-feed.gdax.com/"
        self.products = ["BTC-USD", "ETH-USD"]
        self.MessageCount = 0
        print "Lets count the messages!"
    def onMessage(self, msg):
        if msg['type'] == "heartbeat":
            print(msg)
        #else:
            #print "Message type:", msg["type"], "\t@ %.3f" % float(msg["price"])
        self.MessageCount += 1
    def onClose(self):
        print("-- Goodbye! --")

wsClient = myWebsocketClient()
wsClient.start()
#print (wsClient.url, wsClient.products)
# Do some logic with the data
while (wsClient.MessageCount < 500 and not wsClient.stop):
    time.sleep(1)
    print ("\nMessageCount =", "%i \n" % wsClient.MessageCount)
wsClient.close()

@its-sarin
Copy link
Author

Yep this did it- working on my end with these changes. Thank you!

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

2 participants