Skip to main content

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

Historical Candle Data

#To fetch historical candle data, jwt token needs to be validated first.
client.jwt_validation("client_code")

#After successful jwt validation, historical data can be fetched.            
client.historical_candles(exch='n',exchType='c',scripcode='1660',interval='30m',fromdate='2021-04-01',todate='2021-04-30',client_id="client_code")

Fetching user info

# Fetches client profile
client.profile(client_id = "client_code")

# Fetches holdings
client.holdings(client_id = "client_code")

# Fetches DP holdings
client.dp_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")

Fetching transactions info

# Fetches equity transactions
client.equity_transactions(client_id="client_code", from_date="20210201", to_date="20210301")

# Fetches future transactions
client.future_transactions(client_id="client_code", from_date="20210201", to_date="20210301")

# Fetches option transactions
client.option_transactions(client_id="client_code", from_date="20210201", to_date="20210301")

# Fetches mutual funds transactions
client.mf_transactions(client_id="client_code", from_date="20210201", to_date="20210301")

# Fetches DP transactions
client.dp_transactions(client_id="client_code", from_date="20210201", to_date="20210301")

# Fetches ledger
client.ledger(client_id="client_code", from_date="20210201", to_date="20210301")

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

IIFLapis-2.1.0.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

IIFLapis-2.1.0-py2.py3-none-any.whl (10.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file IIFLapis-2.1.0.tar.gz.

File metadata

  • Download URL: IIFLapis-2.1.0.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for IIFLapis-2.1.0.tar.gz
Algorithm Hash digest
SHA256 2f3c234049a1a0d83761b102d76951897be8d0d542a0e3777257d0140e37ee33
MD5 6bfa5b69465041fc990b19f896a8e502
BLAKE2b-256 5df538adab8cfc509f17ca70141f06a5cb89954053a09e789a183e3e020450d6

See more details on using hashes here.

File details

Details for the file IIFLapis-2.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: IIFLapis-2.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for IIFLapis-2.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7983be447cab6dd31075350cdc8652cafbb653de6573e748f459ead86704b21c
MD5 b0e55d7678a2c39cea74f2332498a73f
BLAKE2b-256 8eba268973787ec1d11bd1bbee5bbe59d487b25b106bf3bd1282b56e75c49db6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page