### Make a GET Request Source: https://api.icicidirect.com/breezeapi/documents/index.html Example of making a GET request to the BreezeAPI using OkHttpClient. ```APIDOC ## Make a GET Request (OkHttpClient) ### Description This example demonstrates how to make a GET request to the BreezeAPI using the OkHttpClient library in Java. ### Method GET ### Endpoint `https://breezeapi.icicidirect.com` ### Headers - **User-Agent**: XYZABC - **user**: LZLAL - **token**: 12i299 ### Request Example ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://breezeapi.icicidirect.com") .method("GET", null) .addHeader("User-Agent", "XYZABC") .addHeader("user", "LZLAL") .addHeader("token", "12i299") .build(); Response response = client.newCall(request).execute(); ``` ``` -------------------------------- ### HTTP GET Request Example Source: https://api.icicidirect.com/breezeapi/documents/index.html This snippet shows how to make a GET request to the BreezeAPI using OkHttpClient in Java. ```APIDOC ## HTTP GET Request ### Description This example demonstrates how to perform an HTTP GET request to the BreezeAPI using OkHttpClient in Java. ### Method GET ### Endpoint https://breezeapi.icicidirect.com/ ### Headers - **User-Agent**: XYZABC - **user**: LZLAL - **token**: 12i299 ### Request Example (Java - OkHttpClient) ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://breezeapi.icicidirect.com") .method("GET", null) .addHeader("User-Agent", "XYZABC") .addHeader("user", "LZLAL") .addHeader("token", "12i299") .build(); Response response = client.newCall(request).execute(); ``` ``` -------------------------------- ### Make HTTP GET Request in Java Source: https://api.icicidirect.com/breezeapi/documents/index.html Example of making a GET request to the BreezeAPI using OkHttpClient. Ensure correct headers for authentication and user agent are provided. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://breezeapi.icicidirect.com") .method("GET", null) .addHeader("User-Agent", "XYZABC") .addHeader("user", "LZLAL") .addHeader("token", "12i299") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### HTTP GET Request Example (C#) Source: https://api.icicidirect.com/breezeapi/documents/index.html This snippet shows how to make a GET request to the BreezeAPI using RestClient in C#. ```APIDOC ## HTTP GET Request (C#) ### Description This example demonstrates how to perform an HTTP GET request to the BreezeAPI using RestClient in C#. ### Method GET ### Endpoint https://breezeapi.icicidirect.com/ ### Headers - **user**: LZLAL - **token**: 12i299 ### Request Example (C# - RestClient) ```csharp var client = new RestClient("https://breezeapi.icicidirect.com"); client.Timeout = -1; var request = new RestRequest(Method.GET); client.UserAgent = "XYZABC"; request.AddHeader("user", "LZLAL"); request.AddHeader("token", "12i299"); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` ``` -------------------------------- ### Make a GET Request (Axios) Source: https://api.icicidirect.com/breezeapi/documents/index.html Example of making a GET request to the BreezeAPI using Axios. ```APIDOC ## Make a GET Request (Axios) ### Description This example demonstrates how to make a GET request to the BreezeAPI using the Axios library in JavaScript. ### Method GET ### Endpoint `https://breezeapi.icicidirect.com` ### Headers - **User-Agent**: XYZABC - **user**: LZLAL - **token**: 12i299 ### Request Example ```javascript var axios = require('axios'); var config = { method: 'get', url: 'https://breezeapi.icicidirect.com', headers: { 'User-Agent': 'XYZABC', 'user': 'LZLAL', 'token': '12i299' } }; axios(config) .then(function (response) { console.log(JSON.stringify(response.data)); }) .catch(function (error) { console.log(error); }); ``` ``` -------------------------------- ### JavaScript Example using Axios Source: https://api.icicidirect.com/breezeapi/documents/index.html This snippet demonstrates how to make a GET request to the Oneclick Equity Strategy endpoint using axios in JavaScript. ```APIDOC ## Oneclick Equity Strategy (iclick_2_gain) ### Description This section provides a JavaScript example using the `axios` library to interact with the Oneclick Equity Strategy API. ### Method GET ### Endpoint `https://breezeapi.icicidirect.com` ### Headers - **User-Agent**: XYZABC - **user**: LZLAL - **token**: 12i299 ### Request Example ```javascript var axios = require('axios'); var config = { method: 'get', url: 'https://breezeapi.icicidirect.com', headers: { 'User-Agent': 'XYZABC', 'user': 'LZLAL', 'token': '12i299' } }; axios(config) .then(function (response) { console.log(JSON.stringify(response.data)); }) .catch(function (error) { console.log(error); }); ``` ### Response #### Success Response (200) Returns the data associated with the Oneclick Equity Strategy. #### Response Example ```json { "example": "response data" } ``` ``` -------------------------------- ### Get Order List using RestClient (C#) Source: https://api.icicidirect.com/breezeapi/documents/index.html This C# example uses RestClient to fetch order lists. It demonstrates setting up the request with necessary headers and a JSON payload. ```csharp var client = new RestClient("https://api.icicidirect.com/breezeapi/api/v1/order"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AddHeader("Content-Type", "application/json"); request.AddHeader("X-Checksum", "token "); request.AddHeader("X-Timestamp", ""); request.AddHeader("X-AppKey", ""); request.AddHeader("X-SessionToken", ""); var body = @"{ "exchange_code": "NSE", "from_date": "2022-05-29T10:00:00.000Z", "to_date": "2022-05-31T10:00:00.000Z" }"; request.AddParameter("application/json", body, ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### Make HTTP GET Request with OkHttpClient Source: https://api.icicidirect.com/breezeapi/documents/index.html Demonstrates how to make a GET request to the BreezeAPI using OkHttpClient in Java. Includes setting URL, headers, and executing the request. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://breezeapi.icicidirect.com") .method("GET", null) .addHeader("User-Agent", "XYZABC") .addHeader("user", "LZLAL") .addHeader("token", "12i299") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Get Portfolio Holdings with RestClient (C#) Source: https://api.icicidirect.com/breezeapi/documents/index.html This C# example uses RestClient to fetch portfolio holdings. It demonstrates setting request headers and the request body, including specific parameters for filtering holdings. ```csharp var client = new RestClient("https://api.icicidirect.com/breezeapi/api/v1/portfolioholdings"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AddHeader("Content-Type", "application/json"); request.AddHeader("X-Checksum", "token "); request.AddHeader("X-Timestamp", ""); request.AddHeader("X-AppKey", ""); request.AddHeader("X-SessionToken", ""); var body = @"{ " + "\n" + " "exchange_code":"NSE", " + "\n" + " "from_date":"", " + "\n" + " "to_date":"", " + "\n" + " "stock_code":"JKPAP", " + "\n" + " "portfolio_type":"" " + "\n" + "}"; request.AddParameter("application/json", body, ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### Make HTTP GET Request with Axios Source: https://api.icicidirect.com/breezeapi/documents/index.html Example of making a GET request to the BreezeAPI using Axios in JavaScript. Configures the request with URL and headers, then logs the response data or any errors. ```javascript var axios = require('axios'); var config = { method: 'get', url: 'https://breezeapi.icicidirect.com', headers: { 'User-Agent': 'XYZABC', 'user': 'LZLAL', 'token': '12i299' } }; axios(config) .then(function (response) { console.log(JSON.stringify(response.data)); }) .catch(function (error) { console.log(error); }); ``` -------------------------------- ### Get Customer Details with OkHttpClient (Java) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Java example demonstrates fetching customer details using OkHttpClient. The request includes the 'Content-Type' header and specifies the API endpoint. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://api.icicidirect.com/breezeapi/api/v1/customerdetails") .method("GET", null) .addHeader("Content-Type", "application/json") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Make HTTP GET Request in C# Source: https://api.icicidirect.com/breezeapi/documents/index.html Demonstrates making a GET request to the BreezeAPI using RestClient. Includes setting timeout, headers, and handling the response. ```csharp var client = new RestClient("https://breezeapi.icicidirect.com"); client.Timeout = -1; var request = new RestRequest(Method.GET); client.UserAgent = "XYZABC"; request.AddHeader("user", "LZLAL"); request.AddHeader("token", "12i299"); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### Get Order Detail using Java (OkHttp) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Java code snippet demonstrates how to make a GET request to retrieve order details using the OkHttpClient library. Ensure all required headers are correctly populated. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://api.icicidirect.com/breezeapi/api/v1/order") .method("GET", null) .addHeader("Content-Type", "application/json") .addHeader("X-Checksum", "token ") .addHeader("X-Timestamp", "") .addHeader("X-AppKey", "") .addHeader("X-SessionToken", "") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Get Margin Information (Java) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Java code demonstrates how to make a GET request to the margin API using OkHttpClient. Ensure all header values are correctly populated. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://api.icicidirect.com/breezeapi/api/v1/margin") .method("GET", null) .addHeader("Content-Type", "application/json") .addHeader("X-Checksum", "token ") .addHeader("X-Timestamp", "") .addHeader("X-AppKey", "") .addHeader("X-SessionToken", "") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Get Portfolio Positions using OkHttpClient (Java) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Java code snippet shows how to make a GET request to retrieve portfolio positions using OkHttpClient. It sets up the request with the necessary URL and headers. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://api.icicidirect.com/breezeapi/api/v1/portfoliopositions") .method("GET", null) .addHeader("Content-Type", "application/json") .addHeader("X-Checksum", "token ") .addHeader("X-Timestamp", "") .addHeader("X-AppKey", "") .addHeader("X-SessionToken", "") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Get Portfolio Holdings with OkHttpClient (Java) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Java code snippet shows how to make a GET request to retrieve portfolio holdings using OkHttpClient. It includes setting the URL and necessary headers. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://api.icicidirect.com/breezeapi/api/v1/portfolioholdings") .method("GET", null) .addHeader("Content-Type", "application/json") .addHeader("X-Checksum", "token ") .addHeader("X-Timestamp", "") .addHeader("X-AppKey", "") .addHeader("X-SessionToken", "") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Get Order List using OkHttpClient (Java) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Java code snippet shows how to make a GET request to retrieve order lists using OkHttpClient. Ensure all required headers are correctly populated. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://api.icicidirect.com/breezeapi/api/v1/order") .method("GET", null) .addHeader("Content-Type", "application/json") .addHeader("X-Checksum", "token ") .addHeader("X-Timestamp", "") .addHeader("X-AppKey", "") .addHeader("X-SessionToken", "") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Get Funds using Java (OkHttp) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Java code snippet shows how to make a GET request to the Breeze API for fund information using the OkHttpClient library. Ensure that the placeholder headers are replaced with actual values. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://api.icicidirect.com/breezeapi/api/v1/funds") .method("GET", null) .addHeader("Content-Type", "application/json") .addHeader("X-Checksum", "token ") .addHeader("X-Timestamp", "") .addHeader("X-AppKey", "") .addHeader("X-SessionToken", "") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Place an Options Order using Python Source: https://api.icicidirect.com/breezeapi/documents/index.html This Python script demonstrates placing an options order. It includes fetching a session token and generating a checksum. Replace placeholder values for secret_key, appkey, and session_key. ```python import requests import json import hashlib from datetime import datetime, timezone customerDetail_url = "https://api.icicidirect.com/breezeapi/api/v1/customerdetails" secret_key = "Your Secret_key goes here" appkey = "Your App_Key goes here" session_key = "Your Session_key goes here" time_stamp = datetime.now(timezone.utc).isoformat()[:19] + '.000Z' customerDetail_payload = json.dumps({ "SessionToken": session_key, "AppKey": appkey }) customerDetail_headers = { 'Content-Type': 'application/json', } customerDetail_response = requests.request("GET", customerDetail_url, headers=customerDetail_headers, data=customerDetail_payload) data = json.loads(customerDetail_response.text) session_token = data["Success"]["session_token"] url = "https://api.icicidirect.com/breezeapi/api/v1/order" payload = json.dumps({ "stock_code": "NIFTY", "exchange_code": "NFO", "product": "options", "action": "buy", "order_type": "limit", "quantity": "25", "price": "1", "validity": "day", "stoploss": "", "validity_date": "2024-07-23T06:00:00.000Z", "disclosed_quantity": "0", "expiry_date": "2024-09-12T06:00:00.000Z", "right": "call", "strike_price": "25000", "user_remark": "testing" }, separators=(',', ':')) checksum = hashlib.sha256((time_stamp+payload+secret_key).encode("utf-8")).hexdigest() headers = { 'Content-Type': 'application/json', 'X-Checksum': 'token '+ checksum, 'X-Timestamp': time_stamp, 'X-AppKey': appkey, 'X-SessionToken': session_token } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Preview Order with Requests (Python) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Python script demonstrates how to preview an order and fetch brokerage details. It includes fetching a session token first and then making the preview order request. Ensure you have the 'requests' library installed. ```python import requests import json import hashlib from datetime import datetime, timezone customerDetail_url = "https://api.icicidirect.com/breezeapi/api/v1/customerdetails" secret_key = "Your Secret_key goes here" appkey = "Your App_Key goes here" session_key = "Your Session_key goes here" time_stamp = datetime.now(timezone.utc).isoformat()[:19] + '.000Z' customerDetail_payload = json.dumps({ "SessionToken": session_key, "AppKey": appkey }) customerDetail_headers = { 'Content-Type': 'application/json', } customerDetail_response = requests.request("GET", customerDetail_url, headers=customerDetail_headers, data=customerDetail_payload) data = json.loads(customerDetail_response.text) session_token = data["Success"]["session_token"] url = "https://api.icicidirect.com/breezeapi/api/v1/preview_order" payload = json.dumps({ "stock_code": "NIFTY", "exchange_code": "NFO", "product": "options", "order_type": "limit", "price": "0", "action": "buy", "quantity": "75", "expiry_date": "06-Mar-2025", "right": "call", "strike_price": "22500", "specialflag": "N", "stoploss": "", "order_rate_fresh": "0"}, separators=(',', ':')) checksum = hashlib.sha256((time_stamp+payload+secret_key).encode("utf-8")).hexdigest() headers = { 'Content-Type': 'application/json', 'X-Checksum': 'token '+ checksum, 'X-Timestamp': time_stamp, 'X-AppKey': appkey, 'X-SessionToken': session_token } response = requests.request("GET", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Preview Order using Java and OkHttpClient Source: https://api.icicidirect.com/breezeapi/documents/index.html This Java code snippet shows how to preview an order using OkHttpClient. It sets up the request with the necessary URL and headers. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://uatapi.icicidirect.com/iciciDirectWebApi_core/api/v1/preview_order") .method("GET", null) .addHeader("Content-Type", "application/json") .addHeader("X-Checksum", "token ") .addHeader("X-Timestamp", "") .addHeader("X-AppKey", "") .addHeader("X-SessionToken", "") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Make a GET Request (RestSharp) Source: https://api.icicidirect.com/breezeapi/documents/index.html Example of making a GET request to the BreezeAPI using RestSharp. ```APIDOC ## Make a GET Request (RestSharp) ### Description This example demonstrates how to make a GET request to the BreezeAPI using the RestSharp library in C#. ### Method GET ### Endpoint `https://breezeapi.icicidirect.com` ### Headers - **User-Agent**: XYZABC - **user**: LZLAL - **token**: 12i299 ### Request Example ```csharp var client = new RestClient("https://breezeapi.icicidirect.com"); client.Timeout = -1; var request = new RestRequest(Method.GET); client.UserAgent = "XYZABC"; request.AddHeader("user", "LZLAL"); request.AddHeader("token", "12i299"); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` ``` -------------------------------- ### Python Example using SocketIO Source: https://api.icicidirect.com/breezeapi/documents/index.html This snippet demonstrates how to connect to the Oneclick Equity Strategy using Python's socketio client to subscribe to market data. ```APIDOC ## Oneclick Equity Strategy (i_click_2_gain) - Python SocketIO ### Description This section provides a Python example using the `socketio` library to establish a WebSocket connection for real-time market data related to the 'i_click_2_gain' strategy. ### Authentication Requires a `session_key` to derive `user_id` and `session_token` for authentication. ### Connection - **URL**: `https://livefeeds.icicidirect.com` - **Transports**: `websocket` - **Headers**: `User-Agent: python-socketio[client]/socket` - **Auth**: `{"user": user_id, "token": session_token}` ### Subscription - **Script Code**: `["i_click_2_gain"]` ### Code Example ```python import base64 import socketio from datetime import datetime # Get User ID and Session Token session_key = "SESSION_TOKEN_FROM_CUSTOMER_DETAILS_API" # e.g. "QUYyOTUzMTM6NjY5ODc5NzY=" user_id, session_token = base64.b64decode(session_key.encode('ascii')).decode('ascii').split(":") # Python Socket IO Client sio = socketio.Client() script_code = ["i_click_2_gain"] # Subscribe more than one stock at a time auth = {"user": user_id, "token": session_token} sio.connect("https://livefeeds.icicidirect.com", headers={"User-Agent":"python-socketio[client]/socket"}, auth=auth, transports="websocket", wait_timeout=3) if sio.connected: print("Connection established successfully!") else: print("Failed to connect.") # Helper function to parse market depth (example) def parse_market_depth(data, exchange): depth = [] counter = 0 for lis in data: counter += 1 dict = {} if exchange == '1': dict["BestBuyRate-"+str(counter)] = lis[0] dict["BestBuyQty-"+str(counter)] = lis[1] dict["BestSellRate-"+str(counter)] = lis[2] dict["BestSellQty-"+str(counter)] = lis[3] depth.append(dict) else: dict["BestBuyRate-"+str(counter)] = lis[0] dict["BestBuyQty-"+str(counter)] = lis[1] dict["BuyNoOfOrders-"+str(counter)] = lis[2] dict["BuyFlag-"+str(counter)] = lis[3] dict["BestSellRate-"+str(counter)] = lis[4] dict["BestSellQty-"+str(counter)] = lis[5] dict["SellNoOfOrders-"+str(counter)] = lis[6] dict["SellFlag-"+str(counter)] = lis[7] depth.append(dict) return depth # Example of how to use the helper function (assuming 'market_data' and 'exchange_type' are received) # parsed_depth = parse_market_depth(market_data, exchange_type) ``` ``` -------------------------------- ### Preview Order using Python and Requests Source: https://api.icicidirect.com/breezeapi/documents/index.html This Python script demonstrates how to preview an order. It first fetches a session token and then constructs the request with necessary headers and payload. Ensure you have the 'requests' library installed. ```python import requests import json import hashlib from datetime import datetime, timezone customerDetail_url = "https://api.icicidirect.com/breezeapi/api/v1/customerdetails" secret_key = "Your Secret_key goes here" appkey = "Your App_Key goes here" session_key = "Your Session_key goes here" time_stamp = datetime.now(timezone.utc).isoformat()[:19] + '.000Z' customerDetail_payload = json.dumps({ "SessionToken": session_key, "AppKey": appkey }) customerDetail_headers = { 'Content-Type': 'application/json', } customerDetail_response = requests.request("GET", customerDetail_url, headers=customerDetail_headers, data=customerDetail_payload) data = json.loads(customerDetail_response.text) session_token = data["Success"]["session_token"] url = "https://api.icicidirect.com/breezeapi/api/v1/preview_order" payload = json.dumps({ "stock_code": "ICIBAN", "exchange_code": "NSE", "product": "", "order_type": "limit", "price": "907.05", "action": "buy", "quantity": "1", "specialflag": "N"}, separators=(',', ':')) checksum = hashlib.sha256((time_stamp+payload+secret_key).encode("utf-8")).hexdigest() headers = { 'Content-Type': 'application/json', 'X-Checksum': 'token '+ checksum, 'X-Timestamp': time_stamp, 'X-AppKey': appkey, 'X-SessionToken': session_token } response = requests.request("GET", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Get Demat Holdings with C# (RestSharp) Source: https://api.icicidirect.com/breezeapi/documents/index.html Utilize RestSharp in C# to make a GET request for demat holdings. This example demonstrates setting up the client, request, and headers. ```csharp var client = new RestClient("https://api.icicidirect.com/breezeapi/api/v1/dematholdings"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AddHeader("Content-Type", "application/json"); request.AddHeader("X-Checksum", "token "); request.AddHeader("X-Timestamp", ""); request.AddHeader("X-AppKey", ""); request.AddHeader("X-SessionToken", ""); var body = @"{{}}"; request.AddParameter("application/json", body, ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### SetFunds using C# (RestClient) Source: https://api.icicidirect.com/breezeapi/documents/index.html This C# example utilizes RestClient to interact with the SetFunds API. It demonstrates how to configure the request, including the request body and headers, and how to process the response. ```csharp var client = new RestClient("https://api.icicidirect.com/breezeapi/api/v1/funds"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddHeader("X-Checksum", "token "); request.AddHeader("X-Timestamp", ""); request.AddHeader("X-AppKey", ""); request.AddHeader("X-SessionToken", ""); var body = @"{ \"transaction_type\": \"Credit\", \"amount\": \"10000\", \"segment\": \"FNO\" }"; request.AddParameter("application/json", body, ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### SetFunds using Python (Requests) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Python script demonstrates how to set funds using the Requests library. It includes logic to fetch a session token and generate a checksum, which are crucial for authentication and request integrity. ```python import requests import json import hashlib from datetime import datetime, timezone customerDetail_url = "https://api.icicidirect.com/breezeapi/api/v1/customerdetails" secret_key = "Your Secret_key goes here" appkey = "Your App_Key goes here" session_key = "Your Session_key goes here", time_stamp = datetime.now(timezone.utc).isoformat()[:19] + '.000Z' customerDetail_payload = json.dumps({ "SessionToken": session_key, "AppKey": appkey }) customerDetail_headers = { 'Content-Type': 'application/json', } customerDetail_response = requests.request("GET", customerDetail_url, headers=customerDetail_headers, data=customerDetail_payload) data = json.loads(customerDetail_response.text) session_token = data["Success"]["session_token"] url = "https://api.icicidirect.com/breezeapi/api/v1/funds" payload = json.dumps({ "transaction_type": "credit", "amount": "200", "segment": "Equity" }, separators=(',', ':')) checksum = hashlib.sha256((time_stamp+payload+secret_key).encode("utf-8")).hexdigest() headers = { 'Content-Type': 'application/json', 'X-Checksum': 'token '+ checksum, 'X-Timestamp': time_stamp, 'X-AppKey': appkey, 'X-SessionToken': session_token } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Get Customer Details with RestSharp (C#) Source: https://api.icicidirect.com/breezeapi/documents/index.html A C# example using RestSharp to retrieve customer details. The request body is formatted as JSON, including the required SessionToken and AppKey. ```csharp var client = new RestClient("https://api.icicidirect.com/breezeapi/api/v1/customerdetails"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AddHeader("Content-Type", "application/json"); var body = @"{ "SessionToken": "58593", "AppKey": "8g791^N029R47I831B8153=^O2f#7u8g" }"; request.AddParameter("application/json", body, ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### Place a Cash Order using JavaScript (Node.js) Source: https://api.icicidirect.com/breezeapi/documents/index.html Use this snippet to place a cash order. Ensure you have axios installed. The 'X-Checksum', 'X-Timestamp', 'X-AppKey', and 'X-SessionToken' headers need to be populated with valid tokens. ```javascript var axios = require('axios'); var data = JSON.stringify({ "stock_code": "ITC", "exchange_code": "NSE", "product": "cash", "action": "buy", "order_type": "limit", "quantity": "1", "price": "263.15", "validity": "ioc" }); var config = { method: 'post', url: 'https://api.icicidirect.com/breezeapi/api/v1/order', headers: { 'Content-Type': 'application/json', 'X-Checksum': 'token ', 'X-Timestamp': '', 'X-AppKey': '', 'X-SessionToken': '' }, data : data }; axios(config) .then(function (response) { console.log(JSON.stringify(response.data)); }) .catch(function (error) { console.log(error); }); ``` -------------------------------- ### Get Trade Detail using Axios (Node.js) Source: https://api.icicidirect.com/breezeapi/documents/index.html Use this snippet to fetch trade details via the API using Axios in a Node.js environment. Ensure you have Axios installed. ```javascript var axios = require('axios'); var data = JSON.stringify({ "exchange_code": "NSE", "order_id": "20210928N100000067" }); var config = { method: 'get', url: 'https://api.icicidirect.com/breezeapi/api/v1/trades', headers: { 'Content-Type': 'application/json', 'X-Checksum': 'token ', 'X-Timestamp': '', 'X-AppKey': '', 'X-SessionToken': '' }, data : data }; axios(config) .then(function (response) { console.log(JSON.stringify(response.data)); }) .catch(function (error) { console.log(error); }); ``` -------------------------------- ### Get Quotes using Axios (Node.js) Source: https://api.icicidirect.com/breezeapi/documents/index.html Use this snippet to fetch stock quotes with Axios in Node.js. Ensure you have the 'axios' package installed. The request requires specific headers including authentication tokens. ```javascript var axios = require('axios'); var data = JSON.stringify({ "stock_code": "CNXBAN", "exchange_code": "NFO", "expiry_date": "2022-05-26T06:00:00.000Z", "product_type": "Futures", "right": "Others", "strike_price": "0" }); var config = { method: 'get', url: 'https://api.icicidirect.com/breezeapi/api/v1/quotes', headers: { 'Content-Type': 'application/json', 'X-Checksum': 'token ', 'X-Timestamp': '', 'X-AppKey': '', 'X-SessionToken': '' }, data : data }; axios(config) .then(function (response) { console.log(JSON.stringify(response.data)); }) .catch(function (error) { console.log(error); }); ``` -------------------------------- ### Calculate Limit Price and Quantity (Java) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Java snippet demonstrates how to calculate the limit price and quantity using OkHttpClient. It sets up the request with JSON payload and necessary headers. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, "{ \r\n \"strike_price\": \"19200\", \r\n \"product_type\":\"\", \r\n \"expiry_date\": \"13-JUL-2023\",\r\n \"underlying\" : \"NIFTY\",\r\n \"exchange_code\":\"NFO\",\r\n \"order_flow\" :\"Buy\",\r\n \"stop_loss_trigger\":\"200.00\",\r\n \"option_type\":\"Call\",\r\n \"source_flag\" : \"P\",\r\n \"limit_rate\" : \"\",\r\n \"order_reference\":\"\",\r\n \"available_quantity\":\"\",\r\n \"market_type\":\"limit\",\r\n \"fresh_order_limit\":\"218.65\"\r\n}"); Request request = new Request.Builder() .url("https://api.icicidirect.com/breezeapi/api/v1/fnolmtpriceandqtycal") .method("POST", body) .addHeader("Content-Type", "application/json") .addHeader("X-Checksum", "token ") .addHeader("X-Timestamp", "") .addHeader("X-AppKey", "") .addHeader("X-SessionToken", "") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Place a Cash Order using Java (OkHttpClient) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Java code snippet uses OkHttpClient to place a cash order. Ensure you have the OkHttpClient library added to your project. The headers for 'X-Checksum', 'X-Timestamp', 'X-AppKey', and 'X-SessionToken' require valid values. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, "{\r\n \"stock_code\": \"ITC\",\r\n \"exchange_code\": \"NSE\",\r\n \"product\": \"cash\",\r\n \"action\": \"buy\",\r\n \"order_type\": \"limit\",\r\n \"quantity\": \"1\",\r\n \"price\": \"263.15\",\r\n \"validity\": \"ioc\"\r\n}"); Request request = new Request.Builder() .url("https://api.icicidirect.com/breezeapi/api/v1/order") .method("POST", body) .addHeader("Content-Type", "application/json") .addHeader("X-Checksum", "token ") .addHeader("X-Timestamp", "") .addHeader("X-AppKey", "") .addHeader("X-SessionToken", "") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Get Trade Detail using RestClient (C#) Source: https://api.icicidirect.com/breezeapi/documents/index.html This C# example utilizes RestClient to fetch trade details. It configures the request with appropriate headers and a JSON body containing exchange code and order ID. ```csharp var client = new RestClient("https://api.icicidirect.com/breezeapi/api/v1/trades"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AddHeader("Content-Type", "application/json"); request.AddHeader("X-Checksum", "token "); request.AddHeader("X-Timestamp", ""); request.AddHeader("X-AppKey", ""); request.AddHeader("X-SessionToken", ""); var body = @"{ "exchange_code": "NSE", "order_id": "20210928N100000067" }"; request.AddParameter("application/json", body, ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### Get Option Chain Data with C# (RestSharp) Source: https://api.icicidirect.com/breezeapi/documents/index.html This C# code uses the RestSharp library to call the OptionChain API. It configures the request with the appropriate method, URL, headers, and a JSON request body. Ensure RestSharp is installed in your project. ```csharp var client = new RestClient("https://api.icicidirect.com/breezeapi/api/v1/OptionChain"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AddHeader("Content-Type", "application/json"); request.AddHeader("X-Checksum", "token "); request.AddHeader("X-Timestamp", ""); request.AddHeader("X-AppKey", ""); request.AddHeader("X-SessionToken", ""); var body = @"{ "stock_code": "NIFTY", "exchange_code": "NFO", "expiry_date": "2022-08-25T06:00:00.000Z", "product_type": "Futures", "right": "", "strike_price": "" }"; request.AddParameter("application/json", body, ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### Get Demat Holdings with Python (requests) Source: https://api.icicidirect.com/breezeapi/documents/index.html Fetch demat holdings using the requests library in Python. This example first retrieves a session token from customer details and then constructs the necessary headers, including a SHA256 checksum, for the demat holdings request. ```python import requests import json import hashlib from datetime import datetime, timezone customerDetail_url = "https://api.icicidirect.com/breezeapi/api/v1/customerdetails" secret_key = "Your Secret_key goes here" appkey = "Your App_Key goes here" session_key = "Your Session_key goes here" time_stamp = datetime.now(timezone.utc).isoformat()[:19] + '.000Z' customerDetail_payload = json.dumps({ "SessionToken": session_key, "AppKey": appkey }) customerDetail_headers = { 'Content-Type': 'application/json', } customerDetail_response = requests.request("GET", customerDetail_url, headers=customerDetail_headers, data=customerDetail_payload) data = json.loads(customerDetail_response.text) session_token = data["Success"]["session_token"] url = "https://api.icicidirect.com/breezeapi/api/v1/dematholdings" payload = json.dumps({}) checksum = hashlib.sha256((time_stamp+payload+secret_key).encode("utf-8")).hexdigest() headers = { 'Content-Type': 'application/json', 'X-Checksum': 'token '+ checksum, 'X-Timestamp': time_stamp, 'X-AppKey': appkey, 'X-SessionToken': session_token } response = requests.request("GET", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Place a Cash Order using C# (RestSharp) Source: https://api.icicidirect.com/breezeapi/documents/index.html This C# example uses the RestSharp library to place a cash order. The JSON payload is constructed with explicit newlines. Remember to populate the 'X-Checksum', 'X-Timestamp', 'X-AppKey', and 'X-SessionToken' headers. ```csharp var client = new RestClient("https://api.icicidirect.com/breezeapi/api/v1/order"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddHeader("X-Checksum", "token "); request.AddHeader("X-Timestamp", ""); request.AddHeader("X-AppKey", ""); request.AddHeader("X-SessionToken", ""); var body = @"{ " + "\n" + @ ``` -------------------------------- ### Get Option Chain Data with Java (OkHttpClient) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Java snippet shows how to make a GET request to the OptionChain API using OkHttpClient. It sets the necessary headers and URL. Note that the request body is null for a GET request. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://api.icicidirect.com/breezeapi/api/v1/OptionChain") .method("GET", null) .addHeader("Content-Type", "application/json") .addHeader("X-Checksum", "token ") .addHeader("X-Timestamp", "") .addHeader("X-AppKey", "") .addHeader("X-SessionToken", "") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### SetFunds using Java (OkHttpClient) Source: https://api.icicidirect.com/breezeapi/documents/index.html This Java code snippet shows how to make a POST request to the SetFunds API using OkHttpClient. It details setting up the request body, headers, and executing the request. ```java OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, "{\r\n \"transaction_type\": \"Credit\",\r\n \"amount\": \"10000\",\r\n \"segment\": \"FNO\"\r\n}"); Request request = new Request.Builder() .url("https://api.icicidirect.com/breezeapi/api/v1/funds") .method("POST", body) .addHeader("Content-Type", "application/json") .addHeader("X-Checksum", "token ") .addHeader("X-Timestamp", "") .addHeader("X-AppKey", "") .addHeader("X-SessionToken", "") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Preview Order using Node.js and Axios Source: https://api.icicidirect.com/breezeapi/documents/index.html Use this snippet to preview an order with specified parameters. Ensure you have Axios installed. The request includes headers for authentication and content type. ```javascript var axios = require('axios'); var data = JSON.stringify({ "stock_code": "ICIBAN", "exchange_code": "NSE", "product": "", "order_type": "limit", "price": "907.05", "action": "buy", "quantity": "1", "specialflag": "N" }); var config = { method: 'get', url: 'https://uatapi.icicidirect.com/iciciDirectWebApi_core/api/v1/preview_order', headers: { 'Content-Type': 'application/json', 'X-Checksum': 'token ', 'X-Timestamp': '', 'X-AppKey': '', 'X-SessionToken': '' }, data : data }; axios(config) .then(function (response) { console.log(JSON.stringify(response.data)); }) .catch(function (error) { console.log(error); }); ```