DownloadBybitData¶
Defined in dccd.continuous_dl.bybit
- class DownloadBybitData(pair='BTCUSDT', time_step=60, until=3600, checkpoint_dir=None)[source]
Bases:
ContinuousDownloaderDownload data continuously from Bybit via WebSocket v5.
- Parameters:
- pairstr
Trading pair symbol (e.g. ‘BTCUSDT’).
- time_stepint, optional
Seconds between data snapshots, default is 60.
- untilint, optional
Seconds to run or stop timestamp, default is 3600.
- Attributes:
- hoststr
WebSocket URL.
- is_connectbool
True if connected.
- tsint
Snapshot interval in seconds.
- untilint
Stop timestamp.
Methods
set_process_data(func, **kwargs)Set processing function.
set_saver(call, **kwargs)Set saver object to save data or update a database.
__call__(*args, **kwargs)Start the WebSocket stream and block until it stops.
- __call__(*args, **kwargs)
Start the WebSocket stream and block until it stops.
- Parameters:
- *args, **kwargs
Forwarded to
_connect.
- Returns:
- ContinuousDownloader
The downloader instance (for chaining).
- get_parser(key)
Get allowed data parser.
- Parameters:
- keystr
Name code of data to parse.
- Returns:
- function
The allowed function to parse this kind of data.
- Raises:
- KeyError
If key is not in the allowed parser keys.
- on_close()
On websocket close print and fire event.
- async on_error(error, *args)
On websocket error print and fire event.
- async on_message(msg)[source]
Dispatch incoming WebSocket messages.
- on_open(**kwargs)
On websocket open.
- Parameters:
- **kwargs
Any relevant keyword arguments to set connection.
- parser_book(msg)[source]
Parse and update order book from WebSocket messages.
- Parameters:
- msgdict
Raw WebSocket orderbook message.
- parser_trades(msg)[source]
Parse and store trade messages.
- Parameters:
- msgdict
Raw WebSocket trade message.
- set_book_saver(saver, process_func=<function set_marketdepth>, **kwargs)
Set saver for the order-book channel.
- Parameters:
- savercallable
Callable to persist the processed DataFrame (e.g.
IODataBase).- process_funccallable, optional
Function to convert the book dict to a DataFrame, default is
dccd.process_data.set_marketdepth.- **kwargs
Extra keyword arguments forwarded to
saveron each call.
- set_process_data(func, **kwargs)
Set processing function.
- Parameters:
- funccallable
Function to process and clean data before to be saved. Must take data in arguments and can take any optional keywords arguments, cf exemples in
dccd.process_data.- **kwargs
Any keyword arguments to be passed to func.
- set_saver(call, **kwargs)
Set saver object to save data or update a database.
- Parameters:
- callcallable
Callable object to save data or update a database. Must take data in arguments and can take any optional keywords arguments, cf exemples in
dccd.io_tools.- **kwargs
Any keyword arguments to be passed to call.
- set_trades_saver(saver, process_func=<function set_trades>, **kwargs)
Set saver for the trades channel.
- Parameters:
- savercallable
Callable to persist the processed DataFrame (e.g.
IODataBase).- process_funccallable, optional
Function to convert raw trade list to a DataFrame, default is
dccd.process_data.set_trades.- **kwargs
Extra keyword arguments forwarded to
saveron each call.
- async wait_that(is_true)
Wait before running.