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 $22B 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:
- Create an Oanda demo account.
- Log in to your demo account.
- On the Account page, in the My Services section, click .
- On the Your key to OANDA's API page, click .
- In the top navigation bar, click .
- On the Account page, in the Manage Funds section, click .
- On the My Funds page, in the Account Summary section, note your v20 Account Number.
Your access token displays. Store it somewhere safe. You need your access token to deploy an algorithm with your paper trading account.
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 Class | Dataset Listing |
---|---|
Forex | FOREX Data |
CFD | CFD 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 Type | Forex | CFD |
---|---|---|
MarketOrder | ![]() | ![]() |
LimitOrder | ![]() | ![]() |
StopMarketOrder | ![]() | ![]() |
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.
Security and Stability
When you deploy live algorithms with Oanda, we don't save your brokerage account credentials.
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.
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:
- Open the project you want to deploy.
- Click the
Deploy Live icon.
- On the Deploy Live page, click the Brokerage field and then click from the drop-down menu.
- Enter your Oanda account ID and access token.
- Click the Environment field and then click one of the environments.
- Click the Node field and then click the live trading node that you want to use from the drop-down menu.
- (Optional) Set up notifications.
- Configure the Automatically restart algorithm setting.
- Click .
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.
The following table shows the supported environments:
Environment | Description |
---|---|
Real | Trade real money with fxTrade |
Demo | Trade paper money with fxTrade Practice |
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.
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.