def connect( self ) -> List[Tuple[AsyncConnection, Callable[[None], None], Callable[ [str, float], None]]]: authenticated = [] public = [] ret = [] for channel in self.subscription or self.channels: if is_authenticated_channel(channel): authenticated.extend( self.subscription.get(channel) or self.symbols) else: public.extend(self.subscription.get(channel) or self.symbols) if authenticated: header = generate_token(self.key_id, self.key_secret, "/v1/order/events", self.config.gemini.account_name) symbols = '&'.join([ f"symbolFilter={s.lower()}" for s in authenticated ]) # needs to match REST format (lower case) ret.append( self._connect_builder(f"{self.address['auth']}?{symbols}", None, header=header, sub=self._empty_subscribe, handler=self.message_handler_orders)) if public: ret.append( self._connect_builder(self.address['public'], list(set(public)))) return ret
def _post(self, command: str, payload=None): headers = generate_token(self.config.key_id, self.config.key_secret, command, account_name=self.config.account_name, payload=payload) headers['Content-Type'] = "text/plain" headers['Content-Length'] = "0" headers['Cache-Control'] = "no-cache" api = self.api if not self.sandbox else self.sandbox_api api = f"{api}{command}" resp = requests.post(api, headers=headers) self._handle_error(resp, LOG) return resp.json()