Example code to subscribe/unsubscribe to new/current instruments while market feed is running

Example code to subscribe/unsubscribe to new/current instruments while market feed is running

Hello @abd1987

You can use subscribe_instruments packet to subscribe to new instruments while feed is running. I do not have a code sample of the same here, maybe someone from community can look into this?

Hello, I also have same question. I tried to use subscribe_instruments function like below -

feed = marketfeed.DhanFeed(client_id=client_id,
    access_token=access_token,
    instruments=instruments,
    subscription_code=subscription_code,
    on_connect=on_connect,
    on_message=on_message)

instruments = [(1, "1333"), (1, "3499"), (1, "13")] # This is a long list containing 101 tuples

feed.subscribe_instruments(instruments)
feed.run_forever()

This threw me an error

Traceback (most recent call last):
  File "MY_PYTHON_FILE_LOCATION", line 53, in <module>
    feed.subscribe_instruments(instruments)
TypeError: DhanFeed.subscribe_instruments() takes 1 positional argument but 2 were given

Hello @lalitnmudgal

My bad here, you can use subscribe_symbols function instead for this use case.