Getting same/wrong OHLC throughout the day

raw_orb
Hi, I have been getting same/wrong ticks for TVSMOTOR (2170625). Here's an example from yesterday (08/10/2020):-

(I've converted the second based ticks into minute based.)


Whereas here's the chart on Kite for the same time period:-


As far as I can see, everything else seems to be working alright in the tick except the OHLC. Here's an example:-

[{'tradable': True, 'mode': 'full', 'instrument_token': 2170625, 'last_price': 475.4, 'last_quantity': 1, 'average_price': 477.87, 'volume': 3538449, 'buy_quantity': 225727, 'sell_quantity': 247933, 'ohlc': {'open': 481.55, 'high': 486.0, 'low': 473.45, 'close': 478.75}, 'change': -0.6997389033942606, 'last_trade_time': datetime.datetime(2020, 10, 8, 15, 18, 33), 'oi': 0, 'oi_day_high': 0, 'oi_day_low': 0, 'timestamp': datetime.datetime(2020, 10, 8, 15, 18, 33), 'depth': {'buy': [{'quantity': 119, 'price': 475.15, 'orders': 3}, {'quantity': 13, 'price': 475.1, 'orders': 1}, {'quantity': 416, 'price': 475.05, 'orders': 2}, {'quantity': 202, 'price': 475.0, 'orders': 2}, {'quantity': 13, 'price': 474.95, 'orders': 1}], 'sell': [{'quantity': 673, 'price': 475.4, 'orders': 3}, {'quantity': 871, 'price': 475.45, 'orders': 4}, {'quantity': 864, 'price': 475.5, 'orders': 5}, {'quantity': 936, 'price': 475.55, 'orders': 6}, {'quantity': 26, 'price': 475.6, 'orders': 1}]}}]

[{'tradable': True, 'mode': 'full', 'instrument_token': 2170625, 'last_price': 475.6, 'last_quantity': 50, 'average_price': 477.81, 'volume': 3611589, 'buy_quantity': 213675, 'sell_quantity': 226107, 'ohlc': {'open': 481.55, 'high': 486.0, 'low': 473.45, 'close': 478.75}, 'change': -0.6579634464751911, 'last_trade_time': datetime.datetime(2020, 10, 8, 15, 20, 35), 'oi': 0, 'oi_day_high': 0, 'oi_day_low': 0, 'timestamp': datetime.datetime(2020, 10, 8, 15, 20, 36), 'depth': {'buy': [{'quantity': 1071, 'price': 475.6, 'orders': 1}, {'quantity': 175, 'price': 475.55, 'orders': 2}, {'quantity': 200, 'price': 475.5, 'orders': 2}, {'quantity': 13, 'price': 475.45, 'orders': 1}, {'quantity': 262, 'price': 475.4, 'orders': 1}], 'sell': [{'quantity': 564, 'price': 475.75, 'orders': 3}, {'quantity': 26, 'price': 475.8, 'orders': 1}, {'quantity': 13, 'price': 475.85, 'orders': 1}, {'quantity': 13, 'price': 475.9, 'orders': 1}, {'quantity': 613, 'price': 475.95, 'orders': 5}]}}]

[{'tradable': True, 'mode': 'full', 'instrument_token': 2170625, 'last_price': 475.75, 'last_quantity': 50, 'average_price': 477.79, 'volume': 3653349, 'buy_quantity': 206903, 'sell_quantity': 225504, 'ohlc': {'open': 481.55, 'high': 486.0, 'low': 473.45, 'close': 478.75}, 'change': -0.6266318537859008, 'last_trade_time': datetime.datetime(2020, 10, 8, 15, 21, 41), 'oi': 0, 'oi_day_high': 0, 'oi_day_low': 0, 'timestamp': datetime.datetime(2020, 10, 8, 15, 21, 42), 'depth': {'buy': [{'quantity': 13, 'price': 475.5, 'orders': 1}, {'quantity': 3, 'price': 475.45, 'orders': 1}, {'quantity': 14, 'price': 475.4, 'orders': 2}, {'quantity': 78, 'price': 475.35, 'orders': 2}, {'quantity': 1226, 'price': 475.3, 'orders': 3}], 'sell': [{'quantity': 505, 'price': 475.75, 'orders': 4}, {'quantity': 78, 'price': 475.8, 'orders': 2}, {'quantity': 748, 'price': 475.85, 'orders': 5}, {'quantity': 30, 'price': 475.9, 'orders': 1}, {'quantity': 80, 'price': 475.95, 'orders': 2}]}}]

[{'tradable': True, 'mode': 'full', 'instrument_token': 2170625, 'last_price': 474.7, 'last_quantity': 15, 'average_price': 477.75, 'volume': 3694183, 'buy_quantity': 204658, 'sell_quantity': 225992, 'ohlc': {'open': 481.55, 'high': 486.0, 'low': 473.45, 'close': 478.75}, 'change': -0.8459530026109684, 'last_trade_time': datetime.datetime(2020, 10, 8, 15, 22, 23), 'oi': 0, 'oi_day_high': 0, 'oi_day_low': 0, 'timestamp': datetime.datetime(2020, 10, 8, 15, 22, 23), 'depth': {'buy': [{'quantity': 1302, 'price': 474.7, 'orders': 1}, {'quantity': 1, 'price': 474.6, 'orders': 1}, {'quantity': 11, 'price': 474.55, 'orders': 1}, {'quantity': 26, 'price': 474.5, 'orders': 1}, {'quantity': 11, 'price': 474.45, 'orders': 1}], 'sell': [{'quantity': 339, 'price': 474.9, 'orders': 1}, {'quantity': 141, 'price': 474.95, 'orders': 3}, {'quantity': 857, 'price': 475.0, 'orders': 5}, {'quantity': 419, 'price': 475.05, 'orders': 3}, {'quantity': 158, 'price': 475.1, 'orders': 2}]}}]

Why is this happening?
  • raw_orb
    Help, please. Anyone? @sujith ?
  • sujith
    Are you comparing ohlc in the market depth to minute candle ohlc?
  • raw_orb
    Is that even possible? I'm not sure what you mean.
    I'm taking the values given in the 'ohlc' field in the tick and converting it into minute based, which isn't that relevant given I tried plotting the raw, un-edited, second based ticks as well and it's the same result.

    Here's what TVSMOTOR ticks (that I received) from 08/10/2020 look like:-




    and here's SBIN for today (12/10/20/20):-





    These are plotted as candlesticks only, but the wrong ticks are all going in the negative, that's why it's all red.

    Basically, I'm getting all either wrong ticks or they are the same as previous ones, and something is wrong with the volume as well.

    I tried changing the tick mode to QUOTE, which fixed it for a few minutes, it seemed to be getting the correct ticks, but then it went back to the same behaviour as before.

    I am not doing anything with the ticks that might alter them, just printing them once, then picking them up and pushing them into a table.
  • raw_orb
    Everything outside of 'ohlc' is correct (with the exception of volume maybe), the last price, the depth, the quantities for buy and sell, I can verify everything. Just the ohlc seems stuck for some reason.
  • sujith
    Is this how you are building candles?
  • raw_orb
    I was doing:-
    Open - > 'open' of the first tick of that minute.
    Close -> 'close' of the last tick of that minute.
    High -> highest 'high' in all ticks of that minute.
    Low -> lowest 'low' in all ticks of that minute.

    I will try the one you have mentioned there as well, it might actually work.

    But till then, why are even the second based ohlc candles coming wrong? The charts I showed above are from those un-edited second based candles, just as I received them.

    Is that not how it's supposed to work?
  • sujith
    sujith edited October 2020
    Market depth OHLC data denotes day's OHLC and what you are looking for is minute OHLC both are totally different.
  • raw_orb
    raw_orb edited October 2020
    Shit. It would've been easier to tell what it actually is if it were marked 'days_ohlc' instead of just 'ohlc' though, just saying.

    Okay, now that I've (I think) got the right ohlc, what about the 'volume', is that the correct value for every second? Seems a bit too high compared to what Kite shows for an entire minute!
  • sujith
    It is a cumulative value. You can jump to the end of that thread I pointed out earlier, there is a discussion about the volume data.
  • raw_orb
    raw_orb edited October 2020
    Thank You! :)
This discussion has been closed.