@r95990 'mode': 'quote' says it all. You need to change the mode to full. In quote mode you will not get market depth. in your on_connect method you would first subscribe to the instrument tokens and then set the mode to full as follows def on_connect(ws, response): # Callback on successful connect. # Subscribe to a list of instrument_tokens ws.subscribe([9691394, 9699586, 9760514])
# Set the subscriptions to tick in `full` mode. ws.set_mode(ws.MODE_FULL, [9691394, 9699586, 9760514])
Note that you could set full mode for only select instruments from the subscription list So once you subscribed to instrument tokens 9691394, 9699586, 9760514, if you wanted full mode for only one of them say, 9699586 you could set the mode as full for only that instrument token
ws.subscribe([9691394, 9699586, 9760514]) ws.set_mode(ws.MODE_FULL, [ 9699586]) # In this case ticks for 9699586 will be received in full mode # While ticks for 9691394 and 9760514 will be received in quote mode.
Also the default mode is quote. You need to explicitly change the mode to full for any and all instruments for which you want to receive the market depth.
gets me the depth data, but the same thing behaves differently when
def on_ticks(ws, ticks): feed_data(ticks)
def feed_data(ticks): print(ticks)
here it does not print the depth data, rest of the code remains same!
kws.set_mode(ws.MODE_FULL, subscribed_tokens) is my existing subs request. When I print the ticks directly in on_ticks, I can view the entire depth, but when send it to another function, I'm unable to view the depth data. Is there anything to be processed before I assign the data to feed_data.
Thanks for taking the time MAG! Hope you are my savior!
@r95990 the only way to properly debug this is to print a tick as its received by on_ticks and then print the very same tick passed on to the feed_data method. In order to format the output better, add the following lines to the beginning of your file import pprint #you may need to install the module with pip3 install pprint pp = pprint.PrettyPrinter( indent = 4 )
next just subscribe to one instrument and set mode = full
Then change your code to def on_ticks(ws, ticks): pp.pprint( ticks ) feed_data( ticks )
{'tradable': True, 'mode': 'quote', 'instrument_token': 9691394, 'last_price': 2.6, 'last_traded_quantity': 150, 'average_traded_price': 3.03, 'volume_traded': 11756650, 'total_buy_quantity': 2698100, 'total_sell_quantity': 296500, 'ohlc': {'open': 3.4, 'high': 3.65, 'low': 2.5, 'close': 3.35}, 'change': -22.388059701492537}, {'tradable': True, 'mode': 'quote', 'instrument_token': 9699586, 'last_price': 3.75, 'last_traded_quantity': 50, 'average_traded_price': 4.76, 'volume_traded': 3245200, 'total_buy_quantity': 71850, 'total_sell_quantity': 60900, 'ohlc': {'open': 5.6, 'high': 5.7, 'low': 3.15, 'close': 5.8}, 'change': -35.34482758620689}, {'tradable': True, 'mode': 'quote', 'instrument_token': 9760514, 'last_price': 1.6, 'last_traded_quantity': 50, 'average_traded_price': 1.44, 'volume_traded': 11267300, 'total_buy_quantity': 3615650, 'total_sell_quantity': 287050, 'ohlc': {'open': 2.2, 'high': 2.2, 'low': 1.15, 'close': 2.25}, 'change': -28.888888888888882},
'mode': 'quote' says it all.
You need to change the mode to full. In quote mode you will not get market depth.
in your on_connect method you would first subscribe to the instrument tokens and then set the mode to full as follows
def on_connect(ws, response):
# Callback on successful connect.
# Subscribe to a list of instrument_tokens
ws.subscribe([9691394, 9699586, 9760514])
# Set the subscriptions to tick in `full` mode.
ws.set_mode(ws.MODE_FULL, [9691394, 9699586, 9760514])
Note that you could set full mode for only select instruments from the subscription list
So once you subscribed to instrument tokens 9691394, 9699586, 9760514, if you wanted full mode for only one of them say, 9699586 you could set the mode as full for only that instrument token
ws.subscribe([9691394, 9699586, 9760514])
ws.set_mode(ws.MODE_FULL, [ 9699586])
# In this case ticks for 9699586 will be received in full mode
# While ticks for 9691394 and 9760514 will be received in quote mode.
Also the default mode is quote. You need to explicitly change the mode to full for any and all instruments for which you want to receive the market depth.
def on_ticks(ws, ticks):
print(ticks)
gets me the depth data, but the same thing behaves differently when
def on_ticks(ws, ticks):
feed_data(ticks)
def feed_data(ticks):
print(ticks)
here it does not print the depth data, rest of the code remains same!
kws.set_mode(ws.MODE_FULL, subscribed_tokens) is my existing subs request. When I print the ticks directly in on_ticks, I can view the entire depth, but when send it to another function, I'm unable to view the depth data.
Is there anything to be processed before I assign the data to feed_data.
Thanks for taking the time MAG!
Hope you are my savior!
In order to format the output better, add the following lines to the beginning of your file
import pprint #you may need to install the module with pip3 install pprint
pp = pprint.PrettyPrinter( indent = 4 )
next just subscribe to one instrument and set mode = full
Then change your code to
def on_ticks(ws, ticks):
pp.pprint( ticks )
feed_data( ticks )
def feed_data( ticks1 ):
print( "%%% Printing from feed_data %%%" )
pp.pprint( ticks1 )
Do this, run the code and copy paste the output
Note I have changed the variable name in feed_data just to rule out any variable scope issues.