Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.

Fetch the Last Traded Price (LTP) using the ICICI Breeze API

Last updated on 1 month ago
C
caaSuper Admin
Posted 1 month ago
To fetch the Last Traded Price (LTP) using the ICICI Breeze API, you would generally follow these steps:
1. Set Up Your Environment

Ensure you have Python installed and that you're ready to use the requests library for HTTP requests.
2. Obtain API Credentials

You'll need an API key and secret from ICICI Breeze. These are necessary to authenticate your requests.
3. Authentication

Authenticate your requests with the API key and secret.
4. Define the API Endpoint and Request Parameters

You will typically use an endpoint provided by the Breeze API to fetch market data like LTP.
C
caaSuper Admin
Posted 1 month ago
import requests

# Replace with your API credentials
api_key = 'YOUR_API_KEY'
api_secret = 'YOUR_API_SECRET'

# Base URL for Breeze API
base_url = 'https://api.icicidirect.com/breezeapi'

# Headers with API credentials
headers = {
'Content-Type': 'application/json',
'api-key': api_key,
'api-secret': api_secret
}

# Define the symbol you want to fetch the LTP for
symbol = 'RELIANCE' # Example: Reliance Industries

# Endpoint to fetch LTP (adjust the endpoint based on API documentation)
ltp_url = f'{base_url}/market/ltp'

# Parameters for the request
params = {
'symbol': symbol,
'exchange': 'NSE' # Specify the exchange, e.g., NSE or BSE
}
C
caaSuper Admin
Posted 1 month ago
5. Fetch the LTP

Make a GET request to fetch the LTP.

python

# Fetch the LTP
response = requests.get(ltp_url, headers=headers, params=params)

# Check the response
if response.status_code == 200:
ltp_data = response.json()
print("LTP:", ltp_data.get('ltp'))
else:
print("Failed to fetch LTP:", response.text)

6. Handle the Response

Parse the response to extract the LTP.

python

if response.status_code == 200:
ltp_data = response.json()
ltp = ltp_data['ltp'] # Adjust the key according to the actual response structure
print(f"LTP of {symbol}: {ltp}")
else:
print("Error fetching LTP:", response.text)
C
caaSuper Admin
Posted 1 month ago
Important Notes:

API Documentation: Always refer to the latest ICICI Breeze API documentation to ensure you're using the correct endpoints and parameters.
Error Handling: Implement error handling to manage potential issues, such as invalid symbols or network errors.
Rate Limits: Be aware of any rate limits imposed by the API to avoid throttling.
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.
Sign In
Not a member yet? Click here to register.
Forgot Password?
Users Online Now
Guests Online 2
Members Online 0

Total Members: 10
Newest Member: rain