From 783e40069d179e699abe9b163353e1a8414d715b Mon Sep 17 00:00:00 2001 From: kingchenc Date: Fri, 22 May 2026 12:20:19 +0200 Subject: [PATCH] C8: skip non-kline frames in the live_trading example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- examples/python/live_trading.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/python/live_trading.py b/examples/python/live_trading.py index d3f9b71a..810ad829 100644 --- a/examples/python/live_trading.py +++ b/examples/python/live_trading.py @@ -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)