danpaquin / coinbasepro-python

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

Authenticated websocket client disconnects at 1-minute mark. #276

Closed royitaqi closed 6 years ago

royitaqi commented 6 years ago

Commit b1044a33281472778ac232615b723dbbb79dabfa Python 3.5.2 I have read issue #53 and #51, but am not sure this is exactly the same issue.

I tried to subscribe to "user" channel (authenticated) and the connection closed very soon. Retried many times and they all die after the 1-minute mark. I'm guessing this is a heartbeat problem.

Below is the output:

$ python test.py -a int
2018-03-14 10:17:15.562519 GdaxUser: opening
2018-03-14 10:17:16.143786 GdaxUser: received message: %s {'type': 'subscriptions', 'channels': [{'product_ids': ['ETH-USD'], 'name': 'user'}]}
Connection is already closed. - data: None
2018-03-14 10:18:15.935582 GdaxUser: closing. Terminating process.
Killed

My minimal test code is this:

import gdax
import os
import sys
import datetime

auths = {
    'int': {
        'passphrase': '...',
        'key': '...',
        'secret': '...',
        'wss_url': 'wss://ws-feed.gdax.com',
    },
}

import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--auth', help="The authentication profile to use", type=str, required=True, choices=list(auths.keys()))
args = parser.parse_args(sys.argv[1:])

product = 'ETH-USD'
channels = ['user']

class GdaxUser(gdax.WebsocketClient):
    def __init__(self):
        gdax.WebsocketClient.__init__(self)

        self.url = auths[args.auth]['wss_url']
        self.products = [product]
        self.channels = channels
        self.should_print = True

        self.auth = True
        self.api_key = auths[args.auth]['key']
        self.api_secret = auths[args.auth]['secret']
        self.api_passphrase = auths[args.auth]['passphrase']

    def on_open(self):
        print(datetime.datetime.now(), 'GdaxUser: opening')

    def on_message(self, msg):
        print(datetime.datetime.now(), 'GdaxUser: received message: %s', msg)

    def on_close(self):
        print(datetime.datetime.now(), 'GdaxUser: closing. Terminating process.')
        os.kill(os.getpid(), 9)

wsclient = GdaxUser()
wsclient.start()

I tried a similar piece of code but subscribe to "level2" and/or "ticker" channels and they seem to work fine. The problem appear to only happen when I'm subscribing to "user" channel.

royitaqi commented 6 years ago

Apparently this issue is a dupe with #256