From 556f31b1ccac17273125c07bf87d9e7da5d751f9 Mon Sep 17 00:00:00 2001 From: Carlo Eugster Date: Wed, 29 May 2024 15:06:08 +0200 Subject: [PATCH] Fix persisting Kraken trades in QuestDB (#1039) * Conditional `id` setting for QuestDB trade inserts The Kraken ws API does not return a `trade_id`. When the Quest backend tries to insert a record with a `None` id it will just ignore that insert. * Updated changelog --- AUTHORS.md | 1 + CHANGES.md | 1 + cryptofeed/backends/quest.py | 7 +++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 84f7bc00d..576c0fae1 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -16,3 +16,4 @@ Cryptofeed was originally created by Bryant Moscon, but many others have contrib * [Jonggyun Kim](https://github.com/gyunt) - * [QuasarDB](https://quasar.ai/) * [Thomas Bouamoud](https://github.com/thomasbs17) - +* [Carlo Eugster](https://github.com/carloe) - \ No newline at end of file diff --git a/CHANGES.md b/CHANGES.md index 653a87874..99fd6d063 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ * Update: transitioned from Coinbase Pro (retired) to Coinbase Advanced Trade * Feature: Bybit spot support * Update: Bybit migrate to API V5 for public streams + * Bugfix: Handle None ids for Kraken trades in QuestDB ### 2.4.0 (2024-01-07) * Update: Fix tests diff --git a/cryptofeed/backends/quest.py b/cryptofeed/backends/quest.py index a1a89c82b..d0660f629 100644 --- a/cryptofeed/backends/quest.py +++ b/cryptofeed/backends/quest.py @@ -54,9 +54,12 @@ class TradeQuest(QuestCallback, BackendCallback): async def write(self, data): timestamp = data["timestamp"] received_timestamp_int = int(data["receipt_timestamp"] * 1_000_000) + id_field = f'id={data["id"]}i,' if data["id"] is not None else '' timestamp_int = int(timestamp * 1_000_000_000) if timestamp is not None else received_timestamp_int * 1000 - update = f'{self.key}-{data["exchange"]},symbol={data["symbol"]},side={data["side"]},type={data["type"]} ' \ - f'price={data["price"]},amount={data["amount"]},id={data["id"]}i,receipt_timestamp={received_timestamp_int}t {timestamp_int}' + update = ( + f'{self.key}-{data["exchange"]},symbol={data["symbol"]},side={data["side"]},type={data["type"]} ' + f'price={data["price"]},amount={data["amount"]},{id_field}receipt_timestamp={received_timestamp_int}t {timestamp_int}' + ) await self.queue.put(update)