Jump to content
  • 0

Another error in fetching data.


Majoka

Question

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. 

Link to comment

1 answer to this question

Recommended Posts

  • 0

Judging from this code, you would query the non-existing endpoint "/sessionprices", which indeed does not exist, so the 404 is valid.

You need to create a /session first, then you can query price data.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • General Statistics

    • Total Topics
      22,982
    • Total Posts
      95,295
    • Total Members
      43,587
    • Most Online
      7,522
      10/06/21 10:53

    Newest Member
    aroyi
    Joined 22/09/23 03:49
  • Posts

    • Some indices in Asia saw a modest rebound, but the ASX200 and Nikkei continued to fall, following on from yet more heavy losses in the US. Stocks continue to take a battering from the realisation that the Fed would leave US rates at their current levels for a longer period than previously thought, leading to a reversal in equities and a resumption of the losses seen in the early part of September. Today's data is dominated by flash PMIs from around the globe, in the wake of a Bank of Japan statement that left policy unchanged and maintained its dovish outlook. While US futures have recovered slightly, European markets seem set for a choppy open.  
    • Howw? What's the cirteria? Sorry, I was out of the market because of my exam! 🥲
    • Tho whole thing is a big mess actually. SEC Vs crypto! A never ending rivalry! BlackRock, Fidelity, Invesco Spot BTC ETF Application Decisions All Delayed by SEC!   In my opinion, Bull market is coming faster with their arrival!
×
×
  • Create New...
us