Skip to main content

Python SDK for 5paisa APIs natively written in VB.NET

Project description

5paisa Python SDK

Python SDK for 5paisa APIs natively written in VB .NET

PyPI GitHub Workflow Status (branch)

5paisa logo

Documentation

Read the docs hosted here

Features

  • Order placement, modification and cancellation
  • Fetching user info including holdings, positions, margin and order book.
  • Fetching order status and trade information.

Installation

pip install py5paisa

Usage

Configuring API keys

Get your API keys from https://www.5paisa.com/developerapi/apikeys

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

Authentication

from py5paisa import FivePaisaClient

client = FivePaisaClient(email="random_email@xyz.com", passwd="password", dob="YYYYMMDD")
client.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":"D","Symbol":"NIFTY 22 APR 2021 CE 15200.00","Expiry":"20210422","StrikePrice":"15200","OptionType":"CE"},
            {"Exch":"N","ExchType":"D","Symbol":"NIFTY 22 APR 2021 PE 15200.00","Expiry":"20210422","StrikePrice":"15200","OptionType":"PE"}]

client.fetch_market_feed(req_list_)

Fetching user info

# Fetches holdings
client.holdings()

# Fetches margin
client.margin()

# Fetches positions
client.positions()

# Fetches the order book of the client
client.order_book()

Scrip codes reference:

Note : Use these Links for getting scrip codes

BSE: https://www.bseindia.com/ NSE FO: https://www.5paisa.com/docs/default-source/scrip-master/contract.txt NSE CASH : https://www.5paisa.com/docs/default-source/scrip-master/security.txt

Placing an order

# Note: This is an indicative order.

from py5paisa.order import Order, OrderType, Exchange, ExchangeType

test_order = Order(order_type='B',exchange='N',exchange_segment='C', scrip_code=1660, quantity=1, price=205,is_intraday=True,atmarket=False)
client.place_order(test_order)

Modifying an order

test_order = Order(order_type='B', scrip_code=1660, quantity=1, price=205,is_intraday=False,exchange='N',exchange_segment='C',atmarket=True,exch_order_id="12345678" )
client.modify_order(test_order)

Canceling an order

client.cancel_order(order_type='B', scrip_code=1660, quantity=1,exchange='N',exchange_segment='C',exch_order_id='12345678')

Bracket Order

#For placing Braket order

test_order=bo_co_order(scrip_code=1660,BuySell='B',Qty=1, LimitPriceInitialOrder=204,TriggerPriceInitialOrder=0,LimitPriceProfitOrder=208.0,TriggerPriceForSL=202,RequestType='P',AtMarket=False)

client.bo_order(test_order)

#For Modifying Bracket Order only for Initial order (entry)
test_order=bo_co_order(scrip_code=1660,BuySell='B',Qty=1, LimitPriceInitialOrder=203,TriggerPriceInitialOrder=0,LimitPriceProfitOrder=208.0,TriggerPriceForSL=202,RequestType='M',AtMarket=False,ExchOrderId='12345678')

client.bo_order(test_order)

#Note : For cover order just pass LimitPriceProfitOrder equal to Zero.

#For Modifying LimitPriceProfitOrder 
test_order=Order(order_type='S', scrip_code=1660, quantity=1, price=208.50,is_intraday=True,exchange='N',exchange_segment='C',atmarket=False,exch_order_id="12345678" ,order_for=OrderFor.MODIFY)

client.mod_bo_order(test_order)

#For Modifying TriggerPriceForSL
#test_order=Order(order_type='S', scrip_code=1660, quantity=1, price=0,is_intraday=True,exchange='N',exchange_segment='C',atmarket=True,exch_order_id="123456789" ,stoploss_price=201.50,is_stoploss_order=True,order_for=OrderFor.MODIFY)

client.mod_bo_order(test_order)

#Note : You have pass atmarket=true while modifying stoploss price, Pass ExchorderId for the particular leg to modify.

Fetching Order Status and Trade Information

from py5paisa.order import  Exchange, ExchangeType

req_list= [

        {
            "Exch": "N",
            "ExchType": "C",
            "ScripCode": 20374,
            "ExchOrderID": "1000000015310807"
        }]

# Fetches the trade details
client.fetch_trade_info(req_list)

req_list_= [

        {
            "Exch": "N",
            "ExchType": "C",
            "ScripCode": 20374,
            "RemoteOrderID": "90980441"
        }]
# Fetches the order status
client.fetch_order_status(req_list_)

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

py5paisa-0.2.1.tar.gz (58.2 kB view details)

Uploaded Source

Built Distribution

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

py5paisa-0.2.1-py2.py3-none-any.whl (9.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file py5paisa-0.2.1.tar.gz.

File metadata

  • Download URL: py5paisa-0.2.1.tar.gz
  • Upload date:
  • Size: 58.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.3

File hashes

Hashes for py5paisa-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a8947b94e5eece6cb1f79e477d8293bb23859fc95654aed145a5b12a103da8be
MD5 c0acb8e03ec58d20d6cff3a63c26ac32
BLAKE2b-256 45aabcd7e0fcf78a103e76bd5cadf4903033c85ad8bcbe9940a63209643996e1

See more details on using hashes here.

File details

Details for the file py5paisa-0.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: py5paisa-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.3

File hashes

Hashes for py5paisa-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 394b5ed82661c486aebcc78a2b1f3a3ce1746ea9f8f003f7468bfb9f8e2928dc
MD5 e0ce81ea50b989e4e805d4417a60a480
BLAKE2b-256 c1ba95c198aaca661b76291e0b817ba6f9af5dfd6572f96a72cdbd34dc8742e1

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