Skip to content

Commit 3836f7d

Browse files
committed
Run autopep8, add default case for message stream match case
1 parent ae3f669 commit 3836f7d

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

piker/brokers/kucoin.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,12 @@ def _gen_auth_req_headers(
197197
'''
198198

199199
if not self._config:
200-
raise ValueError('No config found when trying to send authenticated request')
200+
raise ValueError(
201+
'No config found when trying to send authenticated request')
201202

202203
str_to_sign = (
203-
str(int(time.time() * 1000)) + action + f'/api/{api_v}{endpoint}'
204+
str(int(time.time() * 1000))
205+
+ action + f'/api/{api_v}{endpoint}'
204206
)
205207

206208
signature = base64.b64encode(
@@ -240,7 +242,8 @@ async def _request(
240242
241243
'''
242244
if self._config:
243-
headers = self._gen_auth_req_headers(action, endpoint, api_v)
245+
headers = self._gen_auth_req_headers(
246+
action, endpoint, api_v)
244247

245248
api_url = f'https://api.kucoin.com/api/{api_v}{endpoint}'
246249

@@ -271,7 +274,8 @@ async def _get_ws_token(
271274
'POST', f'/bullet-{token_type}', 'v1'
272275
)
273276
except Exception as e:
274-
log.error(f'Error making request for Kucoin ws token -> {str(e)}')
277+
log.error(
278+
f'Error making request for Kucoin ws token -> {str(e)}')
275279
return None
276280

277281
if data and 'token' in data:
@@ -371,7 +375,8 @@ async def _get_bars(
371375
end_dt = pendulum.now('UTC').add(minutes=1)
372376

373377
if start_dt is None:
374-
start_dt = end_dt.start_of('minute').subtract(minutes=limit)
378+
start_dt = end_dt.start_of(
379+
'minute').subtract(minutes=limit)
375380

376381
start_dt = int(start_dt.timestamp())
377382
end_dt = int(end_dt.timestamp())
@@ -429,7 +434,8 @@ async def _get_bars(
429434
)
430435
)
431436

432-
array = np.array(new_bars, dtype=_ohlc_dtype) if as_np else bars
437+
array = np.array(
438+
new_bars, dtype=_ohlc_dtype) if as_np else bars
433439
return array
434440

435441

@@ -497,7 +503,8 @@ async def stream_quotes(
497503
feed_is_live: trio.Event,
498504
loglevel: str = '',
499505
# startup sync
500-
task_status: TaskStatus[tuple[dict, dict]] = trio.TASK_STATUS_IGNORED,
506+
task_status: TaskStatus[tuple[dict, dict]
507+
] = trio.TASK_STATUS_IGNORED,
501508
) -> None:
502509
'''
503510
Required piker api to stream real-time data.
@@ -556,7 +563,7 @@ async def stream_quotes(
556563

557564

558565
@acm
559-
async def subscribe(ws: wsproto.WSConnection, connect_id, sym):
566+
async def subscribe(ws: wsproto.WSConnection, connect_id, sym) -> AsyncGenerator[None, None]:
560567
# level 2 sub
561568
await ws.send_msg(
562569
{
@@ -608,7 +615,8 @@ async def stream_messages(
608615
if cs.cancelled_caught:
609616
timeouts += 1
610617
if timeouts > 2:
611-
log.error('kucoin feed is sh**ing the bed... rebooting...')
618+
log.error(
619+
'kucoin feed is sh**ing the bed... rebooting...')
612620
await ws._connect()
613621

614622
continue
@@ -670,7 +678,8 @@ async def stream_messages(
670678
],
671679
}
672680

673-
681+
case _:
682+
log.warn(f'Unhandled message: {msg}')
674683

675684

676685
@acm
@@ -685,9 +694,9 @@ async def get_ohlc_history(
685694
end_dt: datetime | None = None,
686695
start_dt: datetime | None = None,
687696
) -> tuple[
688-
np.ndarray, datetime |
689-
None, datetime |
690-
None
697+
np.ndarray, datetime
698+
| None, datetime
699+
| None
691700
]: # start # end
692701
if timeframe != 60:
693702
raise DataUnavailable('Only 1m bars are supported')

0 commit comments

Comments
 (0)