noddy09 / ks-orderapi-python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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/noddy09/ks-orderapi-python.git

(you may need to run pip with root permission: sudo pip install git+https://github.com/noddy09/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 hosts is optional and defaults to ["https://tradeapi.kotaksecurities.com/apim","https://ctradeapi.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 specific environment use host="https://tradeapi.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 = "")

#Generate session token without access code [Optional]
client.session_2fa()

# 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 calculate margins
client.get_margins()

# 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"})

# Subscribe to instrument token's stream.
def callback_method(message):
    print(message)
    print("Your logic/computation will come here.")
client.subscribe(input_token="745,754", auth_token="", callback=callback_method)

# Unsubscribe from streaming service.
client.unsubscribe()

#Terminate user's Session
client.logout()

Documentation for API Endpoints

All URIs are relative to https://tradeapi.kotaksecurities.com/apim and https://ctradeapi.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.
MarginApi get_margins Get all calculated margins.
PositionsApi positions Get's Open position.
QuoteApi quote Get Quote details
HistoricalApi history Get historical data.
StreamingApi subscribe Subscribe to streaming api of specified instrument tokens.
StreamingApi unsubscribe Unsubscribe from streaming api.
SessionApi logout Invalidate Session Token

About


Languages

Language:Python 99.8%Language:Shell 0.2%