Kotak API
Kotak API
Kotak API
(Optional)
Description of Result items Array
{
"percentage_static_rates": {
"brokerage": "0.49%",
"transaction_charges": "0.00345%",
"stt_ctt": "0.1%",
"sebi_tax": "0.0001%",
"stamp_duty": "0.015%",
"gst": "18%"
},
"value_static_rates": {
"brokerage": 88.2,
"transaction_charges": 0.62,
"stt_ctt": 18,
"sebi_tax": 0.02,
"stamp_duty": 3,
"gst": 15.99,
"total_charges": 125.83
},
"display_rates": {
"brokerage_str": "0.49% or Rs. 21 per order whichever is higher",
"transaction_charges_str": "0.62",
"stt_ctt_str": "18",
"sebi_tax_str": "0.02",
"stamp_duty_str": "3",
"gst_str": "15.99",
"total_charges_str": "125.83"
}
}
Response of Success example
{
"result_items": [
{
"percentage_static_rates": [ "2.5%", "0.00345%", "0.1%", "0.0001%",
"0.015%", "18%" ],
"value_static_rates": [ 986.88, 1.36, 39.48, 0.04, 6, 177.89, 1211.65 ],
"display_rates": [ "2.5% or Rs. 21 per order whichever is higher",
"1.36", "39.48", "0.04", "6", "177.89", "1211.65" ]
},
{
"percentage_static_rates": [ "2.5%", "0.00345%", "0.1%", "0.0001%",
"0.015%", "18%" ],
"value_static_rates": [ 986.88, 1.36, 39.48, 0.04, 6, 177.89, 1211.65 ],
"display_rates": [ "2.5% or Rs. 21 per order whichever is higher",
"1.36", "39.48", "0.04", "6", "177.89", "1211.65" ]
},
{
"error": "inactive_segment",
"error_description": "As per our records, in your account the segment
selected for this stock is inactive and hence we are unable to show charges
related to this order. You can activate the segment by visiting the profile
section."
}
],
"sum_total_charges": [ 1973.76, 2.72, 78.96, 0.08, 12, 355.78, 2423.3 ],
"result_count": {
"success": 2,
"error": 1,
"error_message": "We are unable to calculate the charges for this order
since the trading segment you have selected for one of the scrips / contracts
is possibly inactive. You can still continue placing your order (for other
scrips) and check your charges in your contract note or you can check
individual scrip-wise charges by entering the order information on the
individual scrip order page"
}
}
Documentation
Margin API:
Margin API takes consumer key, session token and access token as header
inputs, with no data body, to return complete margin details associated
with the client, classified segment-wise.
https://tradeapi.kotaksecurities.com/apim/margin/1.0/margin
Headers = {
'accept': 'application/json',
Order API:
The order API is concerned with all order placements, modifications, and
cancellations. The following types of orders are available at this time. Their
respective endpoints are listed as follows:
TYPES:
Normal
Order: https://tradeapi.kotaksecurities.com/apim/orders/1.0/order/
normal
For each of the above endpoints, the request type determines whether
the request is an order placement, modification or cancellation (POST,
PUT, and DELETE respectively). For order placement, an input parameter
labelled 'instrument token' is listed. This refers to a unique number that
dictates to the server the instrument listing that the order is placed in.
Each listing on each exchange has a unique token. These values change
over time, and the latest list can be obtained via the scrip master
generation URL.
Headers = {
'accept': 'application/json',
'Content-Type': 'application/json',
Data:
Headers = {
'accept': 'application/json',
'Content-Type': 'application/json',
Data:
Headers = {
'accept': 'application/json',
'Content-Type': 'application/json',
For example, to cancel a NORMAL order type, the url will be:
https://tradeapi.kotaksecurities.com/apim/orders/1.0/order/normal/\
<order ID\>
Positions API:
Positions API takes consumer key, session token and access token as
header inputs, with no data body, to return positions associated with the
client
https://tradeapi.kotaksecurities.com/apim/positions/1.0/positions/todays
Headers = {
'accept': 'application/json',
Headers = {
'accept': 'application/json',
Headers = {
'accept': 'application/json',
Quotes API:
Quotes APIs take consumer key, session token and access token as
header inputs, with no data body, to return instantaneous quotes for any
particular scrip associated with the instrument token passed into the url.
The instrument token for the scrip can be retrieved using the scrip master
generation URL.
Depth (returns the disclosed depth of existing orders for the scrip)
https://tradeapi.kotaksecurities.com/apim/quotes/v1.0/depth/
instruments/ \<instrument token\>
Headers = {
'accept': 'application/json',
Headers = {
'accept': 'application/json',
Headers = {
'accept': 'application/json',
Headers = {
'accept': 'application/json',
Reports API:
Reports API takes consumer key, session token and access token as
header inputs, with no data body, to return order book associated with
the client, or if order ID is specified, the order status history.
Order Details (returns the general details of all orders placed by the
client)
https://tradeapi.kotaksecurities.com/apim/reports/1.0/orders
Headers = {
'accept': 'application/json',
Headers = {
'accept': 'application/json',
Trade Details (returns the general details of all trades made by the client)
https://tradeapi.kotaksecurities.com/apim/reports/1.0/trades
Request type: GET
Headers = {
'accept': 'application/json',
Headers = {
'accept': 'application/json',
Session API:
The first step to logging in is to generate the One-Time Token, which will
later be required for the 2-factor authentication function. For this you
must input your user ID and password associated with your Kotak
securities account as data, along with your access token, consumer key, IP
address, and app ID as header inputs (latter two being optional inputs for
clients):
Generate OTT
https://tradeapi.kotaksecurities.com/apim/session/1.0/session/login/
userid
Headers = {
'accept': 'application/json',
'Content-Type': 'application/json',
Data:
https://tradeapi.kotaksecurities.com/apim/session/1.0/session/2FA/
oneTimeToken
Headers = {
'accept': 'application/json',
'Content-Type': 'application/json',
Data:
Once the above function is executed you will have your validated session
token iin your response body that can be used as header input for all
subsequent API requests.
https://tradeapi.kotaksecurities.com/apim/session/1.0/session/2FA/
accesscode
Request type: POST
Headers = {
'accept': 'application/json',
'Content-Type': 'application/json',
Data:
Attribute
Datatype Description
Name
userid String Your trading account user ID
Your Kotak securities access code (sent to
accessCode String
mobile)
Once the above function is executed you will have your validated session
token iin your response body that can be used as header input for all
subsequent API requests.
Tokens Api
grant_type=password
URL
https://tradeapi.kotaksecurities.com/token
Method
POST
Request header
grant_type=password
username=<your_username>
password=<your_password>
Sample CURL
Sample Response
{
"access_token": "4e125cd8-4e05-3ba4-b48c-eb1fe1c40743",
"refresh_token": "ad51d5e6-b3c3-39e4-adf3-5b4f17786adb",
"scope": "default",
"token_type": "Bearer",
"expires_in": 3600
----------------------------------------------
grant_type=refresh_token
URL
https://tradeapi.kotaksecurities.com/token
Method
POST
Request header
grant_type=refresh_token
refresh_token=<refresh_token>
Sample CURL
curl -k -X POST https://tradeapi.kotaksecurities.com/token --header
"Authorization: Basic Base64(consumer-key:consumer-secret)" --header
'Content-Type: application/x-www-form-urlencoded' --data-urlencode
'grant_type=refresh_token' --data-urlencode
'refresh_token=<refresh_token>'
Sample Response
"access_token": "803a74b0-47e2-34e7-b1af-66eb01ad4d7b",
"refresh_token": "d668eb08-0751-33fc-8bc1-f6ebfb557418",
"scope": "default",
"token_type": "Bearer",
"expires_in": 3600
----------------------------------------------
grant_type=client_credentials
URL
https://tradeapi.kotaksecurities.com/token
Method
POST
Request header
grant_type=client_credentials
Sample CURL
Sample Response
"access_token": "77c74dea-c463-3892-8667-36a0c7c7e890",
"token_type": "Bearer",
"expires_in": 3600
----------------------------------------------
ks_api_client
No description provided
Requirements.
Python 2.7 and 3.4+
pip install
If the python package is hosted on a repository, you can install directly using:
pip install -e
"git+https://github.com/paramatrixtech/ksapi.git#egg=ks_api_client&subdirectory=./
python"
(you may need to run pip with root permission: sudo pip install -e
"git+https://github.com/paramatrixtech/ksapi.git#egg=ks_api_client&subdirectory=./
python")
Then import the package:
import ks_api_client
Setuptools
import ks_api_client
Getting Started
Please follow the installation procedure and then run the following:
# Place an order
client.place_order(order_type = "O", instrument_token = 727, transaction_type =
"BUY",\
quantity = 1, price = 0, disclosed_quantity = 0, trigger_price =
0,\
validity = "GFD", variety = "REGULAR", tag = "string", product =
"NORMAL", smart_order_routing="string")
# Modify an order
client.modify_order(order_id = "", price = 0, quantity = 1, disclosed_quantity = 0,
trigger_price = 0, validity = "GFD")
# Cancel an order
client.cancel_order(order_id = "")
# Get Margin
client.margin()
# Get Positions
client.positions(position_type = "TODAYS")
ks_api.KSTradeAp
SessionApi Initialise Session
i
StreamingAp
unsubscribe Unsubscribe from streaming api.
i