Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Streaming Speed and/or Bid/Ask Spread #22

Open
4 tasks done
AlexCatarino opened this issue Dec 20, 2024 · 0 comments
Open
4 tasks done

Data Streaming Speed and/or Bid/Ask Spread #22

AlexCatarino opened this issue Dec 20, 2024 · 0 comments

Comments

@AlexCatarino
Copy link
Member

Expected Behavior

The bid/ask spread is 50 pips.

Actual Behavior

The bid/ask spread is 300 pips.

Captura de ecrã 2024-12-20 151450

Potential Solution

N/A

Reproducing the Problem

Live algorithm that subscribes to tick data:

    def initialize(self):
        self.xauusd = self.add_cfd("XAUUSD", Resolution.TICK, market = Market.OANDA).symbol
    def on_data(self, data: Slice):        
        if data.Ticks.ContainsKey(self.xauusd):
            ticks = data.Ticks[self.xauusd]
            for tick in ticks:
                spread = tick.AskPrice - tick.BidPrice
                self.Debug(f"Time: {self.Time}, Price: {tick.Price}, Ask: {tick.AskPrice}, Bid: {tick.BidPrice}, Spread: {spread}")

Using the following script, we get 50 pips.

import oandapyV20
import oandapyV20.endpoints.pricing as pricing

# Replace with your OANDA API key and account ID
API_KEY = ""
ACCOUNT_ID = ""

# Initialize the API client
client = oandapyV20.API(access_token=API_KEY)

# Define the instrument for XAU/USD
instrument = "XAU_USD"

try:
    # Create a pricing endpoint request
    params = {"instruments": instrument}
    request = pricing.PricingInfo(accountID=ACCOUNT_ID, params=params)
    
    # Send the request and receive the response
    response = client.request(request)
    
    # Extract the bid and ask prices
    prices = response.get("prices", [])
    for price in prices:
        if price["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}")
            break
    else:
        print(f"Instrument {instrument} not found in the response.")
except Exception as e:
    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant