3

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.

bloodynri
  • 543
  • 1
  • 6
  • 14
  • Out of curiosity, how do you query your data to get the orderbook? Do you get all points for given `datetime` or query by `levels`? – Tom Raganowicz Jul 20 '19 at 09:49
  • Yes query by a given datetime gives me the entire order book snapshot. If I query by levels, say level 0, it will give me the top of the book data. – bloodynri Jul 21 '19 at 13:14
  • 1. If you search for the e.g.: `2018-08-15 09:22:16`, but there is none and there is snapshot at `2018-08-15 09:22:03` and 2018-08-15 09:22:33` how do you find them? 2. It is easily possible to get the full order book snapshot or the exact level, but how do you get the let's say level 0 to 4, the range queries doesn't seem to work correctly on tags, or am I wrong? Thanks – Tom Raganowicz Jul 21 '19 at 20:45
  • 1
    They worked for me. What I used to do was pull in the entire dataset and then do a Pandas groupby on the index. If I wanted just the top 5 levels l, in my query I used to add where Level <= 4. Then do a groupby. – bloodynri Jul 22 '19 at 23:01

1 Answers1

0

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

bloodynri
  • 543
  • 1
  • 6
  • 14