Search code examples
python-3.xpandasinfluxdbinfluxdb-python

How to properly write order book data into influxdb with same timestamp


I'm trying to store order book data into an influx db. This is what the data looks like:

Datetime           BidPrice BidSize    AskPrice  AskSize    Level

2018-08-15 09:21:15 6347.67 14.561605   6347.68 3.189313    0
2018-08-15 09:21:15 6347.52 2.351050    6348.10 0.102000    1
2018-08-15 09:21:15 6347.47 4.640000    6348.96 0.010000    2
2018-08-15 09:21:15 6346.20 2.902000    6349.00 0.300000    3
2018-08-15 09:21:15 6346.19 5.042739    6349.20 0.002000    4
2018-08-15 09:21:15 6346.13 1.072136    6349.22 0.433458    5
2018-08-15 09:21:15 6346.00 0.070000    6350.00 4.434813    6
2018-08-15 09:21:15 6345.50 0.002000    6350.15 0.170300    7
2018-08-15 09:21:15 6345.15 3.500000    6350.44 0.202500    8
2018-08-15 09:21:15 6345.00 0.100000    6350.54 0.001000    9
2018-08-15 09:21:15 6344.89 1.000000    6350.82 0.001000    10

The Level is the depth in the order book. So Level=0 would be top of the book. When I write points:

client.write_points(df,measurement='bidask',time_precision='s',database='orderbook_test',tags={'Market':'BTC/USD'},protocol='json')

since they all have the same timestamp, I only get the entry with Level=10. It overwrites the others. I'm guessing I need to some how put Level as a tag so that each row can be unique but I'm not sure how to do that.


Solution

  • I solved this by using tag_columns=['Level']