osparamatrix / ks-orderapi-python

47 stars 59 forks source link

whats the command to check the available fund? #57

Open keerthankumar opened 3 years ago

keerthankumar commented 3 years ago

whats the command to check the available fund ? I dont see any command.

Please point me to the correct document

nishu88 commented 3 years ago
from hyper.contrib import HTTP20Adapter
def get_funds():

    header_params = {}
    header_params['consumerKey'] = consumer_key
    header_params['sessionToken'] = client.session_token
    body_params = None
    header_params['Authorization'] = "Bearer "+ access_token

    s = requests.session()
    s.mount('https://', HTTP20Adapter())
    res = s.get("https://tradeapi.kotaksecurities.com/apim/margin/1.0/margin",data=body_params, headers=header_params)

    res = res.json()

    if "Success" in res:
        if "equity" in res["Success"]:
            eq = res["Success"]["equity"]
            if (len(eq) >0):
                if 'cash' in eq[0]:
                    if "marginAvailable" in eq[0]['cash']:
                        return round(float(res["Success"]["equity"][0]["cash"]["availableCashBalance"]),2)
keerthankumar commented 2 years ago

Hi I tried with this, i get error - {"fault":{"code":99999,"description":"Session token is either expired or not correct","message":"You have been logged out of your account due to inactivity or have logged into another device. Kindly re-login."}}

tried multiple times after generating multiple session token, not sure whats the issue ?

nishu88 commented 2 years ago

@keerthankumar switch to ks-api.... This is outdated.. You can use check_margin endpoint https://github.com/paramatrixtech/ksapi/tree/main/python

keerthankumar commented 2 years ago

@nishu88 Thanks, this is helpful