MCPcopy Create free account
hub / github.com/danpaquin/coinbasepro-python / _connect

Method _connect

cbpro/websocket_client.py:63–89  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

61 self.thread.start()
62
63 def _connect(self):
64 if self.products is None:
65 self.products = ["BTC-USD"]
66 elif not isinstance(self.products, list):
67 self.products = [self.products]
68
69 if self.url[-1] == "/":
70 self.url = self.url[:-1]
71
72 if self.channels is None:
73 self.channels = [{"name": "ticker", "product_ids": [product_id for product_id in self.products]}]
74 sub_params = {'type': 'subscribe', 'product_ids': self.products, 'channels': self.channels}
75 else:
76 sub_params = {'type': 'subscribe', 'product_ids': self.products, 'channels': self.channels}
77
78 if self.auth:
79 timestamp = str(time.time())
80 message = timestamp + 'GET' + '/users/self/verify'
81 auth_headers = get_auth_headers(timestamp, message, self.api_key, self.api_secret, self.api_passphrase)
82 sub_params['signature'] = auth_headers['CB-ACCESS-SIGN']
83 sub_params['key'] = auth_headers['CB-ACCESS-KEY']
84 sub_params['passphrase'] = auth_headers['CB-ACCESS-PASSPHRASE']
85 sub_params['timestamp'] = auth_headers['CB-ACCESS-TIMESTAMP']
86
87 self.ws = create_connection(self.url)
88
89 self.ws.send(json.dumps(sub_params))
90
91 def _keepalive(self, interval=30):
92 while self.ws.connected:

Callers 1

_goMethod · 0.95

Calls 1

get_auth_headersFunction · 0.90

Tested by

no test coverage detected