You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importoandapyV20importoandapyV20.endpoints.pricingaspricing# Replace with your OANDA API key and account IDAPI_KEY=""ACCOUNT_ID=""# Initialize the API clientclient=oandapyV20.API(access_token=API_KEY)
# Define the instrument for XAU/USDinstrument="XAU_USD"try:
# Create a pricing endpoint requestparams= {"instruments": instrument}
request=pricing.PricingInfo(accountID=ACCOUNT_ID, params=params)
# Send the request and receive the responseresponse=client.request(request)
# Extract the bid and ask pricesprices=response.get("prices", [])
forpriceinprices:
ifprice["instrument"] ==instrument:
bid=price.get("bids", [{}])[0].get("price")
ask=price.get("asks", [{}])[0].get("price")
print(f"XAU/USD Bid Price: {bid}")
print(f"XAU/USD Ask Price: {ask}")
spread=float(ask)-float(bid)
print(f"Spread: {spread}")
breakelse:
print(f"Instrument {instrument} not found in the response.")
exceptExceptionase:
print(f"An error occurred: {e}")
System Information
QuantConnect Clous using QuantConnect or OANDA as data provider.
Checklist
I have completely filled out this template
I have confirmed that this issue exists on the current master branch
I have confirmed that this is not a duplicate issue by searching issues
I have provided detailed steps to reproduce the issue
The text was updated successfully, but these errors were encountered:
Expected Behavior
The bid/ask spread is 50 pips.
Actual Behavior
The bid/ask spread is 300 pips.
Potential Solution
N/A
Reproducing the Problem
Live algorithm that subscribes to tick data:
Using the following script, we get 50 pips.
System Information
QuantConnect Clous using QuantConnect or OANDA as data provider.
Checklist
master
branchThe text was updated successfully, but these errors were encountered: