From 1a655b7e396b96898616a4898c046e72ddc04778 Mon Sep 17 00:00:00 2001 From: jaredgoldman Date: Sat, 11 Mar 2023 16:21:42 -0500 Subject: [PATCH] Ensure we're passing the correct api version to the header builder, make headers a default arg --- piker/brokers/kucoin.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/piker/brokers/kucoin.py b/piker/brokers/kucoin.py index 1a7861cb..f4ef0b97 100644 --- a/piker/brokers/kucoin.py +++ b/piker/brokers/kucoin.py @@ -15,10 +15,9 @@ # along with this program. If not, see . """ - +Kucoin broker backend """ -from logging import warning from typing import Any, Optional, Literal from contextlib import asynccontextmanager as acm from datetime import datetime @@ -41,10 +40,6 @@ from piker.log import get_logger from ._util import DataUnavailable from piker.pp import config -_spawn_kwargs = { - "infect_asyncio": True, -} - log = get_logger(__name__) _ohlc_dtype = [ ("index", int), @@ -68,7 +63,7 @@ class Client: self._authenticated: bool = False config = get_config() - breakpoint() + if ("key_id" in config) and \ ("key_secret" in config) and \ ("key_passphrase" in config): @@ -83,11 +78,13 @@ class Client: endpoint: str, api_v: str = "v2", ): + ''' + https://docs.kucoin.com/#authentication + ''' now = int(time.time() * 1000) path = f'/api/{api_v}{endpoint}' str_to_sign = str(now) + action + path - # Add headers to request if authenticated signature = base64.b64encode( hmac.new( self._key_secret.encode('utf-8'), @@ -109,7 +106,7 @@ class Client: "KC-API-TIMESTAMP": str(now), "KC-API-KEY": self._key_id, "KC-API-PASSPHRASE": passphrase, - "KC-API-KEY-VERSION": "2" + "KC-API-KEY-VERSION": api_v[1] } async def _request( @@ -117,8 +114,8 @@ class Client: action: Literal["POST", "GET", "PUT", "DELETE"], endpoint: str, api_v: str = "v2", + headers: dict = {} ) -> Any: - headers = {} if self._authenticated: headers = self._gen_auth_req_headers(action, endpoint, api_v)