Python tardis-client provides simple and intuitive way of accessing Tardis.dev historical market data API. Detailed and most up to date documentation & installation instructions can be found on GitHub, but the gist of it is that you provide exchange name, historical date ranges and optional filters (channel names are the same as exchange's channels in real-time WebSocket feeds, same for symbols) and you receive an Async Generator that provides market data message for each iteration. Local disk-based caching is being done transparently in the background. Cached data is stored on disk in compressed form (GZIP) and decompressed on demand when reading the data. See example snippet below that shows how to replay some of the historical BitMEX data.
Requires Python 3.7.0+.
import asynciofrom tardis_client import TardisClient, Channelasyncdefreplay(): tardis_client =TardisClient()# replay method returns Async Generator# https://rickyhan.com/jekyll/update/2018/01/27/python36.html messages = tardis_client.replay( exchange="bitmex", from_date="2019-06-01", to_date="2019-06-02", filters=[Channel(name="trade", symbols=["XBTUSD","ETHUSD"]), Channel("orderBookL2", ["XBTUSD"]) ], )# this will print all trades and orderBookL2 messages for XBTUSD# and all trades for ETHUSD for bitmex exchange# between 2019-06-01T00:00:00.000Z and 2019-06-02T00:00:00.000Z #(whole first day of June 2019)asyncfor local_timestamp, message in messages:# local timestamp is a Python datetime that marks timestamp # when given message has been received# message is a message object as provided by exchange real-time streamprint(message)asyncio.run(replay())
Examples
■ BitMEX historical trades and order book data replay
import asynciofrom tardis_client import TardisClient, Channelasyncdefreplay(): tardis_client =TardisClient()# replay method returns Async Generator# https://rickyhan.com/jekyll/update/2018/01/27/python36.html messages = tardis_client.replay( exchange="bitmex", from_date="2019-06-01", to_date="2019-06-02", filters=[Channel(name="trade", symbols=["XBTUSD","ETHUSD"]), Channel("orderBookL2", ["XBTUSD"]) ], )# this will print all trades and orderBookL2 messages for XBTUSD# and all trades for ETHUSD for bitmex exchange# between 2019-06-01T00:00:00.000Z and 2019-06-02T00:00:00.000Z #(whole first day of June 2019)asyncfor local_timestamp, message in messages:# local timestamp is a Python datetime that marks timestamp # when given message has been received# message is a message object as provided by exchange real-time streamprint(message)asyncio.run(replay())
■ Saving Deribit historical index data to CSV file