paramatrixtech / ksapi

Kotak Securities Trading APIs Integration
Apache License 2.0
51 stars 50 forks source link

Web socket not working #18

Open cvsk123 opened 2 years ago

cvsk123 commented 2 years ago

Hi, I am trying to use client.subscribe method, but its giving an error that this method is not available. please guide. Thank you

jayakarthik-devices commented 2 years ago

@cvsk123 I too got the same error when initially tried. The reason is previously i had installed the api from osparamatrix github. Then i uninstalled the api and again installed the api from this github paramatrixtech and it worked fine.

See if it works after uninstalling the api and installing it again from paramatrixtech github link.

cvsk123 commented 2 years ago

@jayakarthik-devices I tried to install it from this package, but now getting some warnings and this error. Token not found. image

cvsk123 commented 2 years ago

@jayakarthik-devices could you share a sample code you are using? I am getting errors and am unable to use it.

jayakarthik-devices commented 2 years ago

@cvsk123 I use the below code and it works.

import ks_api_client from ks_api_client import ks_api

def kotak_session_login(): kotak_ip = '127.0.0.1' kotak_appId = 'DefaultApplication' user_id = '' user_pwd = '' consumer_key = '' consumer_secret = '' access_token = '' access_code = '' host = "https://tradeapi.kotaksecurities.com/apim"

try:
    client = ks_api.KSTradeApi(access_token = access_token, userid = user_id, \
                           consumer_key = consumer_key, ip = kotak_ip, app_id = kotak_appId, \
                           host = host, consumer_secret = consumer_secret)

except Exception as e:
    print("Exception when calling SessionApi->KSTradeApi: %s\n" % e)

try:
    # Login using password
    client.login(password = user_pwd)
except Exception as e:
    print("Exception when calling SessionApi->login: %s\n" % e)

try:
    # Generate final Session Token
    client.session_2fa(access_code = access_code)
except Exception as e:
    print("Exception when calling SessionApi->session_2fa: %s\n" % e)

ktk_client = client

return(ktk_client)

def data_streaming(message): print(message)

if name=="main":

ktk_client = kotak_session_login()

token_string = '11721'
status = ktk_client.subscribe(input_tokens=token_string,callback=data_streaming)
jayakarthik-devices commented 2 years ago

@cvsk123 some distortion in copy paste of code in above comment. So pasted the code in a text file. Replace ***** with actual values.

test1.txt .

dhwajsinghal commented 2 years ago

are you getting the token issue with this token alone, or with any token you try to use?

cvsk123 commented 2 years ago

@cvsk123 some distortion in copy paste of code in above comment. So pasted the code in a text file. Replace ***** with actual values.

test1.txt .

Still Same Issue with this code also image

cvsk123 commented 2 years ago

are you getting the token issue with this token alone, or with any token you try to use?

For every token i am getting this error

cvsk123 commented 2 years ago

@paramatrixtech could you please guide me on this issue.

KESHAV48 commented 2 years ago

@cvsk123 some distortion in copy paste of code in above comment. So pasted the code in a text file. Replace ***** with actual values. test1.txt .

Still Same Issue with this code also image even i'm facing the same issue for below piece of code image