Hi, I have also tried the following Python code to extract data.
import requests
# Set your API credentials
api_key = "xx"
account_id = 'xx'
# Set the API endpoint and parameters
endpoint = 'https://demo-api.ig.com/gateway/deal/session'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-IG-API-KEY': api_key,
'Authorization': f'Bearer {account_id}',
}
params = {
'resolution': 'D', # Daily resolution
'epic': 'CS.D.BHP.LON.IP', # BHP market identifier
'pageSize': 10, # Number of prices to fetch
}
# Make the API request
response = requests.get(endpoint + 'prices', headers=headers, params=params)
# Check if the request was successful
if response.status_code == 200:
# Extract the close prices from the response
data = response.json()
close_prices = [price['closePrice'] for price in data['prices']]
print(close_prices)
else:
print('Error occurred:', response.text)
It gives me the following error message.
Error occurred: <html><head><title>Page Not Found</title><h3>Error 404</h3><h3>Sorry, the requested page is not available.</h3></body></html>
So basically, I am not sure how to extract price data via the API using Python.