How to organize Websockets data into OHLC?

Dear All,

I am a novice user on the Fyers API platform and would like to seek your assistance in organizing market data obtained via WebSocket into the structure of open, high, low, close, and volume.

Enclosed herewith is a sample dataset for your reference:
[{'symbol': 'NSE:BANKNIFTY2381744200CE', 'timestamp': 1692179079, 'fyCode': 7208, 'fyFlag': 2, 'pktLen': 200, 'ltp': 36.0, 'open_price': 60.0, 'high_price': 64.0, 'low_price': 23.5, 'close_price': 144.6, 'min_open_price': 35.7, 'min_high_price': 36.45, 'min_low_price': 35.05, 'min_close_price': 36.0, 'min_volume': 142635, 'last_traded_qty': 120, 'last_traded_time': 1692179079, 'avg_trade_price': 3931, 'vol_traded_today': 71572695, 'tot_buy_qty': 223665, 'tot_sell_qty': 341685, 'market_pic': [{'price': 36.0, 'qty': 660, 'num_orders': 6}, {'price': 35.95, 'qty': 840, 'num_orders': 13}, {'price': 35.9, 'qty': 1335, 'num_orders': 12}, {'price': 35.85, 'qty': 1275, 'num_orders': 12}, {'price': 35.79, 'qty': 795, 'num_orders': 9}, {'price': 36.1, 'qty': 465, 'num_orders': 5}, {'price': 36.15, 'qty': 975, 'num_orders': 11}, {'price': 36.2, 'qty': 1950, 'num_orders': 15}, {'price': 36.25, 'qty': 1440, 'num_orders': 14}, {'price': 36.29, 'qty': 1515, 'num_orders': 10}]}]

By the way, I had tried re-sampling the data(timestamp,ltp,min_volume), however while testing the data with 1min candle's data I found discrepancies for volume aggregation.
Note: If the similar query was addressed in the past, help me with the code. Thanks in advance.
Regards

5 replies