### Example Usage Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/webSocket.md Example of setting up callbacks and subscribing to live feed data. ```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(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") # 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) ``` -------------------------------- ### Example Order Placement Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Place_Order.md This is a full example of how to initialize the client and place an order, including error handling. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") 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, scrip_token=None, square_off_type=None, stop_loss_type=None, stop_loss_value=None, square_off_value=None, last_traded_price=None, trailing_stop_loss=None, trailing_sl_value=None, ) except Exception as e: print("Exception when calling OrderApi->place_order: %s\n" % e) ``` -------------------------------- ### Install via Setuptools Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Installs the package using Setuptools. ```sh python setup.py install --user ``` -------------------------------- ### Example Usage Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/webSocket_orderfeed.md A comprehensive example demonstrating how to set up callbacks for WebSocket events and subscribe to the orderfeed. ```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(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") # 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 try: # Get live feed data client.subscribe_to_orderfeed() except Exception as e: print("Exception while connection to orderfeed socket->subscribe_to_orderfeed: %s\n" % e) ``` -------------------------------- ### Example Usage of Scrip Search Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Scrip_Search.md An example demonstrating how to initialize the NeoAPI client and use the search_scrip method. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") 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) ``` -------------------------------- ### Example Usage Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Limits.md This example demonstrates how to initialize the NeoAPI client, log in, validate TOTP, and then call the limits method with optional parameters. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") try: client.limits(segment="ALL", exchange="ALL",product="ALL") except Exception as e: print("Exception when calling Limits->limits: %s\n" % e) ``` -------------------------------- ### Example Usage Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Positions.md This example demonstrates initializing the NeoAPI client, logging in, validating TOTP, and then calling the positions() method. It also includes basic error handling. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") try: client.positions() except Exception as e: print("Exception when calling PositionsApi->positions: %s\n" % e) ``` -------------------------------- ### Example Usage Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Scrip_Master.md This example demonstrates how to initialize the NeoAPI client, log in, validate TOTP, and call the scrip_master API, including error handling. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") try: client.scrip_master() except Exception as e: print("Exception when calling Scrip Master Api->scrip_master: %s\n" % e) ``` -------------------------------- ### TOTP Login Example Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Totp_login.md This snippet provides a more complete example of how to use the totp_login function, including initialization and exception handling. ```python from neo_api_client import NeoAPI client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) try: client.totp_login(mobilenumber="", ucc="", totp='') except Exception as e: print("Exception when calling TOTPLogin ->login: %s\n" % e) ``` -------------------------------- ### Example Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Totp_validate.md This example shows how to initialize the NeoAPI client and call the totp_validate method, including basic error handling. ```python from neo_api_client import NeoAPI client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) try: client.totp_validate(mpin="") except Exception as e: print("Exception when calling TOTPLogin ->totp_validate: %s\n" % e) ``` -------------------------------- ### Example Usage Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Quotes.md Example of how to use the Quotes API with instrument tokens. ```python from neo_api_client import NeoAPI #Only need to initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) instrument_tokens = [ {"instrument_token": "Nifty 50", "exchange_segment": "nse_cm"}, {"instrument_token": "Nifty Bank", "exchange_segment": "nse_cm"} ] try: client.quotes(instrument_tokens = instrument_tokens, quote_type = "all") except Exception as e: print("Exception when calling Quotes Api->quotes: %s\n" % e) ``` -------------------------------- ### Example Usage Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Order_report.md This is a comprehensive example demonstrating the initialization of the NeoAPI client, session login, token validation, and calling the order_report() method with error handling. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") try: # Get all order details client.order_report() except Exception as e: print("Exception when order report API->order_report: %s\n" % e) ``` -------------------------------- ### Example Usage Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Holdings.md This example demonstrates initializing the NeoAPI client, logging in, validating the session, and then calling the holdings API. It also includes basic error handling. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") try: client.holdings("") except Exception as e: print("Exception when calling Holdings->holdings: %s\n" % e) ``` -------------------------------- ### Full Example with Initialization and Error Handling Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Cancel_Cover_Order.md A comprehensive example demonstrating session initialization, order cancellation, and exception handling. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") try: # Cancel an order client.cancel_cover_order(order_id = "") except Exception as e: print("Exception when calling OrderApi->cancel_cover_order: %s\n" % e) ``` -------------------------------- ### Install using pip Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Installs the Kotak Neo API client package from a Git repository using pip. ```sh pip install "git+https://github.com/Kotak-Neo/Kotak-neo-api-v2.git@v2.0.1#egg=neo_api_client" ``` -------------------------------- ### Example Usage Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Trade_report.md Example demonstrating how to initialize the NeoAPI client, log in, and use the trade_report method to fetch all trade details or specific order details. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") 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) ``` -------------------------------- ### Get RMS Limits details Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Limits.md This snippet shows how to get RMS Limits details using the client.limits() method. ```python client.limits() ``` -------------------------------- ### Get ScripMaster CSV file Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Scrip_Master.md This code snippet shows how to get the ScripMaster CSV file. ```python client.scrip_master() ``` -------------------------------- ### Full Example Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Cancel_Bracket_Order.md Demonstrates initializing the NeoAPI client, logging in, validating TOTP, and then cancelling a bracket order with error handling. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") try: # Cancel an order client.cancel_bracket_order(order_id = "") except Exception as e: print("Exception when calling OrderApi->cancel_bracket_order: %s\n" % e) ``` -------------------------------- ### Example of Modifying an Order Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Modify_Order.md A complete Python example demonstrating how to initialize the NeoAPI client, log in, and modify an order, including exception handling. ```python from neo_api_client import NeoAPI from neo_api_client import BaseUrl #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") 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) ``` -------------------------------- ### Get Positions Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Positions.md This snippet shows how to call the positions() method. ```python client.positions() ``` -------------------------------- ### Example Usage Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Margin_Required.md This snippet demonstrates how to initialize the NeoAPI client, log in, and then call the margin_required function with error handling. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") 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) ``` -------------------------------- ### Full Example with Session Initialization Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Cancel_Order.md Demonstrates initializing the NeoAPI client, logging in, validating TOTP, and then cancelling an order within a try-except block. ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") try: # Cancel an order client.cancel_order(order_id = "") except Exception as e: print("Exception when calling OrderApi->cancel_order: %s\n" % e) ``` -------------------------------- ### Totp validation Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Totp_validate.md This is a basic example of how to call the totp_validate method. ```python client.totp_validate(mpin="") ``` -------------------------------- ### Import neo_api_client Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Imports the neo_api_client package after installation. ```python import neo_api_client ``` -------------------------------- ### Get all order details Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Order_report.md This snippet shows how to call the order_report() method to get all order details. ```python client.order_report() ``` -------------------------------- ### Subscribe to Live Feed Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Subscribes to live feed details for given tokens. By default, `isIndex` is False. Set to True to get live feed for index scrips. By default, `isDepth` is False. Set to True to get depth information. ```python # Subscribe method will get you the live feed details of the given tokens. # By Default isIndex is set as False and you want to get the live feed to index scrips set the isIndex flag as True # By Default isDepth is set as False and you want to get the depth information set the isDepth flag as True ``` -------------------------------- ### Sample Response Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Cancel_Order.md Example JSON response for a successful order cancellation. ```json { "stat": "Ok", "nOrdNo": "230120000017243", "stCode": 200 } ``` -------------------------------- ### Get Limits Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Retrieves the limits available for the given segment, exchange, and product. ```python client.limits(segment="", exchange="", product="") ``` -------------------------------- ### Get Portfolio Holdings Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Retrieves the current holdings for the portfolio. ```python client.holdings() ``` -------------------------------- ### Get Margin Required for Equity Orders Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Calculates the margin required for a given trade. ```python client.margin_required(exchange_segment = "", price = "", order_type= "", product = "", quantity = "", instrument_token = "", transaction_type = "") ``` -------------------------------- ### Get Scrip Master CSV File for Specific Exchange Segment Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Retrieves the list of scrips available in the given exchange segment. ```python client.scrip_master(exchange_segment = "") ``` -------------------------------- ### Get Quote Details Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Retrieves quote details for specified instrument tokens. The `quote_type` parameter can be 'all', 'depth', 'ohlc', 'ltp', 'oi', '52w', 'circuit_limits', or 'scrip_details'. By default, `quote_type` is 'all'. Quotes API can be accessed by access token without completing login. ```python instrument_tokens = [ {"instrument_token": "", "exchange_segment": ""}, {"instrument_token": "", "exchange_segment": ""}, {"instrument_token": "", "exchange_segment": ""} ] client.quotes(instrument_tokens = instrument_tokens, quote_type = "") ``` -------------------------------- ### Get ScripMaster CSV file for a specific segment Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Scrip_Master.md To get ScripMaster file of a particular segment, pass the exchange segment within bracket. For example - `client.scripmaster(nse_cm)` ```python client.scripmaster(nse_cm) ``` -------------------------------- ### Initialize NeoAPI Client Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Initializes the NeoAPI client with environment, access token, neo_fin_key, and consumer_key. ```python client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None, consumer_key='YOUR_TOKEN') ``` -------------------------------- ### Place Order Parameters Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Place_Order.md This snippet shows the parameters available for placing an order. ```python 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, scrip_token=None, square_off_type=None, stop_loss_type=None, stop_loss_value=None, square_off_value=None, last_traded_price=None, trailing_stop_loss=None, trailing_sl_value=None, ) ``` -------------------------------- ### Sample Response Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Place_Order.md A sample JSON response indicating a successful order placement. ```json { "stat": "Ok", "nOrdNo": "", "stCode": 200 } ``` -------------------------------- ### Sample Response Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/webSocket.md Sample response structure for live data. ```json { #Gets live data } ``` -------------------------------- ### Session Initialization Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Session_init.md The session initializes when the NeoAPI constructor is called. You can either pass consumer_key and consumer_secret or an access_token. ```python from neo_api_client import NeoAPI #the session initializes when the following constructor is called # Either you pass consumer_key and consumer_secret or you pass acsess_token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) ``` -------------------------------- ### Get Order History Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Order_history.md Retrieves details of a specific order by its ID. ```python client.order_history(order_id = "") ``` ```python from neo_api_client import NeoAPI #First initialize session and generate session token client = NeoAPI(environment='prod', access_token=None, neo_fin_key=None) client.totp_login(mobilenumber="", ucc="", totp='') client.totp_validate(mpin="") try: # Get particular details using order_id client.order_history() except Exception as e: print("Exception when order history API->order_history: %s\n" % e) ``` -------------------------------- ### Sample Equity Response Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Scrip_Search.md This JSON object represents a sample response for an equity scrip search, detailing various parameters like symbol, exchange, tick size, and more. ```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": 1,"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": "16.65-20.35","pReAdminDate": 0.0,"pExpulsionDate": 0.0,"pLocalUpdateTime": 1421948339.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": 5392180,"iLotSize": 1,"dOpenInterest": 0,"dHighPriceRange": 2035.0,"dLowPriceRange": 1665.0,"dPriceNum": 1,"dGenDen": 1,"dGenNum": 1,"dPriceQuatation": 0,"dIssuerate": 0,"dPriceDen": 1,"dWarningQty": 0,"dIssueCapital": 31349900000.0,"dExposureMargin": 0,"dMinRedemptionQty": 0,"lFreezeQty": 5392180}],"pSymbol": 12900,"pGroup": "BL","pExchSeg": "nse_cm","pInstType": null,"pSymbolName": "YESBANK","pTrdSymbol": "YESBANK-BL","pOptionType": null,"pScripRefKey": "YESBANK-BL","pISIN": "INE528G01035","pAssetCode": null,"pSubGroup": null,"pCombinedSymbol": null,"pDesc": "YES BANK LIMITED","pAmcCode": null,"pContractId": null,"dTickSize": 1,"lLotSize": 1,"lExpiryDate": -1,"lMultiplier": -1,"lPrecision": 2,"dStrikePrice;": -1,"pExchange": "NSE","pInstName": null,"pExpiryDate": null,"pIssueDate": 816220800.0,"pMaturityDate": null,"pListingDate": 816220800.0,"pNoDelStartDate": 0.0,"pNoDelEndDate": 0.0,"pBookClsStartDate": 1244246400.0,"pBookClsEndDate": 1244764800.0,"pRecordDate": 0.0,"pCreditRating": "18.31-18.68","pReAdminDate": 0.0,"pExpulsionDate": 0.0,"pLocalUpdateTime": 1421947175.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": null,"pVarMargin": null,"pTotProposedLimitValue": null,"pScripBasePrice": null,"pSettlementType": "T+1","pCurrectionTime": 315513000.0,"iPermittedToTrade": 0,"iBoardLotQty": 1,"iMaxOrderSize": 0,"iLotSize": 1,"dOpenInterest": 0,"dHighPriceRange": 1868.0,"dLowPriceRange": 1831.0,"dPriceNum": 1,"dGenDen": 1,"dGenNum": 1,"dPriceQuatation": 0,"dIssuerate": 0,"dPriceDen": 1,"dWarningQty": 0,"dIssueCapital": 31349900000.0,"dExposureMargin": 0,"dMinRedemptionQty": 0,"lFreezeQty": 99999999}] ``` -------------------------------- ### Websocket Event Callbacks Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Sets up optional callbacks for websocket events. ```python def on_message(message): print(message) def on_error(error_message): print(error_message) def on_close(message): print(message) def on_open(message): print(message) # 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 ``` -------------------------------- ### Get Order History Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Retrieves the order history for a given order ID. ```python client.order_history(order_id = "") ``` -------------------------------- ### Force Reinstall using pip Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Force reinstalls the Kotak Neo API client package from a Git repository using pip, useful for updates. ```sh pip install --force-reinstall "git+https://github.com/Kotak-Neo/Kotak-neo-api-v2.git@v2.0.1#egg=neo_api_client" ``` -------------------------------- ### Sample Response Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Margin_Required.md This is a sample JSON response for the margin_required API call. ```json { "data": { "avlCash": "38.190000", "totMrgnUsd": "34.280000", "mrgnUsd": "18.780000", "ordMrgn": "15.500000", "rmsVldtd": "OK", "reqdMrgn": "0.000000", "avlMrgn": "0.000000", "insufFund": "0.000000", "stat": "Ok", "stCode": 200 } } ``` -------------------------------- ### Get all traded order details Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Trade_report.md This method retrieves all traded order details. ```python client.trade_report() ``` -------------------------------- ### Search Scrip Details Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Searches for scrip details from the Scrip master file. ```python client.search_scrip(exchange_segment="", symbol="", expiry="", option_type="", strike_price="") ``` -------------------------------- ### Subscribe to Orderfeed Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/webSocket_orderfeed.md This snippet shows how to subscribe to the orderfeed using the NeoAPI client. ```python client.subscribe_to_orderfeed() ``` -------------------------------- ### Get details of a particular order using order_id Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Trade_report.md This method retrieves details of a specific order using its order_id. ```python client.trade_report(order_id = "") ``` -------------------------------- ### Subscribe to Order Feed Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Subscribes to the order feed. ```python #Order Feed # This function subscribes to order feed client.subscribe_to_orderfeed() ``` -------------------------------- ### TOTP Login Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Logs in using TOTP (Time-based One-Time Password) with mobile number, UCC, and TOTP. ```python client.totp_login(mobile_number="", ucc="", totp='') ``` -------------------------------- ### Subscribe to Instrument Data Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Subscribes to instrument data, with options to include index and depth data. ```python #instrument_tokens: This is a list of dictionaries. # instrument_token: The instrument token of the stock which you will get from master scrip file # exchange_segment: Expected values are nse_cm, bse_cm, nse_fo, bse_fo, cde_fo, mcx_fo # isIndex: If you want to subscribe to index data, set isIndex to True # isDepth: If you want to subscribe to depth data, set isDepth to True client.subscribe(instrument_tokens = instrument_tokens, isIndex=False, isDepth=False) ``` -------------------------------- ### Cancel Order with Verification Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md This snippet shows how to cancel an order with an option to verify its status before cancellation. If the order is already rejected, cancelled, traded, or completed, it won't be cancelled. ```python # order_id: Order number you'll recieve from the response after placing the order # isVerify: isVerify is an optional param. Default value is 'False'. If isVerify is True, we will first check the status of the given order. If the order status is not 'rejected', 'cancelled', 'traded', or 'completed', we will proceed to cancel the order using the cancel_order function. Otherwise, we will display the order status to the user instead. # amo: It specifies whether its an after market order. Expected values are YES and NO # This request will check whether your order is rejected, cancelled, complete or traded. If any of this is true, your order will not be cancelled. This will be rejected with the rejection reson. # If this is not the case, the your order will be cancelled. client.cancel_order(order_id = "", amo = "", isVerify=True) ``` -------------------------------- ### Cancel Cover Order with Verification Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md This snippet shows how to cancel a cover order with an option to verify its status before cancellation. If the order is already rejected, cancelled, traded, or completed, it won't be cancelled. ```python # order_id: Order number you'll recieve from the response after placing the order # isVerify: isVerify is an optional param. Default value is 'False'. If isVerify is True, we will first check the status of the given order. If the order status is not 'rejected', 'cancelled', 'traded', or 'completed', we will proceed to cancel the order using the cancel_order function. Otherwise, we will display the order status to the user instead. # This request will check whether your order is rejected, cancelled, complete or traded. If any of this is true, your order will not be cancelled. This will be rejected with the rejection reson. # amo: It specifies whether its an after market order. Expected values are YES and NO client.cancel_cover_order(order_id = "", amo = "", isVerify=False) ``` -------------------------------- ### Subscribe to live feed Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/webSocket.md Subscribe to live feed details of the given tokens. ```python inst_tokens = [{"instrument_token": "", "exchange_segment": ""}] client.subscribe(instrument_tokens = inst_tokens, isIndex=False, isDepth=False) ``` -------------------------------- ### Sample Order History Response Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Order_history.md This JSON object represents a sample response for an order in the 'Ok' status. ```json {"data": {"stat": "Ok", "stCode": 200, "data": [ {"trdSym": "IDEA-EQ", "prc": "9.39", "qty": 1, "ordSt": "complete", "trnsTp": "B", "prcTp": "L", "brdLtQty": 1, "exch": "NSE", "exSeg": "nse_cm", "exchTmstp": "22-Jan-2025 14: 32: 53", "expDt": "NA", "tok": "14366", "nOrdNo": "250122000624384", "nReqId": "1", "sym": "IDEA", "avgPrc": "9.39", "algId": "NA", "algCat": "NA", "algSeqNo": "NA", "trgPrc": "0.00", "dclQty": "0", "exchOrdId": "1100000060414692", "rejRsn": "--", "ordDur": "DAY", "prod": "NRML", "rptTp": "NA", "cstFrm": "C", "ordSrc": "ADMINCPPAPI_FINTECH001", "flDtTm": "22-Jan-2025 14: 33: 01", "ordGenTp": "--", "scripName": "IDEA", "stkPrc": "0.00", "legOrdInd": "NA", "fldQty": 1, "ordUsrMsg": "NA", "mfdBy": "XX", "unFldSz": 0, "vendorCode": "", "classification": "0", "prcNum": "1", "series": "EQ", "genNum": "1", "prcDen": "1", "genDen": "1", "lotSz": "1", "multiplier": "1", "precision": "2", "mktPro": "0.00", "GuiOrdId": "", "symOrdId": "NA", "locId": "111111111111100", "optTp": "XX", "strategyCode": "NA", "ordValDt": "NA", "updRecvTm": 1737536606366027474, "boeSec": 1737536606, "uSec": "1737536606366" }, {"trdSym": "IDEA-EQ", "prc": "9.39", "qty": 1, "ordSt": "open", "trnsTp": "B", "prcTp": "L", "brdLtQty": 1, "exch": "NSE", "exSeg": "nse_cm", "exchTmstp": "22-Jan-2025 14: 32: 53", "expDt": "NA", "tok": "14366", "nOrdNo": "250122000624384", "nReqId": "1", "sym": "IDEA", "avgPrc": "0.00", "algId": "NA", "algCat": "NA", "algSeqNo": "NA", "trgPrc": "0.00", "dclQty": "0", "exchOrdId": "1100000060414692", "rejRsn": "--", "ordDur": "DAY", "prod": "NRML", "rptTp": "NA", "cstFrm": "C", "ordSrc": "ADMINCPPAPI_FINTECH001", "flDtTm": "22-Jan-2025 14: 32: 53", "ordGenTp": "--", "scripName": "IDEA", "stkPrc": "0.00", "legOrdInd": "NA", "fldQty": 0, "ordUsrMsg": "NA", "mfdBy": "XX", "unFldSz": 1, "vendorCode": "", "classification": "0", "prcNum": "1", "series": "EQ", "genNum": "1", "prcDen": "1", "genDen": "1", "lotSz": "1", "multiplier": "1", "precision": "2", "mktPro": "0.00", "GuiOrdId": "", "symOrdId": "NA", "locId": "111111111111100", "optTp": "XX", "strategyCode": "NA", "ordValDt": "NA", "updRecvTm": 1737536606366114068, "boeSec": 1737536606, "uSec": "1737536606366" }, {"trdSym": "IDEA-EQ", "prc": "9.39", "qty": 1, "ordSt": "open pending", "trnsTp": "B", "prcTp": "L", "brdLtQty": 1, "exch": "NSE", "exSeg": "nse_cm", "exchTmstp": "--", "expDt": "NA", "tok": "14366", "nOrdNo": "250122000624384", "nReqId": "1", "sym": "IDEA", "avgPrc": "0.00", "algId": "NA", "algCat": "NA", "algSeqNo": "NA", "trgPrc": "0.00", "dclQty": "0", "exchOrdId": "NA", "rejRsn": "--", "ordDur": "DAY", "prod": "NRML", "rptTp": "NA", "cstFrm": "C", "ordSrc": "ADMINCPPAPI_FINTECH001", "flDtTm": "22-Jan-2025 14: 32: 53", "ordGenTp": "--", "scripName": "IDEA", "stkPrc": "0.00", "legOrdInd": "NA", "fldQty": 0, "ordUsrMsg": "NA", "mfdBy": "XX", "unFldSz": 1, "vendorCode": "", "classification": "0", "prcNum": "1", "series": "EQ", "genNum": "1", "prcDen": "1", "genDen": "1", "lotSz": "1", "multiplier": "1", "precision": "2", "mktPro": "0.00", "GuiOrdId": "", "symOrdId": "NA", "locId": "111111111111100", "optTp": "XX", "strategyCode": "NA", "ordValDt": "NA", "updRecvTm": 1737536606366181251, "boeSec": 1737536606, "uSec": "1737536606366" }, {"trdSym": "IDEA-EQ", "prc": "9.39", "qty": 1, "ordSt": "validation pending", "trnsTp": "B", "prcTp": "L", "brdLtQty": 1, "exch": "NSE", "exSeg": "nse_cm", "exchTmstp": "--", "expDt": "NA", "tok": "14366", "nOrdNo": "250122000624384", "nReqId": "1", "sym": "IDEA", "avgPrc": "0.00", "algId": "NA", "algCat": "NA", "algSeqNo": "NA", "trgPrc": "0.00", "dclQty": "0", "exchOrdId": "NA", "rejRsn": "--", "ordDur": "DAY", "prod": "NRML", "rptTp": "NA", "cstFrm": "C", "ordSrc": "ADMINCPPAPI_FINTECH001", "flDtTm": "22-Jan-2025 14: 32: 53", "ordGenTp": "--", "scripName": "IDEA", "stkPrc": "0.00", "legOrdInd": "NA", "fldQty": 0, "ordUsrMsg": "NA", "mfdBy": "XX", "unFldSz": 1, "vendorCode": "", "classification": "0", "prcNum": "1", "series": "EQ", "genNum": "1", "prcDen": "1", "genDen": "1", "lotSz": "1", "multiplier": "1", "precision": "2", "mktPro": "0.00", "GuiOrdId": "", "symOrdId": "NA", "locId": "111111111111100", "optTp": "XX", "strategyCode": "NA", "ordValDt": "NA", "updRecvTm": 1737536606366181251, "boeSec": 1737536606, "uSec": "1737536606366" } ] }} ``` -------------------------------- ### Cancel Cover Order Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md This snippet demonstrates how to cancel a cover order using its order ID. ```python # Cancel cover order # order_id: Order number you'll recieve from the response after placing the order client.cancel_cover_order(order_id = "") ``` -------------------------------- ### Sample Order History Response Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/docs/Order_history.md This JSON snippet represents a sample response from an order history API, showcasing various fields related to order details. ```json { "genDen": "1", "lotSz": "1", "multiplier": "1", "precision": "2", "mktPro": "0.00", "GuiOrdId": "", "symOrdId": "NA", "locId": "111111111111100", "optTp": "XX", "strategyCode": "NA", "ordValDt": "NA", "updRecvTm": 1737536606366256162, "boeSec": 1737536606, "uSec": "1737536606366" }, { "trdSym": "IDEA-EQ", "prc": "9.39", "qty": 1, "ordSt": "put order req received", "trnsTp": "B", "prcTp": "L", "brdLtQty": 1, "exch": "NSE", "exSeg": "nse_cm", "exchTmstp": "--", "expDt": "NA", "tok": "14366", "nOrdNo": "250122000624384", "nReqId": "1", "sym": "IDEA", "avgPrc": "0.00", "algId": "NA", "algCat": "NA", "algSeqNo": "NA", "trgPrc": "0.00", "dclQty": "0", "exchOrdId": "NA", "rejRsn": "--", "ordDur": "DAY", "prod": "NRML", "rptTp": "NA", "cstFrm": "C", "ordSrc": "ADMINCPPAPI_FINTECH001", "flDtTm": "22-Jan-2025 14: 32: 53", "ordGenTp": "--", "scripName": "", "stkPrc": "0.00", "legOrdInd": "NA", "fldQty": 0, "ordUsrMsg": "NA", "mfdBy": "XX", "unFldSz": 1, "vendorCode": "", "classification": "0", "prcNum": "1", "series": "EQ", "genNum": "1", "prcDen": "1", "genDen": "1", "lotSz": "1", "multiplier": "1", "precision": "2", "mktPro": "0.00", "GuiOrdId": "", "symOrdId": "NA", "locId": "", "optTp": "XX", "strategyCode": "NA", "ordValDt": "NA", "updRecvTm": 1737536606366304511, "boeSec": 1737536606, "uSec": "1737536606366" } ] } } ``` -------------------------------- ### Terminate Session Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md Logs out the user and terminates the current session. ```python #Terminate user's Session client.logout() ``` -------------------------------- ### Cancel Order Source: https://github.com/kotak-neo/kotak-neo-api-v2/blob/main/README.md This snippet demonstrates how to cancel an order using its order ID. ```python # Cancel an order # order_id: Order number you'll recieve from the response after placing the order client.cancel_order(order_id = "") ```