Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion demo_questdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading