From a0522da8c4c5f8a48541832e06b6fce2c129044c Mon Sep 17 00:00:00 2001 From: Steve Sklar Date: Mon, 18 May 2026 14:29:29 -0400 Subject: [PATCH] Fix OKX spot symbol bootstrap --- demo_questdb.py | 18 +++++++++++++++++- pyproject.toml | 1 - 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/demo_questdb.py b/demo_questdb.py index 229cb9f..2d5c2e4 100644 --- a/demo_questdb.py +++ b/demo_questdb.py @@ -7,6 +7,7 @@ from cryptofeed import FeedHandler from cryptofeed.backends.backend import BackendCallback from cryptofeed.backends.socket import SocketCallback +from cryptofeed.connection import RestEndpoint, Routes from cryptofeed.defines import TRADES from cryptofeed.exchanges import OKX @@ -15,6 +16,21 @@ QUEST_PORT = 9009 +class OKXSpot(OKX): + # cryptofeed initializes OKX by parsing every instrument type, but OKX now + # returns some FUTURES instIds without the expiry segment cryptofeed expects. + # This demo only subscribes to spot trades, so load only SPOT metadata. + rest_endpoints = [ + RestEndpoint('https://www.okx.com', routes=Routes([ + '/api/v5/public/instruments?instType=SPOT', + ])) + ] + + @classmethod + def _parse_symbol_data(cls, data): + return super()._parse_symbol_data([data] if isinstance(data, dict) else data) + + class QuestCallback(SocketCallback): def __init__(self, host='127.0.0.1', port=9009, **kwargs): super().__init__(f"tcp://{host}", port=port, **kwargs) @@ -67,7 +83,7 @@ def main(): # USDT is almost USD symbols = [s.replace("-USD", "-USDT") if not s.endswith('-USDT') and not s.endswith('-USDC') else s for s in symbols] - hanlder.add_feed(OKX(channels=[TRADES], symbols=symbols, + hanlder.add_feed(OKXSpot(channels=[TRADES], symbols=symbols, callbacks={TRADES: TradeQuest(host=host, port=port)})) hanlder.run() diff --git a/pyproject.toml b/pyproject.toml index 4195cdb..67fcc9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,6 @@ description = "QuestDB demo website injection app" authors = ["QuestDB"] license = "Apache 2.0" readme = "README.md" -package-mode = false [tool.poetry.dependencies] python = "^3.11"