I am using this code to try and fetch live data for HDFCBANK JUN FUT
from dhanhq import marketfeed
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
client_id = os.getenv('DHAN_CLIENT_ID')
access_token = os.getenv('DHAN_ACCESS_TOKEN')
# Structure for subscribing is ("exchange_segment","security_id")
# Maximum 100 instruments can be subscribed, then use 'subscribe_symbols' function
instruments = [(2, "44191")]
# Type of data subscription
subscription_code = marketfeed.Depth
# Ticker - Ticker Data
# Quote - Quote Data
# Depth - Market Depth
async def on_connect(instance):
print("Connected to websocket")
async def on_message(instance, message):
print("Received:", message)
instance.subscribe_symbols(19, instruments)
print("Subscription code :", subscription_code)
feed = marketfeed.DhanFeed(client_id,
access_token,
instruments,
subscription_code,
on_connect=on_connect,
on_message=on_message)
feed.run_forever()
and getting this in Console
RuntimeWarning: coroutine 'DhanFeed.connect' was never awaited
self.connect()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Connected to websocket
Connected to websocket
Received: {'type': 'Market Depth', 'exchange_segment': 2, 'security_id': 44191, 'LTP': 1696.5, 'depth': [{'bid_quantity': 1100, 'ask_quantity': 550, 'bid_orders': 1, 'ask_orders': 1, 'bid_price': 1696.5, 'ask_price': 1696.5999755859375}, {'bid_quantity': 550, 'ask_quantity': 6050, 'bid_orders': 1, 'ask_orders': 2, 'bid_price': 1696.4000244140625, 'ask_price': 1696.699951171875}, {'bid_quantity': 550, 'ask_quantity': 1100, 'bid_orders': 1, 'ask_orders': 2, 'bid_price': 1696.3499755859375, 'ask_price': 1696.800048828125}, {'bid_quantity': 2750, 'ask_quantity': 1100, 'bid_orders': 5, 'ask_orders': 2, 'bid_price': 1696.0999755859375, 'ask_price': 1696.9000244140625}, {'bid_quantity': 6050, 'ask_quantity': 2200, 'bid_orders': 6, 'ask_orders': 4, 'bid_price': 1696.0, 'ask_price': 1696.949951171875}]}
Traceback (most recent call last):
File "/Users/.../backend/live_feed.py", line 105, in <module>
feed.run_forever()
File "/Users/.../backend/venv/lib/python3.11/site-packages/dhanhq/marketfeed.py", line 83, in run_forever
self.loop.run_until_complete(self.connect())
File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Users/.../backend/venv/lib/python3.11/site-packages/dhanhq/marketfeed.py", line 99, in connect
await helper.on_message_received(self.data)
File "/Users/.../backend/venv/lib/python3.11/site-packages/dhanhq/marketfeed.py", line 47, in on_message_received
await self.sdk_instance.on_message(self.sdk_instance, response)
File "/Users/.../backend/live_feed.py", line 94, in on_message
instance.subscribe_symbols(19, instruments)
File "/Users/.../backend/venv/lib/python3.11/site-packages/dhanhq/marketfeed.py", line 333, in subscribe_symbols
asyncio.ensure_future(self.ws.send(self.create_subscription_packet(symbols, feed_request_code, subscribe=True)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: DhanFeed.create_subscription_packet() got an unexpected keyword argument 'subscribe'
So receiving depth data for this future as can be seen in the log but immediately it is getting terminated with this error.