Brokerages

Oanda

Introduction

QuantConnect enables you to run your algorithms in live mode with real-time market data. We have successfully hosted more than 200,000 live algorithms and have had more than $15B in volume traded on our servers since 2015. Brokerages supply a connection to the exchanges so that you can automate orders using LEAN. You can use multiple data feeds in live trading algorithms.

Oanda was founded by Dr. Michael Stumm and Dr. Richard Olsen in 1995 with the goal to "transform all aspects of how the world interacts with currencies, whether that be trading or utilizing currency data and information". Oanda provides access to trading Forex and CFDs for clients in over 240 countries and territories with no minimum deposit. Oanda also provides demo accounts, advanced charting tools, and educational content

To view the implementation of the Oanda brokerage integration, see the Lean.Brokerages.OANDA repository.

Account Types

Oanda supports cash and margin accounts.

SetBrokerageModel(BrokerageName.OandaBrokerage, AccountType.Cash);
SetBrokerageModel(BrokerageName.OandaBrokerage, AccountType.Margin);
self.SetBrokerageModel(BrokerageName.OandaBrokerage, AccountType.Cash)
self.SetBrokerageModel(BrokerageName.OandaBrokerage, AccountType.Margin)

Create an Account

Follow the How to open an account page on the Oanda website to open an Oanda account.

You will need your account number and access token to deploy live algorithms. To get your account number, open the Account Statement page on the Oanda website. Your account number is formatted as ###-###-######-###. To get your access token, open the Manage API Access on the Oanda website.

Paper Trading

Oanda supports paper trading. Follow these steps to set up an Oanda paper trading account:

  1. Create an Oanda demo account.
  2. Log in to your demo account.
  3. On the Account page, in the My Services section, click Manage API Access.
  4. On the Your key to OANDA's API page, click Generate.
  5. Your access token displays. Store it somewhere safe. You need your access token to deploy an algorithm with your paper trading account.

  6. In the top navigation bar, click My Account.
  7. On the Account page, in the Manage Funds section, click View.
  8. On the My Funds page, in the Account Summary section, note your v20 Account Number.
  9. You need your v20 Account Number to deploy an algorithm with your paper trading account.

Asset Classes

Oanda supports trading Forex and CFDs.

AddForex("EURUSD", Resolution.Minute, Market.Oanda);

AddCfd("AU200AUD", Resolution.Minute, Market.Oanda);
self.AddForex("EURUSD", Resolution.Minute, Market.Oanda)

self.AddCfd("AU200AUD", Resolution.Minute, Market.Oanda)

If you call the SetBrokerageModel method with the correct BrokerageName, then you don't need to pass a Market argument to the method calls above because the brokerage model has default markets.

Assets Available

Refer to the dataset listing of the asset class you are trading to see the assets available. The following table shows the dataset listing of each asset class Oanda supports:

Asset ClassDataset Listing
ForexFOREX Data
CFDCFD Data

Orders

We model the Oanda API by supporting several order types, a TimeInForce order instruction, and order updates. When you deploy live algorithms, you can place manual orders through the IDE.

Order Types

The following table describes the available order types for each asset class that Oanda supports:

Order TypeForexCFD
MarketOrdergreen checkgreen check
LimitOrdergreen checkgreen check
StopMarketOrdergreen checkgreen check
MarketOrder(_symbol, quantity);
LimitOrder(_symbol, quantity, limitPrice);
StopMarketOrder(_symbol, quantity, stopPrice);
self.MarketOrder(self.symbol, quantity)
self.LimitOrder(self.symbol, quantity, limit_price)
self.StopMarketOrder(self.symbol, quantity, stop_price)

Time In Force

We model the GoodTilCanceled TimeInForce from the Oanda API.

DefaultOrderProperties.TimeInForce = TimeInForce.GoodTilCanceled;
LimitOrder(_symbol, quantity, limitPrice);
self.DefaultOrderProperties.TimeInForce = TimeInForce.GoodTilCanceled
self.LimitOrder(self.symbol, quantity, limit_price)

Updates

We model the Oanda API by supporting order updates. You can define the following members of an UpdateOrderFields object to update active orders:

  • Quantity
  • LimitPrice
  • StopPrice
  • Tag
var ticket = LimitOrder(symbol, quantity, limitPrice, tag);
var orderFields = new UpdateOrderFields { 
Quantity = newQuantity,
LimitPrice = newLimitPrice,
Tag = newTag
}; ticket.Update(orderFields);
ticket = self.LimitOrder(symbol, quantity, limit_price, tag)
update_fields = UpdateOrderFields() update_fields.Quantity = new_quantity update_fields.LimitPrice = new_limit_price update_fields.Tag = new_tag ticket.Update(update_fields)

Fees

We model the order fees of Oanda, which are $0. To check the latest fees, see the Our Charges and Fees page on the Oanda website.

Margin

We model buying power and margin calls to ensure your algorithm stays within the margin requirements.

Buying Power

Oanda allows up to 50x leverage for margin accounts.

Margin Calls

Regulation T margin rules apply. When the amount of margin remaining in your portfolio drops below 5% of the total portfolio value, you receive a warning. When the amount of margin remaining in your portfolio drops to zero or goes negative, the portfolio sorts the generated margin call orders by their unrealized profit and executes each order synchronously until your portfolio is within the margin requirements.

Slippage

Orders through Oanda do not experience slippage in backtests. In paper trading and live trading, your orders may experience slippage.

Fills

We fill market orders immediately and completely in backtests. In live trading, if the quantity of your market orders exceeds the quantity available at the top of the order book, your orders are filled according to what is available in the order book.

Settlements

Trades settle immediately after the transaction.

security.SettlementModel = new ImmediateSettlementModel();
security.SettlementModel = ImmediateSettlementModel()

Security and Stability

Note the following security and stability aspects of our Oanda integration.

Account Credentials

When you deploy live algorithms with Oanda, we don't save your brokerage account credentials.

API Outages

We call the Oanda API to place live trades. Sometimes the API may be down. Check the Oanda status page to see if the API is currently working.

Deposits and Withdraws

You can deposit and withdraw cash from your brokerage account while you run an algorithm that's connected to the account. We sync the algorithm's cash holdings with the cash holdings in your brokerage account every day at 7:45 AM Eastern Time (ET).

Demo Algorithm

The following algorithm demonstrates the functionality of the Oanda brokerage:

Deploy Live Algorithms

You must have an available live trading node for each live trading algorithm you deploy.

Follow these steps to deploy a live algorithm:

  1. Open the project you want to deploy.
  2. Click the Deploy Live icon.
  3. On the Deploy Live page, click the Brokerage field and then click Oanda from the drop-down menu.
  4. Enter your Oanda account ID and access token.
  5. To get your account ID and access token, see the Create an Account section in the Account Types documentation. Your account details are not saved on QuantConnect.

  6. Click the Environment field and then click one of the environments.
  7. The following table shows the supported environments:

    EnvironmentDescription
    RealTrade real money with fxTrade
    DemoTrade paper money with fxTrade Practice
  8. Click the Node field and then click the live trading node that you want to use from the drop-down menu.
  9. (Optional) Set up notifications.
  10. Configure the Automatically restart algorithm setting.
  11. By enabling automatic restarts, the algorithm will use best efforts to restart the algorithm if it fails due to a runtime error. This can help improve the algorithm's resilience to temporary outages such as a brokerage API disconnection.

  12. Click Deploy.

The deployment process can take up to 5 minutes. When the algorithm deploys, the live results page displays. If you know your brokerage positions before you deployed, you can verify they have been loaded properly by checking your equity value in the runtime statistics, your cashbook holdings, and your position holdings.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: