Skip to content

Commit

Permalink
Fix persisting Kraken trades in QuestDB (#1039)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
carloe authored May 29, 2024
1 parent 7e0c611 commit 556f31b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Cryptofeed was originally created by Bryant Moscon, but many others have contrib
* [Jonggyun Kim](https://github.com/gyunt) - <truth0233@gmail.com>
* [QuasarDB](https://quasar.ai/)
* [Thomas Bouamoud](https://github.com/thomasbs17) - <thomasbs17@yahoo.fr>
* [Carlo Eugster](https://github.com/carloe) - <carlo@relaun.ch>
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions cryptofeed/backends/quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 556f31b

Please sign in to comment.