Candle volume from market data

rishi
I am using websocket through python client. I want to create 1 minute candles. My doubt is how to compute volume traded in 1 minute.

One way is to sum 'last_quantity' received in the ticks. But on doing so, volume I am getting is much less than compared to zerodha charts.

Is last_quantity the right field to use? Or is there any other way?
  • sujith
    Hi @rishi,
    You need to use Volume traded for the day field. It contains cumulative volume.
    In order to get volume data, you need to find the difference between the volume of last tick and first tick of that interval.
  • rishi
    DEBUG:root:Ticks: [{'timestamp': datetime.datetime(2018, 1, 29, 12, 12, 24), 'last_price': 273.8, 'oi_day_low': 0, 'volume': 9508655, 'sell_quantity': 1281348, 'last_quantity': 324, 'change': -2.2840827980014193, 'oi': 0, 'average_price': 274.18, 'ohlc': {'high': 282.8, 'close': 280.2, 'open': 282.0, 'low': 268.6}, 'tradable': True, 'depth': {'sell': [{'price': 273.75, 'orders': 65536, 'quantity': 187}, {'price': 273.8, 'orders': 131072, 'quantity': 330}, {'price': 273.85, 'orders': 262144, 'quantity': 3161}, {'price': 273.9, 'orders': 1245184, 'quantity': 8253}, {'price': 273.95, 'orders': 589824, 'quantity': 4267}], 'buy': [{'price': 273.65, 'orders': 65536, 'quantity': 106}, {'price': 273.6, 'orders': 262144, 'quantity': 596}, {'price': 273.55, 'orders': 65536, 'quantity': 100}, {'price': 273.5, 'orders': 196608, 'quantity': 95}, {'price': 273.45, 'orders': 327680, 'quantity': 3100}]}, 'mode': 'full', 'last_trade_time': datetime.datetime(2018, 1, 29, 12, 12, 23), 'buy_quantity': 868677, 'oi_day_high': 0, 'instrument_token': 1723649}]



    In this you mean the 'volume' field?
  • sujith
    Yes, you need to use volume.
This discussion has been closed.