Skip to content

Commit 9880927

Browse files
committed
Address CodeRabbit review comments on PR #76
- Fix StateUpdate type alias to accept Optional[dict] for the callback's third parameter, since None is passed on initial snapshot - Skip keepalive frames received before the initial snapshot to prevent MarketInitialisationException on startup - Correct the pair parameter docstring from describing an amount to describing the currency pair code
1 parent 8be5204 commit 9880927

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

luno_python/stream_client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
import asyncio
99
from decimal import Decimal
1010
import json
11-
from typing import Callable, Dict, List
11+
from typing import Callable, Dict, List, Optional
1212
import websockets
1313

1414
from .api_types import DEC_0, Order, MarketState, Pair
1515

1616
DEFAULT_URL = "wss://ws.luno.com"
1717

18-
StateUpdate = Callable[[Pair, MarketState, dict], None]
18+
StateUpdate = Callable[[Pair, MarketState, Optional[dict]], None]
1919

2020
class OutOfOrderMessageException(Exception):
2121
pass
@@ -145,6 +145,9 @@ async def _read_from_websocket(ws, pair: Pair, update_f: StateUpdate):
145145
if body == "": # Empty update, used as keepalive
146146
body = None
147147

148+
if body is None and is_first:
149+
continue
150+
148151
if is_first:
149152
is_first = False
150153
state = _MarketStreamState(body)
@@ -174,7 +177,7 @@ async def stream_market(
174177
175178
Stream orderbook information and maintain an orderbook state.
176179
177-
:param pair: str Amount to buy or sell in the pair base currency.
180+
:param pair: str Currency pair code (for example, "XBTZAR").
178181
:param api_key_id: str
179182
:param api_key_secret: str
180183
:param update_callback: an StateUpdate function that will be called with new updates.

0 commit comments

Comments
 (0)