Hi,
I am using Upstox Plus and i am trying to stream the Full D30 data for 100 instruments. As we can stream only 50 instruments at a time, the idea was to keep switching between the two .
Python Code
import upstox_client
import time
from util.accessToken import read_access_token
strikes_instrument_key = [‘NSE_FO|64856’, ‘NSE_FO|64858’, ‘NSE_FO|64860’, ‘NSE_FO|64862’, ‘NSE_FO|64864’, ‘NSE_FO|64866’, ‘NSE_FO|64868’, ‘NSE_FO|64870’, ‘NSE_FO|64872’,
‘NSE_FO|64874’, ‘NSE_FO|64876’, ‘NSE_FO|64878’, ‘NSE_FO|64880’, ‘NSE_FO|64882’, ‘NSE_FO|64907’, ‘NSE_FO|64926’, ‘NSE_FO|64931’, ‘NSE_FO|64935’,
‘NSE_FO|64937’, ‘NSE_FO|64956’, ‘NSE_FO|64958’, ‘NSE_FO|64961’, ‘NSE_FO|64967’, ‘NSE_FO|64997’, ‘NSE_FO|65056’, ‘NSE_FO|65069’, ‘NSE_FO|65071’,
‘NSE_FO|65073’, ‘NSE_FO|65075’, ‘NSE_FO|65077’, ‘NSE_FO|65079’, ‘NSE_FO|65081’, ‘NSE_FO|65083’, ‘NSE_FO|65085’, ‘NSE_FO|65089’, ‘NSE_FO|65091’,
‘NSE_FO|65093’, ‘NSE_FO|65095’, ‘NSE_FO|65097’, ‘NSE_FO|65101’, ‘NSE_FO|65103’, ‘NSE_FO|65105’, ‘NSE_FO|65107’, ‘NSE_FO|65109’, ‘NSE_FO|65111’,
‘NSE_FO|65113’, ‘NSE_FO|65115’, ‘NSE_FO|65117’,‘NSE_FO|65119’, ‘NSE_FO|65121’, ‘NSE_FO|64359’, ‘NSE_FO|64361’, ‘NSE_FO|64363’, ‘NSE_FO|64365’,
‘NSE_FO|64367’, ‘NSE_FO|64369’, ‘NSE_FO|64371’, ‘NSE_FO|64375’, ‘NSE_FO|64377’, ‘NSE_FO|64385’, ‘NSE_FO|64389’, ‘NSE_FO|64408’, ‘NSE_FO|64412’,
‘NSE_FO|64612’, ‘NSE_FO|64620’, ‘NSE_FO|64663’, ‘NSE_FO|64719’, ‘NSE_FO|64760’, ‘NSE_FO|64785’, ‘NSE_FO|64791’, ‘NSE_FO|64793’, ‘NSE_FO|64795’,
‘NSE_FO|64797’, ‘NSE_FO|64799’, ‘NSE_FO|64801’, ‘NSE_FO|64803’, ‘NSE_FO|64805’, ‘NSE_FO|64807’, ‘NSE_FO|64809’, ‘NSE_FO|64811’, ‘NSE_FO|64813’,
‘NSE_FO|64815’, ‘NSE_FO|64817’, ‘NSE_FO|64819’, ‘NSE_FO|64822’, ‘NSE_FO|64824’, ‘NSE_FO|64826’, ‘NSE_FO|64828’, ‘NSE_FO|64830’, ‘NSE_FO|64832’,
‘NSE_FO|64834’, ‘NSE_FO|64836’, ‘NSE_FO|64838’, ‘NSE_FO|64840’, ‘NSE_FO|64842’, ‘NSE_FO|64844’, ‘NSE_FO|64849’, ‘NSE_FO|64851’, ‘NSE_FO|64853’,
‘NSE_FO|64855’]
def main():
configuration = upstox_client.Configuration()
access_token = read_access_token()
configuration.access_token = access_token
streamer = upstox_client.MarketDataStreamerV3(
upstox_client.ApiClient(configuration),[], “full_d30”)
def on_open():
print(“Connected. Subscribing to instrument keys.”)
# list = [‘NSE_FO|48197’,‘NSE_FO|64839’]
# CEStrikes = instruments[“CE”]
streamer.subscribe(
strikes_instrument_key[0:50], “full_d30”)
# Handle incoming market data messages\
def on_message(message):
print(“Message Length:”, len(message))
print(message)
streamer.on(“open”, on_open)
streamer.on(“message”, on_message)
streamer.connect()
time.sleep(5)
streamer.unsubscribe(strikes_instrument_key[0:50])
time.sleep(5)
print(“Rotating subscription to next set of instrument keys.”)
streamer.subscribe(strikes_instrument_key[50:100], “full_d30”)
if _name_ == “_main_”:
main()
The problem is that the live data comes only for the first 50 instruments. Tick data for the next 50 instruments never come after unsubscribing the first 50 and then subscribing onto next 50.
Also, i am getting only depth upto 5 levels and not the entire depth of 30. Could you please tell where i am going wrong.
Returned Data for 1 instrument
{‘feeds’: {‘NSE_FO|64801’: {‘fullFeed’: {‘marketFF’: {‘ltpc’: {‘ltp’: 6.55, ‘ltt’: ‘1771581599762’, ‘ltq’: ‘325’, ‘cp’: 8.05 }, 'marketLevel': {'bidAskQuote': \[
{'bidQ': '195', 'bidP': 6.35, 'askQ': '2080', 'askP': 6.55
},
{'bidQ': '195', 'bidP': 6.3, 'askQ': '1300', 'askP': 6.6
},
{'bidQ': '65', 'bidP': 6.25, 'askQ': '65', 'askP': 6.65
},
{'bidQ': '1690', 'bidP': 6.2, 'askQ': '65', 'askP': 6.7
},
{'bidQ': '65', 'bidP': 6.1, 'askQ': '390', 'askP': 6.8
}
\]
}, 'optionGreeks': {'delta': -0.0253, 'theta': -5.024, 'gamma': 0.0001, 'vega': 1.583, 'rho': -0.0718
}, 'marketOHLC': {'ohlc': \[
{'interval': '1d', 'open': 6.0, 'high': 10.9, 'low': 5.6, 'close': 6.55, 'vol': '24699415', 'ts': '1771525800000'
},
{'interval': 'I1', 'open': 6.7, 'high': 6.95, 'low': 6.1, 'close': 6.55, 'vol': '386100', 'ts': '1771581540000'
}
\]
}, 'atp': 8.93, 'vtt': '24699415', 'oi': 2537535.0, 'iv': 0.25390625, 'tbq': 111995.0, 'tsq': 38805.0
}
}, 'requestMode': 'full_d30'
},