DownloadOKXData¶
Defined in dccd.continuous_dl.okx
- class DownloadOKXData(pair='BTC-USDT', time_step=60, until=3600, span=None, checkpoint_dir=None)[source]
Bases:
ContinuousDownloaderDownload data continuously from OKX via WebSocket v5.
- Parameters:
- pairstr
Trading pair in OKX format (e.g. ‘BTC-USDT’).
- time_stepint, optional
Seconds between data snapshots, default is 60.
- untilint, optional
Seconds to run or stop timestamp, default is 3600.
- spanint, optional
Candle interval in seconds; if given, subscribes to the candle channel in addition to trades and book. Default is None.
- 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 OKX WebSocket push messages.
- Parameters:
- msgdict
OKX push message with
arganddatafields.
- on_open(**kwargs)
On websocket open.
- Parameters:
- **kwargs
Any relevant keyword arguments to set connection.
- parser_book(msg)[source]
Parse and update the order book from a books push message.
- Parameters:
- msgdict
Full OKX books push message (contains
actionanddata).
- parser_kline(data)[source]
Parse and store a candle push message.
- Parameters:
- datalist of list
The
datafield from the OKX candle push message.
- parser_trades(data)[source]
Parse and store a trades push message.
- Parameters:
- datalist of dict
The
datafield from the OKX trades push 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.