Kotak-Neo / kotak-neo-api

100 stars 86 forks source link

Not getting live feed WebSocket LTP data. #76

Closed rosevinod closed 9 months ago

rosevinod commented 9 months ago

I am not getting live feed WebSocket LTP data.

instrument_tokens = [{"instrument_token": "1624", "exchange_segment": "nse_cm"}] client.subscribe(instrument_tokens = instrument_tokens, isIndex=False, isDepth=False)

Only showing the following lines updates ...... updates ...... updates ...... updates ...... updates ......

Please, can someone suggest a solution?

rosevinod commented 9 months ago

The solution has been found.

I was not passing the on_message function, actually I was not storing the session to avoid multiple authentications.

def startKotakEngineCold(on_message,on_error,on_close,on_open):

    json_res = cmn.readJSON(cmn.json_file_access_token)
    df = DataFrame(json_res)
    # print(df.iloc[0].access_token)

    # client = NeoAPI(consumer_key=consumer_key, consumer_secret=consumer_secret,
    #             environment='prod', on_message=on_message, on_error=on_error, on_close=None, on_open=None)

    client = NeoAPI(access_token=df.iloc[0].access_token,
                    consumer_key=cmn.consumer_key,
                    consumer_secret=cmn.consumer_secret,
                    environment='prod',
                    on_message=on_message,
                    on_error=on_error,
                    on_close=on_close,
                    on_open=on_open)

    client.configuration.view_token = df.iloc[0].view_token
    client.configuration.edit_token = df.iloc[0].edit_token
    client.configuration.edit_sid = df.iloc[0].sid
    client.configuration.bearer_token = df.iloc[0].bearer_token
    client.configuration.edit_rid = df.iloc[0].edit_rid
    client.configuration.login_params = {
        'mobileNumber': cmn.mobile_number, 'password': cmn.login_password}
    client.configuration.serverId = df.iloc[0].serverId
    client.configuration.sid = df.iloc[0].sid

    return client