Wed. Jun 11th, 2025

    5paisa is an Indian financial services company that provides an online trading platform for buying and selling stocks, commodities, and other financial instruments. They also offer an Application Programming Interface (API) that allows developers to access various functionalities of their trading platform programmatically.

    Below is a general explanation of what an API is and what functionalities the 5paisa API might offer :

    What is an API?

    An API, or Application Programming Interface, is a set of rules and protocols that allows different software applications to communicate and interact with each other. It defines how different components of software systems should interact, making it easier for developers to integrate various services and functionalities into their own applications without having to understand the underlying implementation details.

    5paisa API Basics

    The 5paisa API provide developers with access to the various features and services offered by the 5paisa trading platform. These functionalities might include:

    5paisa API Integration

    To use the 5paisa API, developers typically need to register for an API key from 5paisa. The API key acts as a unique identifier and access token for their application. The API key helps 5paisa track usage and may also be used to control access to specific API functionalities.

    Get your API keys from https://tradestation.5paisa.com/apidoc

    5paisa Github repo: https://github.com/OpenApi-5p/py5paisa

    5paisa Installation

    Please do Pip install for python 5paisa API as:

    pip install py5paisa
    
    

    5paisa Authentication API

    Most APIs require authentication to ensure secure access. The 5paisa API likely uses an OAuth-based authentication mechanism. You’ll need to obtain an access token using your API key and secret key before making any API requests. The specific steps for authentication are outlined below:

    from py5paisa import FivePaisaClient
    cred={
        "APP_NAME":"YOUR APP_NAME",
        "APP_SOURCE":"YOUR APP_SOURCE",
        "USER_ID":"YOUR USER_ID",
        "PASSWORD":"YOUR PASSWORD",
        "USER_KEY":"YOUR USERKEY",
        "ENCRYPTION_KEY":"YOUR ENCRYPTION_KEY"
        }
    
    #This function will automatically take care of generating and sending access token for all your API's
    
    client = FivePaisaClient(cred=cred)
    
    # New TOTP based authentication
    client.get_totp_session('Your ClientCode','TOTP from authenticator app','Your Pin')
    
    # OAUTH Approach
    # First get a token by logging in to -> https://dev-openapi.5paisa.com/WebVendorLogin/VLogin/Index?VendorKey=<Your Vendor Key>&ResponseURL=<Redirect URL>
    # VendorKey is UesrKey for individuals user
    # for e.g. you can use ResponseURL as https://www.5paisa.com/technology/developer-apis
    # Pass the token received in the response url after successful login to get an access token (this also sets the token for all the APIs you use)-
    
    # Please note that you need to copy the request token from URL and paste in this code and start the code within 30s.
    
    client.get_oauth_session('Your Response Token')
    
    After successful authentication, you should get a `Logged in!!` message in console
    

    5paisa Trading Operations

    Through the API, developers can place buy and sell orders for stocks, commodities, and other financial instruments available on the 5paisa platform. They can specify the details of the orders, such as the stock symbol, quantity, order type (market order, limit order, etc.), and other relevant parameters.

    client.place_order(OrderType='B',Exchange='N',ExchangeType='C', ScripCode = 1660, Qty=1, Price=260)
    
    
    

    5paisa Market Data

    The API offer access to real-time market data, including stock quotes, historical price data, trade volumes, and other relevant market statistics. This information can be used to perform technical analysis, build trading strategies, and make informed decisions.

    #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_)
    
    #historical_data(<Exchange>,<Exchange Type>,<Scrip Code>,<Time Frame>,<From Data>,<To Date>)
    
    df=client.historical_data('N','C',1660,'15m','2021-05-25','2021-06-16')
    print(df)
    

    5paisa Account Information

    Developers can use the API to retrieve information about the user’s 5paisa account, including account balance, holdings, positions, transaction history, and other account-related details.

    # Fetches holdings
    client.holdings()
    
    # Fetches margin
    client.margin()
    
    # Fetches positions
    client.positions()
    
    

    5paisa Order Management

    The API may support features for managing orders, such as modifying or canceling existing orders.

    client.modify_order(ExchOrderID="1100000017861430", Qty=2,Price=261)
    
    client.cancel_order(exch_order_id="1100000017795041")
    

    5paisa Margin and Leverage

    The API might offer access to information about margin requirements and leverage available for different financial instruments, enabling developers to make informed decisions based on risk management strategies.

    # Fetches margin
    client.margin()
    
    

    5paisa API Documentation

    https://www.5paisa.com/developerapi/overview


    The 5paisa API comes with detailed documentation that explains the endpoints, request parameters, response formats, authentication methods, and usage limits. Developers should refer to this documentation to understand how to make API calls and integrate the functionalities into their applications successfully.