C8: skip non-kline frames in the live_trading example
The combined Binance stream interleaves the kline payloads with
subscription acks, heartbeats and error objects. The example pulled
k = payload.get("k", {}) and immediately did float(k.get("c")) — for
any non-kline frame k is {}, k.get("c") is None, and float(None) raises
TypeError, crashing the script the moment it connects.
Skip frames without a kline payload (no "k" object, or no "c" close
field) with a debug log line, matching the C2 fix on the Rust adapter.
This commit is contained in:
@@ -96,6 +96,12 @@ async def run(symbol: str, interval: str) -> None:
|
||||
envelope = json.loads(raw)
|
||||
payload = envelope.get("data", {})
|
||||
k = payload.get("k", {})
|
||||
if not k or "c" not in k:
|
||||
# Subscription acks, heartbeats and error frames carry no
|
||||
# kline payload — skip them instead of crashing on
|
||||
# float(None) the moment the stream opens.
|
||||
log.debug("skipping non-kline frame: %s", raw)
|
||||
continue
|
||||
close = float(k.get("c"))
|
||||
is_closed = bool(k.get("x"))
|
||||
snap = state.update(close)
|
||||
|
||||
Reference in New Issue
Block a user