Closed NotoriousPyro closed 6 months ago
WSS retrieves only future candle updates.
WSS retrieves candle updates which are from the past. A candle was retrieved from WSS which is behind the REST socket candles:
I haven't got one yet, other than checking the deque for duplicates.
candles_update
Reproduction code:
from bfxapi import Client, PUB_REST_HOST, PUB_WSS_HOST from bfxapi.types import Candle from bfxapi.websocket.subscriptions import Candles from bfxapi.websocket.enums import Channel from collections import deque from datetime import datetime, timedelta bfx = Client(rest_host=PUB_REST_HOST, wss_host=PUB_WSS_HOST) @bfx.wss.on("open") async def on_open(): await bfx.wss.subscribe(Channel.CANDLES, key="trade:1m:tBTCUSD") class CandleHolder(): candles: deque[Candle] = deque() candle_holder = CandleHolder() @bfx.wss.on("candles_update") def on_candles_update(subscription: Candles, data: Candle): candle_holder.candles.append(data) def main(): start_date = int((datetime.now() - timedelta(minutes=5)).timestamp()) candle_holder.candles = bfx.rest.public.get_candles_hist( tf='1m', symbol='tBTCUSD', sort="+1", start=f"{start_date}000" ) if not any(candle_holder.candles): raise ValueError("No candles.") bfx.wss.run() if __name__ == "__main__": main()
Python 3.11.4 x64
Not installed and not relevant to the issue.
Hi @NotoriousPyro, this isn't a bitfinex-api-py's bug. This weird behavior is due to how the API works. We discourage using REST and WSS together.
I'm submitting a...
What is the expected behaviour?
WSS retrieves only future candle updates.
What is the current behaviour?
WSS retrieves candle updates which are from the past. A candle was retrieved from WSS which is behind the REST socket candles:
Possible solution (optional)
I haven't got one yet, other than checking the deque for duplicates.
Steps to reproduce (for bugs)
candles_update
and append the data to the same list.Reproduction code:
Python version
Python 3.11.4 x64
Mypy version
Not installed and not relevant to the issue.