Api subscription docs

Dear Team
Not able to subscribe and get data from websecoket. error RuntimeWarning: coroutine ‘DhanFeed.connect’ was never awaited
self.connect()
Used Code below:

from dhanhq import dhanhq, marketfeed
import pandas as pd
from icecream import ic
import cred
clint_id = cred.user_id
access_token = cred.back_door
dhan = dhanhq(clint_id, access_token)
def get_holdings():
global dhan
holdings = pd.DataFrame(dhan.get_holdings()[‘data’])
return holdings
def holding_valuations():
holdings = get_holdings()
valuations = holdings.dpQty.values * holdings.avgCostPrice.values
valuations = round(sum(valuations), 2)
return valuations

ic(get_holdings())

ic(holding_valuations())
instruments = [(1, “1333”),(0,“13”)]
subscription_code = marketfeed.Ticker
async def on_connect(instance):
print(“Connected to websocket”)
async def on_message(instance, message):
print(“Received:”, message)
print(“Subscription code :”, subscription_code)
feed = marketfeed.DhanFeed(clint_id,
access_token,
instruments,
subscription_code,
on_connect=on_connect,
on_message=on_message)
feed.run_forever()

Ticker - Ticker Data

Quote - Quote Data

Depth - Market Depth

RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Connected to websocket
Connected to websocket
Authorization failed: ‘int’ object has no attribute ‘encode’
Not authorized. Please authorize first.
IDE : VSCODE, language: Python, subscription_status: Active.


above error with code

Hello Shrikant,

Looks like either the Client ID or Access Token is not being passed in correct format. Both needs to be in string for the Websocket.

Do check the same and let me know if you are still getting this error.