Need help to calculate volume from tick data

marthanda
I am having trouble calculating volume using tick data that is not near. Can someone help me calculate the volume from tick data [ WebSocket ] using Python?

so far I tried few options like, but didn't helped
- tick [sorted by exchange_timestamp]
- volume traded [0] - volume traded [-1] vice-versa
- volume traded [0 from last min] - (volume traded [-1] / volume traded [0]) vice-versa
- sum(total_buy_quantity) - sum(total_sell_quantity) vice-versa
.....

but not even close to actual no
  • ANL
    You don't have to include total_buy_quantity and total_sell_quantity to calculate volume traded.
    You can calculate any difference of two objects by doing T2 - T1 i.e,

    volume_traded[-1] - Volume_traded[0]
    Volume_traded will be computed if your indexing is accurate.
  • marthanda
    somehow its not working, tried early

    min, volume_traded[-1] - Volume_traded[0]

    30th min, 11387502 - 11355840 = 31,662
    29th min, 11353352 - 11328103 = 25,249
    28th min, 11328103 - 11293612 = 34,491

    but actually looking for:
    29th min, 29,146
    28th min, 45,631
    27th min, 46,432
    26th min, 36,297
  • marthanda
    marthanda edited January 20
    Query which I am using,

    select volume_traded, total_buy_quantity, total_sell_quantity from 2025_tradeplus.012025tick
    where instrument_token = 738561 and exchange_timestamp between '2025-01-20 14:29:00' and '2025-01-20 14:29:59' order by exchange_timestamp
  • anodo123
    Just a guess, in the exchange_timestamp, there might be milliseconds data also '2025-01-20 14:29:59' this query doesn't consider miliseconds, you might be missing some volumes, receives in these milliseconds, please check.
  • ANL
    somehow its not working, tried early

    min, volume_traded[-1] - Volume_traded[0]

    30th min, 11387502 - 11355840 = 31,662
    29th min, 11353352 - 11328103 = 25,249
    28th min, 11328103 - 11293612 = 34,491

    but actually looking for:
    29th min, 29,146
    28th min, 45,631
    27th min, 46,432
    26th min, 36,297
    Didn't get you? As i said,
    You can calculate any difference of two objects by doing T2 - T1 i.e,
    eg: volume_traded:
    100 T1
    110
    120
    130 T2

    vol = T2 -T1# 130 -100 = 30

    Another way is also same:

    100 T1
    110 T2
    120 T3
    130 T4

    T2-T1 = 10, T3-T1 = 10, T4-T3 = 10
    vol = 30

    Are you having trouble understanding why you are using TBQ and TSQ to determine volume?
    If you have the right indexing, this can be completed quite quickly.
  • marthanda
    please check example which I share with image, I am referring volume_traded as you said but its not getting same
  • sujith
    Total buy quantity and total sell quantity means the sum of all pending order quantities at the exchange. It is not related to volume traded for the day.
Sign In or Register to comment.