paramatrixtech / ksapi Goto Github PK
View Code? Open in Web Editor NEWKotak Securities Trading APIs Integration
License: Apache License 2.0
Kotak Securities Trading APIs Integration
License: Apache License 2.0
Hi All,
Can someone Pls help how to get instrument token of FNO symbols like NIFTY CE/PE,
I could find for cash segment - https://preferred.kotaksecurities.com/security/production/TradeApiInstruments_Cash_14_07_2021.txt, but not for FNO.
I feel there is no enough documentation.
thanks,
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>
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
Hi Kotak Dev Team,
I Have a Question: Will the stop-loss and Tslo orders be available in API at some point in API?
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.
Please provide a sample code in Python for websocket connection, subscribing symbols and getting the ticks.
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'
I have not found portfolio-related api in this python SDK, is there any plan to have it near future?
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
@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.
is there any way to place a bracket order through the API ?
i followed the example, but I am getting AttributeError: 'KSTradeApi' object has no attribute 'subscribe'
pls help!
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.
Is there any plan to host ksapi on pypi?
Any Idea
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!
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")
Hey Guys
Do you have an ETA when the history API might begin working?
hello @paramatrixtech ,
Order placement with stocks is just fine. But it's not working with derivatives (i.e NIFTY, BANKNIFTY).
Output error code is 1000 attached screenshot.
please resolve
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"}}
As suggested here https://github.com/paramatrixtech/ksapi/blob/main/python/docs/Bracketplace.md ; I'm passing Spread and bookProfit parameters while placing a bracket order, but I'm getting the following error:
TypeError: place_order() got an unexpected keyword argument 'Spread'
Are bracket orders supported? If not, what are the plans cause its a dealbreaker for me?
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.
Please provide code to get live price feeds in excel
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?
No information on TSLO-BO Order using APIs.
I'm looking for Websocket details. how to subscribe & how to connect.
Please provide the examples of websocket if possible
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"}}
When subscribing to https://wstreamer.kotaksecurities.com/feed/orders via a websocket, we are getting error "Token Not Found". How do we get the order status updates via websocket connection?
Please let me know how many max token that can be subscribed to a websocket connect?
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.
(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'
What Do You say about this? I have no idea what's wrong
Hi, I am trying to use client.subscribe method, but its giving an error that this method is not available.
please guide.
Thank you
Is there a way to get the market status (open/closed) via an API call?
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
please add pnl function or show unreliazed profits in postions data (only realized profts are shown currently)
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:
from ks_api_client import ks_api
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 = "")
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'
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?
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.
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?
How many token i can connect at a time via websocket. ?
How many websocket i can connect on 1 API ?
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.