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:
kingchenc
2026-05-22 12:20:19 +02:00
parent 6b468824ce
commit 783e40069d
+6
View File
@@ -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)