Python SDK for IIFL Trading APIs
Project description
IIFL Securities Python SDK
Python SDK for IIFL Trading APIs
Documentation
Read the docs hosted here
Features
- Order placement, modification and cancellation
- Fetching user info including holdings, positions, margin and order book.
- Fetching live market feed.
- Fetching order status and trade information.
Installation
pip install IIFLapis
Usage
Configuring API keys
Get your API keys from https://api.iiflsecurities.com/api-keys.html
Configure these keys in a file named keys.conf
in the same directory as your python script exists
A sample keys.conf
is given below:
[KEYS]
APP_NAME=YOUR_APP_NAME_HERE
APP_SOURCE=YOUR_APP_SOURCE_HERE
USER_ID=YOUR_USER_ID_HERE
PASSWORD=YOUR_PASSWORD_HERE
USER_KEY=YOUR_USER_KEY_HERE
ENCRYPTION_KEY=YOUR_ENCRYPTION_KEY_HERE
OCP_KEY=YOUR_OCP_KEY_HERE
Authentication
from IIFLapis import IIFLClient
client = IIFLClient(client_code="client_code", passwd="password", dob="YYYYMMDD", email_id="email",contact_number="Contact Number")
client.client_login() #For Customer Login
client.partner_login() #For Partner Login
After successful authentication, you should get a Logged in!!
message
Market Feed
#NOTE : Symbol has to be in the same format as specified in the example below.
req_list_=[{"Exch":"N","ExchType":"C","ScripCode":"22"},
{"Exch":"N","ExchType":"C","ScripCode":"2885"}]
client.fetch_market_feed(req_list=req_list_, count=2,client_id="client_code")
Fetching user info
# Fetches holdings
client.holdings(client_id = "client_code")
# Fetches margin
client.margin(client_id = "client_code")
# Fetches net positions
client.net_positions(client_id = "client_code")
# Fetches net wise positions
client.net_position_netwise(client_id = "client_code")
# Fetches the order book of the client
client.order_book(client_id = "client_code")
# Fetches the trade book of the client
client.trade_book(client_id = "client_code")
Scrip codes reference:
Note : Use these Links for getting scrip codes
CSV Scrip Dump: https://api.iiflsecurities.com/scrip-master.html
Enums
Following are the enums which can be imported and used for placing more complex orders.
class Exchange(Enum):
NSE = "N"
BSE = "B"
MCX = "M"
class ExchangeSegment(Enum):
CASH = "C"
DERIVATIVE = "D"
CURRENCY = "U"
class OrderType(Enum):
BUY = "BUY"
SELL = "SELL"
class OrderValidity(Enum):
DAY = 0
GTD = 1
GTC = 2
IOC = 3
EOS = 4
FOK = 6
class AHPlaced(Enum):
AFTER_MARKET_CLOSED = "Y"
NORMAL_ORDER = "N"
Placing an order
# Note: This is an indicative order.
from IIFLapis.order import Order, OrderType, Exchange, ExchangeSegment, OrderValidity, AHPlaced
test_order = Order(order_type="BUY", scrip_code=2885, quantity=1, exchange="N",
exchange_segment="C", price=1164, is_intraday=False, atmarket=False, order_id=2,
remote_order_id="1", exch_order_id="0", DisQty=0, stoploss_price=0,
is_stoploss_order=False, ioc_order= False, is_vtd=False,ahplaced = AHPlaced.NORMAL_ORDER,
public_ip='192.168.1.1', order_validity=OrderValidity.DAY, traded_qty=0)
client.place_order(order=test_order,client_id='client_code',order_requester_code='order_requester_code')
Modifying an order
test_order = Order(order_type="BUY", scrip_code=2885, quantity=1, exchange="N",
exchange_segment="C", price=1164, is_intraday=False, atmarket=False, order_id=2,
remote_order_id="1", exch_order_id="12345678", DisQty=0, stoploss_price=0,
is_stoploss_order=False, ioc_order= False, is_vtd=False, ahplaced = "N",
vtd=f"/Date({NEXT_DAY_TIMESTAMP})/", public_ip='192.168.1.1',
order_validity=OrderValidity.DAY, traded_qty=0)
client.modify_order(order=test_order,client_id='client_code',order_requester_code='order_requester_code')
Canceling an order
test_order = Order(order_type='B', scrip_code=1660, quantity=1,exchange='N',exchange_segment='C',exch_order_id='12345678')
client.cancel_order(order=test_order,client_id='client_code',order_requester_code='order_requester_code')
Fetching Order Status and Trade Information
from IIFLapis.order import Exchange
req_list= [
{
"Exch": "N",
"ExchType": "C",
"ScripCode": 20374,
"ExchOrderID": "1000000015310807"
}]
# Fetches the trade details
client.fetch_trade_info(req_list=req_list,client_id='client_code')
req_list_= [
{
"Exch": "N",
"ExchType": "C",
"ScripCode": 20374,
"RemoteOrderID": "90980441"
}]
# Fetches the order status
client.fetch_order_status(req_list=req_list_,client_id='client_code')
TODO
- Write tests.
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for IIFLapis-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b47bc2b4c6c515452bb1621e234deafe0791065519d805cb8e071d881e2d57ee |
|
MD5 | 5f19e6e6e3ab5ad810158f4fce6ffe97 |
|
BLAKE2b-256 | 52f19b10c3610fb738408ec7d3a45d423474d00d36aa464366f4887e5ce411c9 |