### Install Kotak Neo Python SDK using Setuptools Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/README.md Instructions for installing the Kotak Neo Python SDK using Setuptools, providing options for user-specific or system-wide installation. ```sh python setup.py install --user ``` -------------------------------- ### Complete Python Example for NeoAPI Quotes Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Quotes.md A comprehensive Python example showing NeoAPI client initialization, login, optional websocket callback setup, and multiple calls to the `quotes` method, including both authenticated and unauthenticated access patterns. ```python from neo_api_client import NeoAPI def on_message(message): print('[Res]: ', message) def on_error(message): result = message print('[OnError]: ', result) client = NeoAPI(consumer_key="", consumer_secret="", environment="prod", access_token=None, neo_fin_key=None) client.login(mobilenumber=" ", password=" ") client.session_2fa("") # Setup Callbacks for websocket events (Optional) client.on_message = on_message # called when message is received from websocket client.on_error = on_error # called when any error or exception occurs in code or websocket client.on_close = None # called when websocket connection is closed client.on_open = None # called when websocket successfully connects inst_tokens = [{"instrument_token": "11536", "exchange_segment": "nse_cm"}, {"instrument_token": "1594", "exchange_segment": "nse_cm"}, {"instrument_token": "11915", "exchange_segment": "nse_cm"}, {"instrument_token": "13245", "exchange_segment": "nse_cm"}] try: # get LTP and Market Depth Data client.quotes(instrument_tokens=inst_tokens, quote_type="", isIndex=False) # OR Quotes API can be accessed without completing login by passing session_token, sid, and server_id client.quotes(instrument_tokens = inst_tokens, quote_type="", isIndex=False, session_token="", sid="",server_id="") except Exception as e: print("Exception when calling get Quote api->quotes: %s\n" % e) ``` -------------------------------- ### Full Python Example for Retrieving Positions Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Positions.md A complete Python example showing how to initialize the NeoAPI client, perform login and 2FA, and then call the `positions()` API, including basic error handling. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(consumer_key=" ",consumer_secret=" ",environment=" ") client.login(mobilenumber=" ", password=" ") client.session_2fa("") try: client.positions() except Exception as e: print("Exception when calling PositionsApi->positions: %s\n" % e) ``` -------------------------------- ### Install Kotak Neo Python SDK using pip Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/README.md Instructions for installing the Kotak Neo Python SDK directly from the GitHub repository using pip, including commands for initial installation and force-reinstallation for updates. ```sh pip install "git+https://github.com/Kotak-Neo/kotak-neo-api.git#egg=neo_api_client" ``` ```sh pip install --force-reinstall "git+https://github.com/Kotak-Neo/kotak-neo-api" ``` -------------------------------- ### Full Python Example for Scrip Search Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Scrip_Search.md A complete Python example showing how to initialize the NeoAPI client, log in, perform a scrip search for 'YESBANK' on 'nse_cm', and include basic exception handling. ```Python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(consumer_key=" ",consumer_secret=" ",environment=" ") client.login(mobilenumber=" ", password=" ") client.session_2fa("") try: # get scrip search details for particular exchange segment client.search_scrip(exchange_segment = "nse_cm", symbol = "YESBANK", expiry = "", option_type = "", strike_price = "") except Exception as e: print("Exception when calling scrip search api->scrip_search: %s\n" % e) ``` -------------------------------- ### Complete Python Example for Retrieving RMS Limits Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Limits.md Provides a comprehensive Python example for initializing the NeoAPI client, performing authentication, and calling the `limits` method with optional parameters and error handling to retrieve RMS limits. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(consumer_key=" ",consumer_secret=" ",environment=" ") client.login(mobilenumber=" ", password=" ") client.session_2fa("") try: client.limits(segment="ALL", exchange="ALL",product="ALL") except Exception as e: print("Exception when calling Limits->limits: %s\n" % e) ``` -------------------------------- ### Initialize NeoAPI Client with Default Callbacks Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Session_init.md Initializes the `NeoAPI` client for a UAT environment, setting all optional callback functions (`on_message`, `on_error`, `on_close`, `on_open`) to `None`. This is a basic setup for starting a trading session. ```python client = NeoAPI(consumer_key="",consumer_secret="",environment="uat",on_message=None, on_error=None, on_close=None, on_open=None, neo_fin_key=None) ``` -------------------------------- ### Complete NeoAPI Client Initialization and Order Retrieval Example (Python) Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Order_report.md This comprehensive Python example showcases the end-to-end process of interacting with the NeoAPI. It includes initializing the `NeoAPI` client, performing login and 2FA for session generation, and then calling both `order_report` and `order_history` methods. Basic exception handling is also demonstrated. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(consumer_key=" ",consumer_secret=" ",environment=" ") client.login(mobilenumber=" ", password=" ") client.session_2fa("") try: # Get all order details client.order_report() # Get particular details using order_id client.order_history() except Exception as e: print("Exception when order report API->order_report: %s\n" % e) ``` -------------------------------- ### Example: Place Order (Python) Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Place_Order.md Demonstrates how to initialize the NeoAPI client, log in, and place an order, including error handling. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(consumer_key=" ",consumer_secret=" ",environment=" ") client.login(mobilenumber=" ", password=" ") client.session_2fa(" ") try: # Place a Order client.place_order(exchange_segment="", product="", price="", order_type="", quantity="", validity="", trading_symbol="", transaction_type="", amo="NO", disclosed_quantity="0", market_protection="0", pf="N", trigger_price="0", tag=None) except Exception as e: print("Exception when calling OrderApi->place_order: %s\n" % e) ``` -------------------------------- ### Successful Login API Response Example Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Login.md An example of the JSON response received upon a successful login, containing the authentication token, session ID, and other user-related data. ```json { "data": { "token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJWaWV3Il0sImV4cCI6MTY4Nzk3NzAwMCwianRpIjoiYzgyMzY2NjAtODkyNy00NzQ0LTk5YmQtMTAyNmRkYTA3MzUzIiwiaWF0IjoxNjg3OTQ2NDQyLCJpc3MiOiJsb2dpbi1zZXJ2aWNlIiwic3ViIjoiYTRlOGE5YzAtZmYyZi0xMWViLTlhMDMtMDI0MmFjMTMwMDAzIiwidWNjIjoiRDIwMTQiLCJuYXAiOiJEVU1NWTExMDVBIiwiZmV0Y2hjYWNoaW5ncnVsZSI6MCwiY2F0ZWdvcmlzYXRpb24iOiIifQ.PRDxhHjdAD2Z_hl3BF_-72l2uds5TzlAEyk57v9BgSnlUZrZ6S9khLi4l8Nfz1zNvwYHqwMPe4Gto6sXnbzbwim-U5c5dDey1hklLTD3kAb6y3bqSR-JcpdvpSGQQ6JVkxckKs_4qDgKEY-0qwnF6jtpB2D_CV0LCKMXfYWNBadZW9-cLLZkIc_C8n6DksyLQF2BWXbTUl6fEb9zSW7GYqI40YLB0q-FZgrOR7dfb3mNtJ4R4oQbeKf0GmR726JWcd3iOqVfFIzHUJvAeVu8FrjWEJfkxjPWf71BU5d_YAUYgtHvRxCweetuZqwa2HNN9xHTNqr6FJdo3W4lhMp1g", "sid": "8f8cd1ab-46e6-41cc-9bdd-9412c5fd4fb7", "rid": "69404582-871b-4de8-8fdd-e3e6a5e15bbf", "hsServerId": "server2", "isUserPwdExpired": false, "caches": { "baskets": "1687845385", "lastUpdatedTS": "1687845385", "multiplewatchlists": "1683352919", "techchartpreferences": "1683528608" }, "ucc": "ABCD0", "greetingName": "DUMMY", "isTrialAccount": false, "dataCenter": "gdc", "searchAPIKey": "" } } ``` -------------------------------- ### Complete WebSocket Live Feed Example with Callbacks (Python) Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/webSocket.md A comprehensive example demonstrating the full lifecycle of a WebSocket connection for live market data. It includes setting up callback functions (`on_message`, `on_error`, `on_open`, `on_close`), initializing the `NeoAPI` client, performing login and 2FA, and then subscribing to a list of specific instrument tokens. Error handling for the subscription process is also included. ```python from neo_api_client import NeoAPI def on_message(message): print('[Res]: ', message) def on_error(message): result = message print('[OnError]: ', result) def on_open(message): print('[OnOpen]: ', message) def on_close(message): print('[OnClose]: ', message) client = NeoAPI(consumer_key="", consumer_secret="", environment="prod", access_token=None, neo_fin_key=None) client.login(mobilenumber=" ", password=" ") client.session_2fa("") # Setup Callbacks for websocket events (Optional) client.on_message = on_message # called when message is received from websocket client.on_error = on_error # called when any error or exception occurs in code or websocket client.on_close = on_close # called when websocket connection is closed client.on_open = on_open # called when websocket successfully connects inst_tokens = [{"instrument_token": "11536", "exchange_segment": "nse_cm"}, {"instrument_token": "1594", "exchange_segment": "nse_cm"}, {"instrument_token": "11915", "exchange_segment": "nse_cm"}, {"instrument_token": "13245", "exchange_segment": "nse_cm"}] try: # Get live feed data client.subscribe(instrument_tokens=inst_tokens) except Exception as e: print("Exception while connection to socket->socket: %s\n" % e) ``` -------------------------------- ### Complete Python Example for Retrieving User Holdings Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Holdings.md Illustrates a full workflow to fetch user holdings using the `neo_api_client` library. This example covers session initialization, user login, 2FA authentication, and includes basic error handling for the API call. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(consumer_key=" ",consumer_secret=" ",environment=" ") client.login(mobilenumber=" ", password=" ") client.session_2fa("") try: client.holdings("") except Exception as e: print("Exception when calling Holdings->holdings: %s\n" % e) ``` -------------------------------- ### Complete Python Login Example with Error Handling Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Login.md Demonstrates how to initialize the `NeoAPI` client with consumer credentials and environment, then perform a login operation, including basic exception handling for API calls. ```python from neo_api_client import NeoAPI client = NeoAPI(consumer_key=" ",consumer_secret=" ",environment="uat") try: # Login using password client.login(mobilenumber=" ", password=" ") except Exception as e: print("Exception when calling SessionApi->login: %s\n" % e) ``` -------------------------------- ### Python: Full Example for Trade Report API Usage Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Trade_report.md A complete example demonstrating the initialization of the `NeoAPI` client, user login, session token generation, and subsequent calls to `trade_report()` to fetch all trades or a specific trade by `order_id`. Includes basic error handling. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(consumer_key=" ",consumer_secret=" ",environment=" ") client.login(mobilenumber=" ", password=" ") client.session_2fa("") try: # Get all trade details client.trade_report() # Get particular traded details using order_id client.trade_report(order_id="") except Exception as e: print("Exception when trade report API->trade_report: %s\n" % e) ``` -------------------------------- ### Place Order API Sample Response (JSON) Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Place_Order.md Example of a successful JSON response after placing an order. ```json { "stat": "Ok", "nOrdNo": "237362700735243", "stCode": 200 } ``` -------------------------------- ### Basic Python Login API Call Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Login.md A basic example demonstrating the `client.login` method call with placeholder parameters for mobile number and password. ```python client.login(mobilenumber="", password = "") ``` -------------------------------- ### Import Kotak Neo Python SDK Package Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/README.md Demonstrates how to import the `neo_api_client` package into a Python script after successful installation. ```python import neo_api_client ``` -------------------------------- ### Basic Python Call to Get RMS Limits Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Limits.md Demonstrates a minimal Python call to the `limits` method of the NeoAPI client to retrieve RMS limits. ```python client.limits() ``` -------------------------------- ### Kotak Neo API Client Method Reference Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/README.md Comprehensive reference for key methods available in the `NeoAPI` client, detailing their purpose, parameters, and usage examples. ```APIDOC NeoAPI.place_order( exchange_segment: str, product: str, price: str, order_type: str, quantity: int, validity: str, trading_symbol: str, transaction_type: str, amo: str = "NO", disclosed_quantity: str = "0", market_protection: str = "0", pf: str = "N", trigger_price: str = "0", tag: Optional[Any] = None ) Purpose: Places a new order. Parameters: exchange_segment: The exchange segment (e.g., NSE, BSE). product: The product type (e.g., CNC, MIS). price: The order price. order_type: The type of order (e.g., LMT, MKT). quantity: The order quantity. validity: The order validity (e.g., GFD, IOC). trading_symbol: The trading symbol. transaction_type: The transaction type (e.g., BUY, SELL). amo: After Market Order (default 'NO'). disclosed_quantity: Disclosed quantity (default '0'). market_protection: Market protection (default '0'). pf: Pro-forma (default 'N'). trigger_price: Trigger price (default '0'). tag: Optional tag for the order. ``` ```APIDOC NeoAPI.modify_order( order_id: str, price: float, quantity: int, disclosed_quantity: int, trigger_price: int, validity: str ) Purpose: Modifies an existing order. Parameters: order_id: The ID of the order to modify. price: The new price for the order. quantity: The new quantity for the order. disclosed_quantity: The new disclosed quantity. trigger_price: The new trigger price. validity: The new validity for the order (e.g., "GFD"). ``` ```APIDOC NeoAPI.cancel_order( order_id: str ) Purpose: Cancels an existing order. Parameters: order_id: The ID of the order to cancel. ``` ```APIDOC NeoAPI.cancel_order( order_id: str, isVerify: bool = False ) Purpose: Cancels an existing order with an optional verification step. Parameters: order_id: The ID of the order to cancel. isVerify: If True, checks the status of the given order ID before proceeding with cancellation. ``` ```APIDOC NeoAPI.order_report() Purpose: Retrieves the order book. Returns: A report of all orders. ``` ```APIDOC NeoAPI.order_history( order_id: str ) Purpose: Retrieves the history for a specific order. Parameters: order_id: The ID of the order to retrieve history for. Returns: Order history details. ``` ```APIDOC NeoAPI.trade_report() Purpose: Retrieves the trade book. Returns: A report of all trades. ``` ```APIDOC NeoAPI.trade_report( order_id: str ) Purpose: Retrieves a detailed trade report for a specific order ID. Parameters: order_id: The ID of the order to retrieve trade details for. Returns: Detailed trade report for the specified order. ``` ```APIDOC NeoAPI.positions() Purpose: Retrieves current positions. Returns: A report of all open positions. ``` ```APIDOC NeoAPI.holdings() Purpose: Retrieves portfolio holdings. Returns: A report of portfolio holdings. ``` ```APIDOC NeoAPI.limits( segment: str, exchange: str, product: str ) Purpose: Retrieves limits for a specific segment, exchange, and product. Parameters: segment: The segment (e.g., equity, commodity). exchange: The exchange (e.g., NSE, BSE). product: The product type (e.g., CNC, MIS). Returns: Limit details. ``` ```APIDOC NeoAPI.margin_required( exchange_segment: str, price: str, order_type: str, product: str, quantity: str, instrument_token: str, transaction_type: str ) Purpose: Retrieves the margin required for equity orders. Parameters: exchange_segment: The exchange segment. price: The order price. order_type: The type of order. product: The product type. quantity: The order quantity. instrument_token: The instrument token. transaction_type: The transaction type. Returns: Required margin details. ``` ```APIDOC NeoAPI.scrip_master() Purpose: Retrieves the complete Scrip Master CSV file. Returns: Scrip Master data. ``` ```APIDOC NeoAPI.scrip_master( exchange_segment: str ) Purpose: Retrieves the Scrip Master CSV file for a specific Exchange Segment. Parameters: exchange_segment: The exchange segment to filter by. Returns: Scrip Master data for the specified segment. ``` ```APIDOC NeoAPI.search_scrip( exchange_segment: str, symbol: str = "", expiry: str = "", option_type: str = "", strike_price: str = "" ) Purpose: Searches for scrip details from the Scrip master file. Parameters: exchange_segment: The exchange segment (mandatory). symbol: The symbol to search for (optional). expiry: The expiry date (optional). option_type: The option type (optional). strike_price: The strike price (optional). Returns: Matching scrip details. ``` ```APIDOC NeoAPI.quotes( instrument_tokens: List[Dict[str, str]], quote_type: Optional[str] = None, isIndex: bool = False, session_token: str = "", sid: str = "", server_id: str = "" ) Purpose: Retrieves quote details for specified instrument tokens. Parameters: instrument_tokens: A list of dictionaries, each containing 'instrument_token' and 'exchange_segment'. quote_type: The type of quote data to retrieve (e.g., market_depth, ohlc, ltp, 52w, circuit_limits, scrip_details). By default, retrieves complete data. isIndex: If True, indicates that the instrument tokens are for index scrips (default False). session_token: Optional session token for accessing quotes without completing login. sid: Optional SID for accessing quotes without completing login. server_id: Optional server ID for accessing quotes without completing login. Returns: Quote details. ``` ```APIDOC NeoAPI.subscribe( instrument_tokens: List ``` ```text ``` ```text ``` -------------------------------- ### Modify Order - Full Example (Python) Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Modify_Order.md Demonstrates a complete workflow for modifying an existing order, including API client initialization, login, 2FA, and error handling. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(consumer_key=" ",consumer_secret=" ",environment=" ") client.login(mobilenumber=" ", password=" ") client.session_2fa("") try: # Modify an existing order client.modify_order(instrument_token = "", exchange_segment = "", product = "", price = "", order_type = "", quantity= "", validity = "", trading_symbol = "",transaction_type = "", order_id = "", amo = "") except Exception as e: print("Exception when calling OrderApi->modify_order: %s\n" % e) ``` -------------------------------- ### Sample JSON Response for Session Token Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/session_2fa.md An example of a successful JSON response received after generating a session token, including the token, session ID, and other user-related data. ```json { "data": { "token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJWaWV3Il0sImV4cCI6MTY4Nzk3NzAwMCwianRpIjoiYzgyMzY2NjAtODkyNy00NzQ0LTk5YmQtMTAyNmRkYTA3MzUzIiwiaWF0IjoxNjg3OTQ2NDQyLCJpc3MiOiJsb2dpbi1zZXJ2aWNlIiwic3ViIjoiYTRlOGE5YzAtZmYyZi0xMWViLTlhMDMtMDI0MmFjMTMwMDAzIiwidWNjIjoiRDIwMTQiLCJuYXAiOiJEVU1NWTExMDVBIiwiZmV0Y2hjYWNoaW5ncnVsZSI6MCwiY2F0ZWdvcmlzYXRpb24iOiIifQ.PRDxhHjdAD2Z_hl3BF_-72l2uds5TzlAEyk57v9BgSnlUZrZ6S9khLi4l8Nfz1zNvwYHqwMPe4Gto6sXnbzbwim-U-U5c5dDey1hklLTD3kAb6y3bqSR-JcpdvpSGQQ6JVkxckKs_4qDgKEY-0qwnF6jtpB2D_CV0LCKMXfYWNBadZW9-cLLZkIc_C8n6DksyLQF2BWXbTUl6fEb9zSW7GYqI40YLB0q-FZgrOR7dfb3mNtJ4R4oQbeKf0GmR726JWcd3iOqVfFIzHUJvAeVu8FrjWEJfkxjPWf71BU5d_YAUYgtHvRxCweetuZqwa2HNN9xHTsNqr6FJdo3W4lhMp1g", "sid": "8f8cd1ab-46e6-41cc-9bdd-9412c5fd4fb7", "rid": "69404582-871b-4de8-8fdd-e3e6a5e15bbf", "hsServerId": "server2", "isUserPwdExpired": false, "caches": { "baskets": "1687845385", "lastUpdatedTS": "1687845385", "multiplewatchlists": "1683352919", "techchartpreferences": "1683528608" }, "ucc": "ABCD0", "greetingName": "DUMMY", "isTrialAccount": false, "dataCenter": "gdc", "searchAPIKey": "" } } ``` -------------------------------- ### Sample JSON Response for Scrip Search Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Scrip_Search.md An example of the JSON object returned by a successful `search_scrip` API call, detailing various attributes of the searched scrip. ```JSON { "pSymbol": 11915, "pGroup": "EQ", "pExchSeg": "nse_cm", "pInstType": null, "pSymbolName": "YESBANK", "pTrdSymbol": "YESBANK-EQ", "pOptionType": null, "pScripRefKey": "YESBANK", "pISIN": "INE528G01035", "pAssetCode": null, "pSubGroup": null, "pCombinedSymbol": null, "pDesc": "YES BANK LIMITED", "pAmcCode": null, "pContractId": null, "dTickSize": 5, "lLotSize": 1, "lExpiryDate": -1, "lMultiplier": -1, "lPrecision": 2, "dStrikePrice;": -1, "pExchange": "NSE", "pInstName": null, "pExpiryDate": null, "pIssueDate": 805593600.0, "pMaturityDate": null, "pListingDate": 805593600.0, "pNoDelStartDate": 0.0, "pNoDelEndDate": 0.0, "pBookClsStartDate": 1244246400.0, "pBookClsEndDate": 1244764800.0, "pRecordDate": 0.0, "pCreditRating": "12.85-19.25", "pReAdminDate": 0.0, "pExpulsionDate": 0.0, "pLocalUpdateTime": 1372357889.0, "pDeliveryUnits": null, "pPriceUnits": null, "pLastTradingDate": null, "pTenderPeridEndDate": null, "pTenderPeridStartDate": null, "pSellVarMargin": null, "pBuyVarMargin": null, "pInstrumentInfo": null, "pRemarksText": null, "pSegment": "CASH", "pNav": null, "pNavDate": null, "pMfAmt": null, "pSipSecurity": null, "pFaceValue": 200.0, "pTrdUnits": null, "pExerciseStartDate": null, "pExerciseEndDate": null, "pElmMargin": 0.0, "pVarMargin": 20.0, "pTotProposedLimitValue": null, "pScripBasePrice": null, "pSettlementType": "T+1", "pCurrectionTime": 315513000.0, "iPermittedToTrade": 0, "iBoardLotQty": 1, "iMaxOrderSize": 6210995, "iLotSize": 1, "dOpenInterest": 0, "dHighPriceRange": 1925.0, "dLowPriceRange": 1285.0, "dPriceNum": 1, "dGenDen": 1, "dGenNum": 1, "dPriceQuatation": 0, "dIssuerate": 0, "dPriceDen": 1, "dWarningQty": 0, "dIssueCapital": 28754600000.0, "dExposureMargin": 0, "dMinRedemptionQty": 0, "lFreezeQty": 6210995 } ``` -------------------------------- ### Example: Initialize NeoAPI Client with Message and Error Handlers Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Session_init.md Demonstrates how to initialize the `NeoAPI` client, providing custom `on_message` and `on_error` callback functions. These functions are used to process incoming messages and handle errors during the trading session, offering more control over session events. ```python from neo_api_client import NeoAPI def on_message(message): print(message) def on_error(error_message): print(error_message) #the session initializes when the following constructor is called client = NeoAPI(consumer_key="",consumer_secret="",environment="uat",on_message=on_message, on_error=on_error) ``` -------------------------------- ### API Reference for Get RMS Limits Endpoint Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Limits.md Detailed API documentation for the `limits` endpoint, outlining its parameters, expected return type, and a sample JSON response structure. This endpoint retrieves RMS limits details for a demat account. ```APIDOC Method: client.limits() Parameters: segment: str [Optional] - CASH, CUR, FO, ALL (Default value - ALL) exchange: str [Optional] - NSE, BSE, ALL (Default value - ALL) product: str [Optional] - CNC, MIS, NRML, ALL (Default value - ALL) Return type: object HTTP request headers: Accept: application/json ``` ```json { "AddPreExpMrgnMisPrsnt": "0.00", "CurExpMrgnNrmlPrsnt": "0.00", "CurPremiumNrmlPrsnt": "0.00", "RmsPayOutAmt": "0.00", "AdhocMargin": "0.00", "MrgnScrpBsktCncPrsnt": "0.00", "FoPremiumMisPrsnt": "17995.00", "tid": "server21_2816", "MrgnVarNrmlPrsnt": "0.00", "AmountUtilizedPrsnt": "0.00", "SplMrgnMisPrsnt": "0.00", "CurSpanMrgnNrmlPrsnt": "0.00", "SlbmVarElm": "0.00", "AuxRmsCollateral": "0.00", "FoUnRlsMtomPrsnt": "0.00", "AuxNotionalCash": "0.00", "AuxAdhocMargin": "0.00", "DaneLimit": "0.00", "RmsMutualFundAmt": "0.00", "RmsPayInAmt": "0.00", "CurPremiumMisPrsnt": "0.00", "SlbmLimit": "0.00", "MarginWarningPrcntPrsnt": "1.45", "MrgnVarMisPrsnt": "0.00", "CurRlsMtomPrsnt": "0.00", "ExposureMarginPrsnt": "7740.95", "NfospreadBenefit": "0.00", "stCode": 200, "CollateralValue": "10000000.00", "AddMrgnNrmlPrsnt": "0.00", "RmsCollateralMult": "1.00", "CncMrgnVarPrsnt": "0.00", "BoardLotLimit": "2000", "ComRlsMtomPrsnt": "0.00", "MarginVarPrsnt": "0.00", "DeliveryMarginPresent": "0.00", "RmsCollateral": "0.00", "ComExpsrMrgnMisPrsnt": "0.00", "CollateralValueMult": "1.00", "FoSpanrgnMisPrsnt": "58881.00", "Category": "CLIENT_MTF", "CurUnRlsMtomPrsnt": "0.00", "SpanMarginPrsnt": "58881.00", "CncSellcrdPresent": "0.00", "Collateral": "0.00", "MrgnScrpBsktNrmlPrsnt": "0.00", "UnrealizedMtomPrsnt": "0.00", "MrgnScrpBsktMisPrsnt": "0.00", "RealizedMtomPrsnt": "59268.70", "MtomWarningPrcntPrsnt": "0.00", "ComSpanMrgnNrmlPrsnt": "0.00", "DeliveryMrgnNrmlPrsnt": "0.00", "AdhocLimitMult": "1.00", "FoPremiumNrmlPrsnt": "0.00", "SpecialMarginPrsnt": "0.00", "SplMrgnNrmlPrsnt": "0.00", "MtomSquareOffWarningPrcntPrsnt": "0.00", "MarginUsedPrsnt": "188025.01", "FoRlsMtomPrsnt": "59265.00", "stat": "Ok", "NationalCashMult": "1.00", "FoSpanrgnNrmlPrsnt": "0.00", "AmtUntilizedPrsnt": "0.00", "PremiumPrsnt": "17995.00", "AddMrgnMisPrsnt": "0.00", "DeliveryMrgnMisPrsnt": "0.00", "SlbmMtom": "0.00", "CdsSpreadBenefit": "0.00", "ComExpsrMrgnNrmlPrsnt": "0.00", "FoExpMrgnNrmlPrsnt": "0.00", "BrokeragePrsnt": "1.86", "CashUnRlsMtomPrsnt": "0.00", "AddPreExpMrgnNrmlPrsnt": "0.00", "CurSpanMrgnMisPrsnt": "0.00", "ComUnRlsMtomPrsnt": "0.00", "CashRlsMtomPrsnt": "6.20", "NotionalCash": "0.00", "CurExpMrgnMisPrsnt": "0.00", "MarginUsed": "188025.01", "LendingFee": "0.00", "Net": "9811974.99", "TenderMrgnMisPrsnt": "0.00", "FoExpMrgnMisPrsnt": "7740.95", "TenderMrgnNrmlPrsnt": "0.00", "MarginScripBasketPrsnt": "0.00", "ComSpanMrgnMisPrsnt": "0.00" } ``` -------------------------------- ### Quotes API Sample JSON Response Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Quotes.md An example of the JSON structure returned by the Quotes API, detailing various market data points for an instrument. ```json { "message": [ { "last_traded_time": "28/06/2023 15:59:47", "volume": "63502734", "last_traded_price": "16.20", "last_traded_quantity": "3", "total_buy_quantity": "622552", "total_sell_quantity": "0", "buy_price": "16.20", "sell_price": "0.00", "buy_quantity": "622552", "average_price": "16.14", "lower_circuit_limit": "13.00", "upper_circuit_limit": "19.40", "52week_high": "24.75", "52week_low": "12.55", "open_interest": "2147483648", "multiplier": "1", "precision": "2", "change": "0.15", "net_change_percentage": "0.93", "total_traded_value": "1024934126.76", "instrument_token": "11915", "exchange_segment": "nse_cm", "trading_symbol": "YESBANK-EQ", "ohlc": { "open": "16.10", "high": "16.35", "low": "15.95", "close": "16.05" }}] } ``` -------------------------------- ### Positions API Sample JSON Response Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Positions.md An example of the successful JSON response structure returned by the Positions API, detailing various attributes of a trading position such as buy/sell quantities, amounts, product type, and instrument details. ```json { "stat": "Ok", "stCode": 200, "data": [ { "buyAmt": "2625.00", "cfSellAmt": "0.00", "prod": "NRML", "exSeg": "nse_fo", "sqrFlg": "Y", "actId": "PRS2206", "cfBuyQty": "0", "cfSellQty": "0", "tok": "53179", "flBuyQty": "25", "flSellQty": "25", "sellAmt": "2625.00", "posFlg": "true", "cfBuyAmt": "0.00", "stkPrc": "0.00", "trdSym": "BANKNIFTY21JULFUT", "sym": "BANKNIFTY", "expDt": "29 Jul, 2021", "type": "FUTIDX", "series": "XX", "brdLtQty": "25", "exp": "1627569000", "optTp": "XX", "genNum": "1", "genDen": "1", "prcNum": "1", "prcDen": "1", "lotSz": "25", "multiplier": "1", "precision": "2", "hsUpTm": "2021/07/13 18:34:44" } ] } ``` -------------------------------- ### Python: Example Usage of `margin_required` Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Margin_Required.md Demonstrates how to initialize the NeoAPI client, log in, and call the `margin_required` method to fetch margin details. Includes error handling for API calls. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(consumer_key=" ",consumer_secret=" ",environment=" ") client.login(mobilenumber=" ", password=" ") client.session_2fa("") try: client.margin_required(exchange_segment = "", price = "", order_type= "", product = "", quantity = "", instrument_token = "", transaction_type = "") except Exception as e: print("Exception when calling margin_required->margin_required: %s\n" % e) ``` -------------------------------- ### Python: Complete Order Cancellation Workflow Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Cancel_Order.md Provides a comprehensive example of canceling an order, including API client initialization, user authentication (login and 2FA), and robust error handling for the cancellation call. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(consumer_key=" ",consumer_secret=" ",environment=" ") client.login(mobilenumber=" ", password=" ") client.session_2fa("") try: # Cancel an order client.cancel_order(order_id = "") except Exception as e: print("Exception when calling OrderApi->cancel_order: %s\n" % e) ``` -------------------------------- ### Modify Order API Sample Response Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Modify_Order.md An example of a successful JSON response from the `modify_order` API call, showing status, order number, and status code. ```json { "stat": "Ok", "nOrdNo": "220621000000097", "stCode": 200 } ``` -------------------------------- ### Sample API Response Data Structure Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Order_report.md An example of the data structure returned in an API response, detailing various fields related to a financial instrument or order, including rejection reasons, timestamps, and pricing information. ```JSON "rejRsn": "RMS:Rule: Check circuit limit including square off order exceeds for entity account-TESTYA24 across exchange across segment across product ", "boeSec": 1655803119, "expDtSsb": "--", "dscQtyPct": "0", "stkPrc": "0.00", "sym": "TCS", "trdSym": "TCS-EQ", "multiplier": "1", "precision": "2", "noMktProFlg": "0.00", "genNum": "1", "series": "EQ", "prcNum": "1", "genDen": "1", "brdLtQty": "1", "mktProFlg": "0.00", "defMktProV": "0.00", "lotSz": "1", "minQty": 0, "optTp": "XX", "prcDen": "1" } ] } ``` -------------------------------- ### Quotes API Index Identifiers Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Quotes.md A list of valid index names that can be used as `instrument_token` when requesting data for indexes, along with an example usage. ```APIDOC For Indexes: Exchange Identifier is not a number. Use names like: - Nifty 50 - Nifty Bank - Nifty Fin Service - SENSEX - INDIA VIX - NIFTY MIDCAP 100 - Nifty 100 - Nifty PSU Bank - Nifty Pharma - Nifty IT - Nifty PSE - Nifty FMCG - Nifty 500 - Nifty Auto - Nifty CPSE - Nifty 200 - Nifty Next 50 - NIFTY MID SELECT Example: inst_tokens = [{"instrument_token": "Nifty 50", "exchange_segment": "nse_cm"}] ``` -------------------------------- ### Sample JSON Response for Kotak Neo API Order Details Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Order_report.md This JSON snippet provides an example of a response payload from the Kotak Neo API, detailing multiple order entries. Each entry includes comprehensive information such as order ID, status (e.g., 'rejected'), transaction type, product, and specific reasons for rejection (e.g., 'RMS:Rule: Check circuit limit'). This structure is crucial for understanding API responses related to order management. ```json { "stat": "Ok", "stCode": 200, "data": [ { "brkClnt": "--", "ordValDt": "NA", "exUsrInfo": "NA", "mfdBy": "NA", "vendorCode": "", "rmk": "--", "odCrt": "NA", "ordSrc": "ADMINCPPAPI_MOB", "sipInd": "NA", "prc": "0.00", "prcTp": "MKT", "cnlQty": 0, "uSec": "364529", "classification": "0", "mktPro": "0.00", "ordEntTm": "--", "reqId": "1", "qty": 1, "unFldSz": 0, "mktProPct": "--", "exOrdId": "NA", "dscQty": 0, "expDt": "NA", "trgPrc": "0.00", "tok": "11536", "symOrdId": "NA", "fldQty": 0, "ordDtTm": "21-Jun-2022 14:49:32", "avgPrc": "0.00", "algId": "NA", "stat": "Ok", "prod": "CNC", "exSeg": "nse_cm", "GuiOrdId": "1655803172-359607-TESTY1124A-ADMINAPI", "usrId": "TESTY1124A", "rptTp": "NA", "exCfmTm": "--", "hsUpTm": "2022/06/21 14:55:28", "ordGenTp": "NA", "vldt": "DAY", "tckSz": "0.05", "ordSt": "rejected", "trnsTp": "B", "refLmtPrc": 0, "coPct": 0, "nOrdNo": "292837000456098", "ordAutSt": "NA", "rejRsn": "RMS:Rule: Check circuit limit including square off order exceeds for entity account-TESTYA24 across exchange across segment across product ", "boeSec": 1655803172, "expDtSsb": "--", "dscQtyPct": "0", "stkPrc": "0.00", "sym": "TCS", "trdSym": "TCS-EQ", "multiplier": "1", "precision": "2", "noMktProFlg": "0.00", "genNum": "1", "series": "EQ", "prcNum": "1", "genDen": "1", "brdLtQty": "1", "mktProFlg": "0.00", "defMktProV": "0.00", "lotSz": "1", "minQty": 0, "optTp": "XX", "prcDen": "1" }, { "brkClnt": "--", "ordValDt": "NA", "exUsrInfo": "NA", "mfdBy": "NA", "vendorCode": "", "rmk": "--", "odCrt": "NA", "ordSrc": "ADMINCPPAPI_MOB", "sipInd": "NA", "prc": "0.00", "prcTp": "MKT", "cnlQty": 0, "uSec": "379164", "classification": "0", "mktPro": "0.00", "ordEntTm": "--", "reqId": "1", "qty": 1, "unFldSz": 0, "mktProPct": "--", "exOrdId": "NA", "dscQty": 0, "expDt": "NA", "trgPrc": "0.00", "tok": "11536", "symOrdId": "NA", "fldQty": 0, "ordDtTm": "21-Jun-2022 14:48:39", "avgPrc": "0.00", "algId": "NA", "stat": "Ok", "prod": "CNC", "exSeg": "nse_cm", "GuiOrdId": "1655803119-377269-TESTY1124A-ADMINAPI", "usrId": "TESTY1124A", "rptTp": "NA", "exCfmTm": "--", "hsUpTm": "2022/06/21 14:55:28", "ordGenTp": "NA", "vldt": "DAY", "tckSz": "0.05", "ordSt": "rejected", "trnsTp": "B", "refLmtPrc": 0, "coPct": 0, "nOrdNo": "220287600096097", "ordAutSt": "NA" } ] } ``` -------------------------------- ### Sample JSON Response for Holdings API Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/docs/Holdings.md Provides an example of the JSON data structure returned by a successful call to the Holdings API. It details individual stock holdings with properties such as symbol, quantity, average price, market value, and exchange information. ```json { "data": [ { "symbol": "YESBANK", "displaySymbol": "YESBANK", "averagePrice": 21.1225, "quantity": 4, "exchangeSegment": "nse_cm", "exchangeIdentifier": "11915", "holdingCost": 84.49, "mktValue": 79, "scripId": "dade08eae3d978dcb31940b6da2cfbab4ab395d3", "instrumentToken": 7169, "instrumentType": "Equity", "isAlternateScrip": "false", "closingPrice": 19.75 }, { "symbol": "CESC", "displaySymbol": "CESC", "averagePrice": 80.01, "quantity": 2, "exchangeSegment": "nse_cm", "exchangeIdentifier": "628", "holdingCost": 160.02, "mktValue": 147.6, "scripId": "fb94935fb38a1dd7f87c52e562d6756636fcb7f3", "instrumentToken": 955, "instrumentType": "Equity", "isAlternateScrip": "false", "closingPrice": 73.8 } ] } ``` -------------------------------- ### Python Project Dependency List Source: https://github.com/kotak-neo/kotak-neo-api/blob/main/requirements.txt This snippet provides a comprehensive list of all Python packages and their specific versions that are essential for the Kotak Neo API project. These dependencies are typically managed via a `requirements.txt` file and installed using `pip` to ensure a consistent development and deployment environment. ```Python bidict==0.22.1 certifi==2022.12.7 idna==2.10 numpy==1.24.2 pyjsparser==2.7.1 PyJWT==2.6.0 python-dateutil==2.8.2 python-dotenv==1.0.0 requests==2.25.1 six==1.16.0 urllib3==1.26.14 websocket-client==1.5.1 websockets==8.1 pandas==2.0.0 asyncio==3.4.3 ```