Skip to content

Commit

Permalink
Added websocket pinger to keep connection alive
Browse files Browse the repository at this point in the history
  • Loading branch information
danpaquin committed Jul 20, 2017
1 parent 26ba493 commit d2f8831
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions gdax/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ def __init__(self, url="wss://ws-feed.gdax.com", products=None, message_type="su
self.api_secret = api_secret
self.api_passphrase = api_passphrase

def _auth_message(self, method, path, options=None):


return auth

def start(self):
def _go():
self._connect()
Expand Down Expand Up @@ -73,6 +68,9 @@ def _connect(self):
def _listen(self):
while not self.stop:
try:
if int(time.time() % 30) == 0:
# Set a 30 second ping to keep connection alive
self.ws.ping("keepalive")
msg = json.loads(self.ws.recv())
except Exception as e:
self.on_error(e)
Expand Down Expand Up @@ -101,7 +99,7 @@ def on_message(self, msg):
print(msg)

def on_error(self, e):
return
print(e)

if __name__ == "__main__":
import gdax
Expand All @@ -126,7 +124,7 @@ def on_close(self):
wsClient.start()
print(wsClient.url, wsClient.products)
# Do some logic with the data
while wsClient.message_count < 500:
while wsClient.message_count < 10000:
print("\nMessageCount =", "%i \n" % wsClient.message_count)
time.sleep(1)

Expand Down

0 comments on commit d2f8831

Please sign in to comment.