Coder Social home page Coder Social logo

ksapi's People

Contributors

dhwajsinghal avatar paramatrixtech avatar sanket-parte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ksapi's Issues

HistoryAPI not working

client.history("historicalprices",{"exchange":"bse","cocode":"476","fromdate":"01-jan-2014","todate":"08-oct-2015"})
Returns:
ApiException: (404)
Reason: Not Found
HTTP response body: <am:fault xmlns:am="http://wso2.org/apimanager">am:code404</am:code>am:typeStatus report</am:type>am:messageNot Found</am:message>am:descriptionThe requested resource is not available.</am:description></am:fault>

client.history("NSEFNO_HistoricalContinuousChart",{"symbol":"HDFC","expiry type": "near"})
Returns:
ApiException: (404)
Reason: Not Found
HTTP response body: <am:fault xmlns:am="http://wso2.org/apimanager">am:code404</am:code>am:typeStatus report</am:type>am:messageNot Found</am:message>am:descriptionThe requested resource is not available.</am:description></am:fault>

AttributeError: partially initialized module 'ks_api_client.ks_api' has no attribute 'KSTradeApi' (most likely due to a circular import)

After I've installed the newer python package of kotak api listed here https://github.com/paramatrixtech/ksapi/tree/main/python I'm getting the error mentioned in the subject. If I reinstall the Kotak python package listed at https://github.com/osparamatrix/ks-orderapi-python it works fine. I don't know why I'm not able to use the newer version.
My file name is not similar to the package name so I'm not able to understand why it is giving such an error

Invalid One time Token ERROR

ks_api_client.exceptions.ApiException: (401)
Reason: Unauthorized
HTTP response body: {"fault":{"code":50001,"description":"Onetimetoken is either expired or not correct","message":"Invalid OneTimeToken"}}

this is what i'm getting
Please Help.

Websocket sample code

Please provide a sample code in Python for websocket connection, subscribing symbols and getting the ticks.

Unable to place order

Code is copied from help:

order_id = client.place_order(order_type="N", instrument_token=token_value, transaction_type="BUY",
quantity=1, price=order_price, disclosed_quantity=0, trigger_price=0,
validity="GFD", variety="REGULAR", tag="API trades buy")

Value of params:
instrument_token = 17854
order_price = 11.35

Error

order_id = client.place_order(order_type="N", instrument_token=token_value, transaction_type="BUY", \

File "site-packages\ks_api_client-1.1.0-py3.9.egg\ks_api_client\ks_api.py", line 147, in place_order
File "site-packages\ks_api_client-1.1.0-py3.9.egg\ks_api_client\api\normal_order_api.py", line 362, in place_new_normal_order
File "site-packages\ks_api_client-1.1.0-py3.9.egg\ks_api_client\api\normal_order_api.py", line 469, in place_new_normal_order_with_http_info
File "site-packages\ks_api_client-1.1.0-py3.9.egg\ks_api_client\api_client.py", line 354, in call_api
File "site-packages\ks_api_client-1.1.0-py3.9.egg\ks_api_client\api_client.py", line 155, in __call_api
File "site-packages\ks_api_client-1.1.0-py3.9.egg\ks_api_client\api_client.py", line 242, in sanitize_for_serialization
File "site-packages\ks_api_client-1.1.0-py3.9.egg\ks_api_client\api_client.py", line 242, in
File "site-packages\ks_api_client-1.1.0-py3.9.egg\ks_api_client\api_client.py", line 239, in sanitize_for_serialization
AttributeError: 'numpy.int64' object has no attribute 'openapi_types'

Portfolio contents

I have not found portfolio-related api in this python SDK, is there any plan to have it near future?

Error while closing orders

Error FIL 2

Hi

I use Kotak Api to trade in bank nifty options.

i have encountered one error while closing the open order. The system i have coded is if an order is placed at a particular time (let's say 09:16) must be traded off at a particular time(let's say 09:45).

I had inserted one condition which checks at 09:45 if the order is traded or not and if not then it modifies the order to trade at 09:45.

In between, if i believe the market will not be in my favor, I modify the order myself manually before the coded time (09:45 in this example).

Doing this terminates my program at 09:45 giving the error message as "ks_api_client.exceptions.Api exception: (999113) Order modification not allowed as current order status is FIL, "){screenshot attached} and thereafter terminating the program for future trades.

please help on why this error occur and how to rectify it

Thanks

Websocket not passing information for all subscribed tokens

@dhwajsinghal, @sanket-parte , @paramatrixtech
I am passing list of 11 tokens to the websocket subscribe method. Out of the tokens, one is token number for Nifty50 Spot and rest 10 token numbers are for options (5 token for PE and 5 token for CE).
The output I am receiving through websocket is not passing Nifty50 Spot details. Also out of 10 option tokens websocket is returning only for 6 or 7 token randomly. What could be the issue ?

Note: If I subscribe only for Nifty 50 Spot, then i get result through websocket. Also if I subscribe for the missing option tokens separately I am getting output through websocket. So the missing results are random if clubbed together. How to address this issue.

Can you please suggest some solution.

Two different params taking same value in ks_api.KSTradeApi()

In the call to ks_api.KSTradeApi () there are parameters app_id and consumer_secret which take same values please avoid adding parameters which take same value. Or initialize them internally based on what was passed.
Actually It make sense to retain consumer_secret instead of app_id since that is what it is called on the api portal.

Unsubscribe one or multiple tokens without stopping streaming service

Hi,

I want to unsubscribe specific token(s) which I subscribed already in streaming/websocket service.
Ex:- I subscribed for HDFC Bank, ICICI Bank, Kotak Bank and later some point I want to unsubscribe only ICICI Bank ( I don't need price streaming), how can I do that?
Please explain with some examples.

Thank you!

clarification on place order

Hi Please clarity few questions related to place order -

client.place_order(order_type = "N", instrument_token = 727, transaction_type = "BUY", quantity = 1, price = 0, \
               disclosed_quantity = 0, trigger_price = 0, tag = "string", validity = "GFD", variety = "REGULAR" \ 
               product = "NORMAL" ,smart_order_routing="string")
  1. In order_type, what is the difference between O(Order), N(NormalOrder) ?
  2. what is product ?
    product | str | Product type for this order - NORMAL, SUPERMULTIPLE, SUPERMULTIPLEOPTION, MTF
  3. for CASH or OPTIONS apart from the instrument_token is there any difference in terms of parameters?

History API

Hey Guys
Do you have an ETA when the history API might begin working?

Invalid Credentials

I am getting following error while trying to login through API.

{"fault":{"code":900901,"message":"Invalid Credentials","description":"Access failure for API: /apim/session/1.0, version: 1.0 status: (900901) - Invalid Credentials. Make sure you have provided the correct security credentials"}}

Cant connect to Websocket

2 days back I was able to get the ticks, but after updating the api, I am now getting below error.
Other error occurred: Expecting value: line 1 column 1 (char 0).

Pls suggest a solution to this.

code request

Please provide code to get live price feeds in excel

Websocket coninuously disconnecting

Hi,
I succeeded to connect to the live streaming. But it is disconnecting frequently. Please see below the messages I received from streaming:

['0154101', '35397', '188.2000', '100', '188.5000', '50', '188.1500', '255.0000', '167.7000', '190.5200', '409.6500', '210.0000', '-54.0705', '425150', '471950', '22552000', '2369550', '4296607040.00', '50', '14/02/2022 10:24:01', '-221.5000', '1070.5500', '0.0500']
Your logic/computation will come here.
Connection closed
..........
...........
INFO:socketio.client:Engine.IO connection established.

Also, one major problem in the received messages is there is a list of values only. How do I know which value refers to what.
I mean how one would know out of the values which is ltp, which is volume and so on.

Could you please provide the response format?

not able to login

I am getting the same error again and again . I have checked all credentials , but still it is not working i dont know why but before the same code used to work.

the following error is

ApiException: (401)
Reason: Unauthorized
HTTP response body: {"fault":{"code":900901,"message":"Invalid Credentials","description":"Access failure for API: /apim/session/1.0, version: 1.0 status: (900901) - Invalid Credentials. Make sure you have provided the correct security credentials"}}

Validate login credentials by Kotak Sec

Is there any way to route to Kotak securities login page from out Algo and where Kotak can validate and send back the response with session id or something else?
This is to avoid hardcoding login credentials in Algo or creating our own login page.

Please let me know if there is way to avoid hardcoding the credentials.

Getting Error while importing the Package.

(trade_bot) C:\Users\Jalal>python
Python 3.10.6 | packaged by conda-forge | (main, Oct 7 2022, 20:14:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import ks_api_client
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Jalal\anaconda3\envs\trade_bot\lib\site-packages\ks_api_client_init_.py", line 10, in
from ks_api_client.api.historical_api import HistoricalApi
File "C:\Users\Jalal\anaconda3\envs\trade_bot\lib\site-packages\ks_api_client\api_init_.py", line 6, in
from ks_api_client.api.historical_api import HistoricalApi
File "C:\Users\Jalal\anaconda3\envs\trade_bot\lib\site-packages\ks_api_client\api\historical_api.py", line 11, in
from ks_api_client.api_client import ApiClient
File "C:\Users\Jalal\anaconda3\envs\trade_bot\lib\site-packages\ks_api_client\api_client.py", line 19, in
from ks_api_client.configuration import Configuration
File "C:\Users\Jalal\anaconda3\envs\trade_bot\lib\site-packages\ks_api_client\configuration.py", line 16, in
from dotenv import load_dotenv
ModuleNotFoundError: No module named 'dotenv'

Web socket not working

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

Query regarding market depth

Hi developer team,

I am using Quotes API, trying to get "market depth" of token. Below is code Run.

Input :

from ks_api_client import ks_api
client = ks_api.KSTradeApi(access_token = "", userid = "********", consumer_key = "",ip = "127.0.0.1", app_id = "",
host = "https://tradeapi.kotaksecurities.com/apim", consumer_secret = "
")
client.login(password = "
")
client.session_2fa(access_code = "
*****")

# Get quote details by quote_type
d = client.quote(instrument_token = 25868, quote_type = "DEPTH")
print(d['success'])

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

Output:
{
"success": {
"depth": [
{
"buy": [
{
"price": "0",
"quantity": "0",
"orders": "0"
},
{
"price": "0",
"quantity": "0",
"orders": "0"
},
{
"price": "0",
"quantity": "0",
"orders": "0"
},
{
"price": "0",
"quantity": "0",
"orders": "0"
},
{
"price": "0",
"quantity": "0",
"orders": "0"
}
],
"sell": [
{
"price": "0",
"quantity": "0",
"orders": "0"
},
{
"price": "0",
"quantity": "0",
"orders": "0"
},
{
"price": "0",
"quantity": "0",
"orders": "0"
},
{
"price": "0",
"quantity": "0",
"orders": "0"
},
{
"price": "0",
"quantity": "0",
"orders": "0"
}
]
}
]
}
}

As per "/depth/instruments/{instrumentTokens} Get market details quote" on (https://tradeapi.kotaksecurities.com/devportal/apis) api portal . I want the output in below mentioned format. Let me know the tweak in code to get desired output.

{
"instrumentName": "string",
"instrumentToken": 0,
"lastUpdatedTime": 0,
"lastTradedTime": 0,
"lastPrice": 0,
"lastTradedQuantity": 0,
"totalBuyQuantity": 0,
"totalSellQuantity": 0,
"averageTradedPrice": 0,
"openInterest": 0,
"netChange": 0,
"dprLow": 0,
"dprHigh": 0,
"ohlc": {
"open": 0,
"high": 0,
"low": 0,
"close": 0
},
"depth": {
"buy": {
"price": 0,
"quantity": 0,
"orders": 0
},
"sell": {
"price": 0,
"quantity": 0,
"orders": 0
}

Thanks in advance

Get PNL function

please add pnl function or show unreliazed profits in postions data (only realized profts are shown currently)

Invalid Credentials

Hi,

I followed the instructions to initiate a session as below .

from ks_api_client import ks_api
client = ks_api.KSTradeApi(access_token = "", userid = "", consumer_key = "",ip = "127.0.0.1", app_id = "",
host = "https://tradeapi.kotaksecurities.com/apim", consumer_secret = "")

I have provided my credentials as seen in my "defaultapplication" in the code above but i am facing the following error. I have also tried to regenerate my access token but still no use.

ApiException: (401)
Reason: Unauthorized
HTTP response body: {"fault":{"code":900901,"message":"Invalid Credentials","description":"Access failure for API: /apim/session/1.0, version: 1.0 status: (900901) - Invalid Credentials. Make sure you have provided the correct security credentials"}}

But when i try to test in the session API portal i receive the following response. This response seems like the session initiation was a success. What is it that i am missing. Kindly help.

{'Success': {'clientType': 'ONLINE',
'encryption': {'keySize': 0, 'publickKey': '', 'type': 'PLAIN'},
'isNRI': 'N',
'message': '',
'redirect': {'host': 'https://ctradeapi.kotaksecurities.com/apim',
'port': 443},
'service': {'host': 'https://tradeapi.kotaksecurities.com/apim',
'port': 443},
'status': 'Success',
'userType': 'G',
'userid': 'XXXXXXXX'}}

i am not able to login:

i am not able to login:

from ks_api_client import ks_api

Defining the host is optional and defaults to https://sbx.kotaksecurities.com/apim

See configuration.py for a list of all supported configuration parameters.

client = ks_api.KSTradeApi(access_token = "", userid = "", consumer_key = "",ip = "127.0.0.1", app_id = "test",
host = "https://tradeapi.kotaksecurities.com/apim", consumer_secret = "")

Initiate login and generate OTT

client.login(password = "")

#Complete login and generate session token
client.session_2fa()

it is giving me the following error

TypeError: init() got an unexpected keyword argument 'consumer_secret'

Login without Access code and BO

Can someone help for login using SDK without Access code?

When do we plan to bring Bracket order? Do we have any alternate for now?

Bug in Script Master api

When we get the data for url by sending get request to url = "https://tradeapi.kotaksecurities.com/apim/scripmaster/1.1/filename".
We receive cash and fno url for downloading instruments like "cash": "https://preferred.kotaksecurities.com/security/production/TradeApiInstruments_Cash_26_02_2023.txt",.

It works fine on normal days, however when we do this on holiday like 26-02-2023, the cash and fno gives 404 error code. Please make necessary changes to fix this bug so the url is always of working day or make holiday dates also available on servers.

what is ApiValueError ?

ApiValueError --> this is not raising any exceptions in the code. Does it simply exist without any warning/error message?
Is there anything I need to set at my end?

#question

How many token i can connect at a time via websocket. ?

How many websocket i can connect on 1 API ?

order_report API is throwing error

When I try to see my orders and used order_report API and getting error "OTIM MODULE NOT AVAILABLE".
Error message:
Exception has occurred: ApiException
(424)
Reason: Failed Dependency
HTTP response body: {"fault":{"code":999321,"description":"-","message":"OTIM MODULE NOT AVAILABLE"}}

My second question is, does this response contains order id?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.