โœ–

Home Forums General Questions How to get tick-by-tick volume from Zerodha’s WebSocket ?

How to get tick-by-tick volume from Zerodha’s WebSocket ?

  • Author
    Posts
    • ๐Ÿ“ Question Details
      Iโ€™m using broker APIs like Zerodha and Angel One, and I noticed that they give cumulative volume instead of per-tick or per-candle volume.
      Because of this, Iโ€™m not able to calculate correct volume for my candles.
      How do we convert this cumulative volume into actual traded tick volume ?
    • You are right some brokers doesn’t give the direct per-tick volume we have to calculate that by comparing the tick cumulative volume with previous candle stored volume.

      So, like that we will have to convert volume manually.

      Below logic and code, you can refer.

      Delta Volume = Current Volume – Previous Volume
      Below code that you can refer:

      def calculate_delta_volume(ticks):
          prev_volume = None
          result = []
          for tick in ticks:
              current_volume = tick["volume"]
              if prev_volume is None:
                  delta = 0  # first tick
              else:
                  delta = current_volume - prev_volume
      
                  # safety check (in case of reset or bad data)
                  if delta < 0:
                      delta = 0
              tick["delta_volume"] = delta
              result.append(tick)
              prev_volume = current_volume
          return result
      
      # usage
      ticks = [
          {"price": 100, "volume": 1000},
          {"price": 101, "volume": 1200},
          {"price": 102, "volume": 1500},
      ]
      
      output = calculate_delta_volume(ticks)
      
      for t in output:
          print(t)

      Later can use in the building candles from live data.

Viewing 1 reply thread
×

Start a Discussion

Get help from the AlgoDelta community.

×

Welcome Back!

Enter your email to sign in or create an account. No passwords needed.

โณ

Pending Approval

โš ๏ธ

Delete This?

Are you sure you want to delete this? This action is permanent and cannot be undone.

Scroll to Top