repl.it
@TardisThad/

saving-deribit-index-historical-data-to-csv

Python

No description

fork
loading
Files
  • main.py
  • deribit_index_data.csv
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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())