Skip to content

osparamatrix/ks-orderapi-python

Repository files navigation

ks_api_client

No description provided

  • API version: 1.0.1
  • Package version: 1.0.15

Requirements.

Python 2.7 and 3.4+

Installation & Usage

pip install

If the python package is hosted on a repository, you can install directly using:

pip install git+https://github.com/osparamatrix/ks-orderapi-python.git

(you may need to run pip with root permission: sudo pip install git+https://github.com/osparamatrix/ks-orderapi-python.git)

Then import the package:

import ks_api_client

Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Then import the package:

import ks_api_client

Getting Started

Please follow the installation procedure and then run the following:

from ks_api_client import ks_api
# Defining the host is optional and defaults to https://tradeapi.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 = "")

#For using sandbox environment use host as https://sbx.kotaksecurities.com/apim
client = ks_api.KSTradeApi(access_token = "", userid = "", \
                consumer_key = "", ip = "127.0.0.1", app_id = "", host = "https://sbx.kotaksecurities.com/apim")
		
# Get session for user
client.login(password = "")

#Generated session token
client.session_2fa(access_code = "")

# Place an order
client.place_order(order_type = "N", instrument_token = 727, transaction_type = "BUY",\
                       quantity = 1, price = 0, disclosed_quantity = 0, trigger_price = 0,\
                            validity = "GFD", variety = "REGULAR", tag = "string")
# Place an MIS order
client.place_order(order_type = "MIS", instrument_token = 727, transaction_type = "BUY",\
                       quantity = 1, price = 0, disclosed_quantity = 0, trigger_price = 0,\
                            validity = "GFD", variety = "REGULAR", tag = "string")			    
						
# Modify an order
client.modify_order(order_id = "", quantity = 1, price = 0, disclosed_quantity = 0, trigger_price = 0, validity = "GFD")

# Cancel an order
client.cancel_order(order_id = "")

# Get Report Orders
client.order_report()

# Get Report Orders for order id
client.order_report(order_id = "")

# Get Margin required
order_info = [
    {"instrument_token": 727, "quantity": 1, "price": 1300, "amount": 0, "trigger_price": 1190},
    {"instrument_token": 1374, "quantity": 1, "price": 1200, "amount": 0, "trigger_price": 1150}
]
client.margin_required(transaction_type = "BUY",order_info = order_info)

# Get Positions
client.positions(position_type = "TODAYS")

# Get Quote details
client.quote(instrument_token = 110)

# Get Historical data
client.history("historicalprices",{"exchange":"bse","cocode":"476","fromdate":"01-jan-2014","todate":"08-oct-2015"})
client.history("historicalprices-unadjusted",{"exchange":"bse","co_code":"476","date":"16-Jun-2016"})
client.history("NSEFNO_HistoricalContinuousChart",{"symbol":"HDFC","expiry type": "near"})
client.history("LiveorEODHistorical",{"exchange":"BSE","co_code":"5400","period":"Y","cnt":"3"})

#Terminate user's Session
client.logout()

Documentation for API Endpoints

All URIs are relative to https://tradeapi.kotaksecurities.com/apim

Class Method Description
SessionApi ks_api.KSTradeApi Initialise Session
SessionApi login Login using Userid
SessionApi session_2fa Generate final Session Token
OrderApi place_order Place a New order
OrderApi modify_order Modify an existing order
OrderApi cancel_order Cancel an order
ReportsApi order_report Get order report
ReportsApi trade_report Get trade report
MarginApi margin_required Get Margin Required for an order by amount or quantity.
PositionsApi positions Get's Open position.
QuoteApi quote Get Quote details
HistoricalApi history Get historical data.
SessionApi logout Invalidate Session Token

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •