Bitfinex Continuous Downloader (dccd.continuous_dl.bitfinex
)¶
Objects and functions to download data from Bitfinex exchange.
These functions and objects allow you to continuously download data and update your database.
High level API¶
-
dccd.continuous_dl.bitfinex.
get_data_bitfinex
(channel, process_func, process_params={}, save_method='dataframe', io_params={}, time_step=60, until=None, path=None, **kwargs)¶ Download data from Bitfinex exchange and update the database.
Parameters: - channel : str, {‘book’, ‘book_raw’, ‘trades’, ‘trades_raw’}
Websocket channel to get data, by default data will be aggregated (OHLC for ‘trades’ and reconstructed orderbook for ‘book’), add ‘_raw’ to the channel to get raw data (trade tick by tick or each orders).
- process_func : callable
Function to process and clean data before to be saved. Must take data in arguments and can take any optional keywords arguments, cf function exemples in
dccd.process_data
.- process_params : dict, optional
Dictionary of the keyword arguments available to process_func, cf documentation into
dccd.process_data
.- save_method : {‘DataFrame’, ‘SQLite’, ‘CSV’, ‘Excel’, ‘PostgreSQL’, ‘Oracle’, ‘MSSQL’, ‘MySQL’},
It will create an IODataBase object to save/update the database in the specified format save_method, default is ‘DataFrame’ it save as binary pd.DataFrame object. More informations are available into
dccd.tools.io
.- io_params : dict, optional
Dictionary of the keyword arguments available to the
dccd.tools.io.IODataBase
callable method. Note: With SQL format some parameters are compulsory, see details intodccd.tools.io
.- time_step : int, optional
Number of second between two snapshots of data, default 60 (1 minute).
- until : int, optional
Number of seconds before stoping to download and update, default is None. If until equal 0 or None it means it never stop.
- path : str, optional
Path to save/update the database, default is None. If path is None, database is saved at the relative path ‘./database/bitfinex/channel’.
- **kwargs
Any revelevant keyword arguments will be passed to the websocket connector, see Bitfinex API documentation [2] for more details.
Warning
‘book_raw’ and ‘trades_raw’ can be very memory expensive.
See also
process_data
- function to process/clean data (set_marketdepth, set_ohlc, set_orders, set_marketdepth).
tools.io.IODataBase
- object to save/update the database with respect to specified format.
References
[2] https://docs.bitfinex.com/v2/docs/ws-public
-
dccd.continuous_dl.bitfinex.
get_orderbook_bitfinex
(symbol, precision='P0', frequency='F0', lenght='25', time_step=60, until=None, path=None, save_method='dataframe', io_params={})¶ Download orderbook from Bitfinex exchange.
-
dccd.continuous_dl.bitfinex.
get_trades_bitfinex
(symbol, time_step=60, until=None, path=None, save_method='dataframe', io_params={})¶ Download trades tick by tick from Bitfinex exchange.
Low level API¶
-
class
dccd.continuous_dl.bitfinex.
DownloadBitfinexData
(time_step=60, until=3600)¶ Bases:
dccd.continuous_dl.exchange.ContinuousDownloader
Basis object to download data from a stream websocket client API.
Parameters: - time_step : int, optional
Number of seconds between two snapshots of data, minimum is 1, default is 60 (one minute). Each time_step data will be processed and updated to the database.
- until : int, optional
Number of seconds before stoping or timestamp of when stoping, default is 3600 (one hour).
Attributes: - host : str
Adress of host to connect.
- conn_par : dict
Parameters of websocket connection.
- ws : websockets.client.WebSocketClientProtocol
Connection with the websocket client.
- is_connect : bool
True if is connected, False otherwise.
- ts : int
Number of second between two snapshots of data.
- t : int
Current timestamp but rounded by ts.
- until : int
Timestamp to stop to download data.
Methods
set_process_data
(self, func, \*\*kwargs)Set processing function. set_saver
(self, call, \*\*kwargs)Set saver object to save data or update a database. __call__
(self, channel, \*\*kwargs)Open a websocket connection and save/update the database. -
__call__
(self, channel, **kwargs)¶ Open a websocket connection and save/update the database.
Run asynchronously two loops to get data from bitfinex websocket and save/update the database.
Parameters: - channel : {‘book’, ‘book_raw’, ‘trades’, ‘trades_raw’}
Channel to get data, by default data will be aggregated (OHLC for ‘trades’ and reconstructed orderbook for ‘book’), add ‘_raw’ to the channel to get raw data (trade tick by tick or each orders).
- **kwargs
Any revelevant keyword arguments will be passed to the websocket connector, see API documentation [1] for more details.
Warning
‘book_raw’ and ‘trades_raw’ can be very memory expensive.
References
[1] https://docs.bitfinex.com/v2/docs/ws-public
-
get_parser
(self, key)¶ Get allowed data parser.
Parameters: - key : str
Name code of data to parse. If key is not allowed then return a debug_parser which will display data structure.
Returns: - function
The allowed function to parse this kind of data.
-
on_close
(self)¶ On websocket close print and fire event.
-
on_error
(self, error, *args)¶ On websocket error print and fire event.
-
on_message
(self, data)¶ Set data to order book.
-
on_open
(self, **kwargs)¶ On websocket open.
Parameters: - **kwargs
Any relevant keyword arguments to set connection.
-
parser_book
(self, data)¶ Parse market depth of order book.
Parameters: - data : list
Order data.
-
parser_raw_book
(self, data)¶ Parse raw order book, each timestep set in a list all orders.
Parameters: - data : list
Order data.
-
parser_raw_trades
(self, data)¶ Parse trade data.
Parameters: - data : list
Trade data.
-
parser_trades
(self, data)¶ Parse OHLC data.
Parameters: - data : list
Trade data.
-
set_process_data
(self, func, **kwargs)¶ Set processing function.
Parameters: - func : callable
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
(self, call, **kwargs)¶ Set saver object to save data or update a database.
Parameters: - call : callable
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.
-
wait_that
(self, is_true)¶ Wait before running.