Examples

Python examples

■ BitMEX historical trades and order book data replay

import asyncio
from tardis_client import TardisClient, Channel
async def replay():
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)
async for 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 stream
print(message)
asyncio.run(replay())

Try on repl.it

■ Saving Deribit historical index data to CSV file

import asyncio
import csv
from tardis_client import TardisClient, Channel
async def save_historical_deribit_index_data_to_csv():
tardis_client = TardisClient()
messages = tardis_client.replay(
exchange="deribit",
from_date="2019-06-01",
to_date="2019-06-02",
filters=[Channel(name="deribit_price_index", symbols=["btc_usd", "eth_usd"])],
)
with open("./deribit_index_data.csv", mode="w") as csv_file:
fieldnames = ["symbol", "price", "timestamp"]
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writeheader()
async for local_timestamp, message in messages:
data = message["params"]["data"]
writer.writerow({"symbol": data["index_name"], "price": data["price"], "timestamp": data["timestamp"]})
print("finished")
asyncio.run(save_historical_deribit_index_data_to_csv())

Try on repl.it

Node.js examples

■ Derbit historical funding and storing it in CSV file

Derbit historical funding and storing it in CSV file

Try example above using run button - first change Node version to v12 in dropdown on the left

■ Binance trades and order book replay

Binance trades and order book replay

Try example above using run button - first change Node version to v12 in dropdown on the left

■ Saving Deribit trades to csv file

Saving Deribit trades to csv file

Try example above using run button - first change Node version to v12 in dropdown on the left

■ Deribit BTC_USD price index replay

Deribit BTC_USD price index replay

Try example above using run button - first change Node version to v12 in dropdown on the left

■ Bitstamp order book market by order (Level 3) order book replay

Bitstamp order book market by order (Level 3) order book replay

Try example above using run button - first change Node version to v12 in dropdown on the left

■ Using ccxws to connect to tardis-machine and replay historical data

Using ccxws to connect to tardis-machine and replay historical data

Try example above using run button - first change Node version to v12 in dropdown on the left

■ Deribit options historical tick by tick best bid and best ask data saved to csv file

Deribit options historical tick by tick best bid and best ask data saved to csv file

Try example above using run button - first change Node version to v12 in dropdown on the left