OandaClient API

Note

OandaClient will look for OANDA_TOKEN in the enviroment variables if no token is passed

OandaClient

class async_v20.OandaClient(token=None, account_id=None, format_order_requests=False, max_transaction_history=100, rest_host='api-fxpractice.oanda.com', rest_port=443, rest_scheme='https', stream_host='stream-fxpractice.oanda.com', stream_port=None, stream_scheme='https', health_host='api-status.oanda.com', health_port=80, health_scheme='http', datetime_format='UNIX', rest_timeout=10, stream_timeout=60, max_requests_per_second=99, max_simultaneous_connections=10, debug=False)[source]

Bases: async_v20.interface.account.AccountInterface, async_v20.interface.instrument.InstrumentInterface, async_v20.interface.order.OrderInterface, async_v20.interface.position.PositionInterface, async_v20.interface.pricing.PricingInterface, async_v20.interface.trade.TradeInterface, async_v20.interface.transaction.TransactionInterface, async_v20.interface.user.UserInterface, async_v20.interface.health.HealthInterface

Create an API context for v20 access

Parameters:
  • token – User generated token from the online account configuration page
  • account_id – The account id the client will connect to. If None will default to the first account number returned by list_accounts()
  • format_order_requests – True=Format all OrderRequests in the context of the orders instrument. False=Do not format OrderRequests, raise InvalidOrderRequest for values outside of allowed range.
  • max_transaction_history – Maximum past transactions to store
  • rest_host – The hostname of the v20 REST server
  • rest_port – The port of the v20 REST server
  • stream_host – The hostname of the v20 REST server
  • stream_port – The port of the v20 REST server
  • rest_scheme – The scheme of the connection to rest server.
  • stream_scheme – The scheme of the connection to the stream server.
  • health_host – The hostname of the health API server
  • health_port – The port of the health server
  • health_scheme – The scheme of the connection for the health server.
  • datetime_format – The format to request when dealing with times
  • rest_timeout – The timeout to use when making a polling request with the v20 REST server
  • stream_timeout – Period to wait for an new json object during streaming
  • max_requests_per_second – Maximum HTTP requests sent per second
  • max_simultaneous_connections – Maximum concurrent HTTP requests
  • debug – Set to True to log debug messages.

Account

OandaClient.account()[source]

Get updated account

Returns:Account
OandaClient.list_accounts(self)

Get a list of all Accounts authorized for the provided token.

Returns:
status [200]
Response (accounts=( AccountProperties, …),)
OandaClient.get_account_details(self)

Get the full details for a single Account that a client has access to. Full pending Order, open Trade and open Position representations are provided.

Returns:
status [200]
Response (account= Account, lastTransactionID= TransactionID)
OandaClient.account_summary(self)

Get a summary for a single Account that a client has access to.

Returns:
status [200]
Response (account= AccountSummary, lastTransactionID= TransactionID)
OandaClient.account_instruments(self, instruments: Instruments= sentinel)

Get the list of tradeable instruments for the given Account. The list of tradeable instruments is dependent on the regulatory division that the Account is located in, thus should be the same for all Accounts owned by a single user.

Parameters:
  • instrumentsInstruments
  • of instruments to query specifically. (list) –
Returns:

status [200]

Response (instruments=( Instrument, …), lastTransactionID= TransactionID)

OandaClient.configure_account(self, alias: Alias= sentinel, margin_rate: DecimalNumber= sentinel)

Set the client-configurable portions of an Account.

Parameters:
  • aliasAlias Client-defined alias (name) for the Account
  • margin_rateDecimalNumber The string representation of a decimal number.
Returns:

status [200]

Response (clientConfigureTransaction= ClientConfigureTransaction, lastTransactionID= TransactionID)

status [400]

Response (clientConfigureRejectTransaction= ClientConfigureRejectTransaction, lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [403]

Response (clientConfigureRejectTransaction= ClientConfigureRejectTransaction, lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.account_changes(self, since_transaction_id: SinceTransactionID= sentinel)

Endpoint used to poll an Account for its current state and changes since a specified TransactionID.

Note

OandaClient will supply since_transaction_id if None is provided

Parameters:since_transaction_idSinceTransactionID ID of the Transaction to get Account changes since.
Returns:
status [200]
Response (changes= AccountChanges, state= AccountChangesState, lastTransactionID= TransactionID)

Instrument

OandaClient.get_candles(self, instrument: InstrumentName, price: PriceComponent=M, granularity: CandlestickGranularity=S5, count: Count= sentinel, from_time: FromTime= sentinel, to_time: ToTime= sentinel, smooth: Smooth=False, include_first_query: IncludeFirstQuery= sentinel, daily_alignment: DailyAlignment=17, alignment_timezone: AlignmentTimezone=America/New_York, weekly_alignment: WeeklyAlignment=Friday)

Fetch candlestick data for an instrument.

Parameters:
  • include_first_queryIncludeFirstQuery
  • instrumentInstrumentName Name of the Instrument
  • pricePriceComponent The Price component(s) to get candlestick data for. Can contain any combination of the characters “M” (midpoint candles) “B” (bid candles) and “A” (ask candles).
  • granularityCandlestickGranularity The granularity of the candlesticks to fetch
  • countCount The number of candlesticks to return in the reponse. Count should not be specified if both the start and end parameters are provided, as the time range combined with the graularity will determine the number of candlesticks to return.
  • from_timeFromTime The start of the time range to fetch candlesticks for.
  • to_timeToTime The end of the time range to fetch candlesticks for.
  • smoothSmooth A flag that controls whether the candlestick is “smoothed” or not. A smoothed candlestick uses the previous candle’s close price as its open price, while an unsmoothed candlestick uses the first price from its time range as its open price.
  • daily_alignmentDailyAlignment The hour of the day (in the specified timezone) to use for granularities that have daily alignments.
  • alignment_timezoneAlignmentTimezone The timezone to use for the dailyAlignment parameter. Candlesticks with daily alignment will be aligned to the dailyAlignment hour within the alignmentTimezone.
  • weekly_alignmentWeeklyAlignment The day of the week used for granularities that have weekly alignment.
Returns:

status [200]

Response (instrument= InstrumentName, granularity= CandlestickGranularity, candles=( Candlestick, …),)

OandaClient.get_order_book(self, instrument: InstrumentName, time: DateTime= sentinel)

Fetch a gzip compressed order book for an instrument

Parameters:
  • instrumentInstrumentName Name of the Instrument
  • timeDateTime The time of the snapshot to fetch. If not specified, then the most recent snapshot is fetched
Returns:

status [200]

Response (orderBook= OrderBook)

OandaClient.get_position_book(self, instrument: InstrumentName, time: DateTime= sentinel)

Fetch a gzip compressed order book for an instrument

Parameters:
  • instrumentInstrumentName Name of the Instrument
  • timeDateTime The time of the snapshot to fetch. If not specified, then the most recent snapshot is fetched
Returns:

status [200]

Response (positionBook= PositionBook)

Order

OandaClient.post_order(self, order_request: OrderRequest= sentinel)

Post an OrderRequest.

Parameters:order_requestOrderRequest or a class derived from OrderRequest
Returns:
status [201]
Response (orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderCancelTransaction= OrderCancelTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)
status [400]
Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)
status [401]
Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)
OandaClient.create_order(self, instrument: InstrumentName, units: DecimalNumber, type: OrderType=MARKET, trade_id: TradeID= sentinel, price: PriceValue= sentinel, client_trade_id: ClientID= sentinel, time_in_force: TimeInForce= sentinel, gtd_time: DateTime= sentinel, trigger_condition: OrderTriggerCondition= sentinel, client_extensions: ClientExtensions= sentinel, distance: PriceValue= sentinel, price_bound: PriceValue= sentinel, position_fill: OrderPositionFill= sentinel, take_profit_on_fill: TakeProfitDetails= sentinel, stop_loss_on_fill: StopLossDetails= sentinel, trailing_stop_loss_on_fill: TrailingStopLossDetails= sentinel, trade_client_extensions: ClientExtensions= sentinel)

create an OrderRequest

Parameters:
Returns:

status [201]

Response (orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderCancelTransaction= OrderCancelTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.list_orders(self, ids: Ids= sentinel, state: OrderStateFilter= sentinel, instrument: InstrumentName= sentinel, count: Count= sentinel, before_id: OrderID= sentinel)

Get a list of Orders for an Account

Parameters:
  • idsIds list of Order IDs to retrieve
  • stateOrderStateFilter The state to filter the requested Orders by
  • instrumentInstrumentName The instrument to filter the requested orders by
  • countCount The maximum number of Orders to return
  • before_idOrderID The maximum Order ID to return. If not provided the most recent Orders in the Account are returned
Returns:

status [200]

Response (orders=( Order, …), lastTransactionID= TransactionID)

OandaClient.list_pending_orders(self)

List all pending Orders

Returns:
status [200]
Response (orders=( Order, …), lastTransactionID= TransactionID)
OandaClient.get_order(self, order_specifier: OrderSpecifier= sentinel)

Get details for a single Order

Parameters:order_specifierOrderSpecifier The Order Specifier
Returns:
status [200]
Response (order= Order, lastTransactionID= TransactionID)
OandaClient.replace_order(self, order_specifier: OrderSpecifier= sentinel, order_request: OrderRequest= sentinel)

Replace an Order by simultaneously cancelling it and creating a replacement Order

Parameters:
Returns:

status [201]

Response (orderCancelTransaction= OrderCancelTransaction, orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, replacingOrderCancelTransaction= OrderCancelTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderCancelRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.cancel_order(self, order_specifier: OrderSpecifier= sentinel)

Cancel a pending Order

Parameters:order_specifierOrderSpecifier The Order Specifier
Returns:
status [200]
Response (orderCancelTransaction= OrderCancelTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)
status [400]
Response (orderCancelRejectTransaction= OrderCancelRejectTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)
OandaClient.set_client_extensions(self, order_specifier: OrderSpecifier= sentinel, client_extensions: ClientExtensions= sentinel, trade_client_extensions: TradeClientExtensions= sentinel)

Update the Client Extensions for an Order . Do not set, modify, or delete clientExtensions if your account is associated with MT4.

Parameters:
  • order_specifierOrderSpecifier The Order Specifier
  • client_extensionsClientExtensions The Client Extensions to update for the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
  • trade_client_extensionsTradeClientExtensions The Client Extensions to update for the Trade created when the Order is filled. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
Returns:

status [200]

Response (orderClientExtensionsModifyTransaction= OrderClientExtensionsModifyTransaction, lastTransactionID= TransactionID, relatedTransactionIDs=( TransactionID, …),)

status [400]

Response (orderClientExtensionsModifyRejectTransaction= OrderClientExtensionsModifyRejectTransaction, lastTransactionID= TransactionID, relatedTransactionIDs=( TransactionID, …), errorCode= str, errorMessage= str)

status [401]

Response (orderClientExtensionsModifyRejectTransaction= OrderClientExtensionsModifyRejectTransaction, lastTransactionID= TransactionID, relatedTransactionIDs=( TransactionID, …), errorCode= str, errorMessage= str)

OandaClient.market_order(self, instrument: InstrumentName, units: DecimalNumber, time_in_force: TimeInForce=FOK, price_bound: PriceValue= sentinel, position_fill: OrderPositionFill=DEFAULT, client_extensions: ClientExtensions= sentinel, take_profit_on_fill: TakeProfitDetails= sentinel, stop_loss_on_fill: StopLossDetails= sentinel, trailing_stop_loss_on_fill: TrailingStopLossDetails= sentinel, trade_client_extensions: ClientExtensions= sentinel)

Create a Market Order Request

Parameters:
  • instrumentInstrumentName The Market Order’s Instrument.
  • unitsUnit The quantity requested to be filled by the Market Order. A posititive number of units results in a long Order, and a negative number of units results in a short Order.
  • time_in_forceTimeInForce The time-in-force requested for the Market Order. Restricted to FOK or IOC for a MarketOrder.
  • price_boundPriceValue The worst price that the client is willing to have the Market Order filled at.
  • position_fillOrderPositionFill Specification of how Positions in the Account are modified when the Order is filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
  • take_profit_on_fillTakeProfitDetails TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s dependent Take Profit Order is modified directly through the Trade.
  • stop_loss_on_fillStopLossDetails StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent Stop Loss Order is modified directly through the Trade.
  • trailing_stop_loss_on_fillTrailingStopLossDetails TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
  • trade_client_extensionsClientExtensions Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderCancelTransaction= OrderCancelTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.limit_order(self, instrument: InstrumentName, units: DecimalNumber, price: PriceValue, time_in_force: TimeInForce=GTC, gtd_time: DateTime= sentinel, position_fill: OrderPositionFill=DEFAULT, trigger_condition: OrderTriggerCondition=DEFAULT, client_extensions: ClientExtensions= sentinel, take_profit_on_fill: TakeProfitDetails= sentinel, stop_loss_on_fill: StopLossDetails= sentinel, trailing_stop_loss_on_fill: TrailingStopLossDetails= sentinel, trade_client_extensions: ClientExtensions= sentinel)

Create a Limit Order

Parameters:
  • instrumentInstrumentName The Limit Order’s Instrument.
  • unitsUnit The quantity requested to be filled by the Limit Order. A posititive number of units results in a long Order, and a negative number of units results in a short Order.
  • pricePriceValue The price threshold specified for the Limit Order. The Limit Order will only be filled by a market price that is equal to or better than this price.
  • time_in_forceTimeInForce The time-in-force requested for the Limit Order.
  • gtd_timeDateTime The date/time when the Limit Order will be cancelled if its timeInForce is “GTD”.
  • position_fillOrderPositionFill Specification of how Positions in the Account are modified when the Order is filled.
  • trigger_conditionOrderTriggerCondition Specification of what component of a price should be used for comparison when determining if the Order should be filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
  • take_profit_on_fillTakeProfitDetails TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s dependent Take Profit Order is modified directly through the Trade.
  • stop_loss_on_fillStopLossDetails StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent Stop Loss Order is modified directly through the Trade.
  • trailing_stop_loss_on_fillTrailingStopLossDetails TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
  • trade_client_extensionsClientExtensions Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderCancelTransaction= OrderCancelTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.limit_replace_order(self, instrument: InstrumentName, order_specifier: OrderSpecifier, units: DecimalNumber, price: PriceValue, time_in_force: TimeInForce=GTC, gtd_time: DateTime= sentinel, position_fill: OrderPositionFill=DEFAULT, trigger_condition: OrderTriggerCondition=DEFAULT, client_extensions: ClientExtensions= sentinel, take_profit_on_fill: TakeProfitDetails= sentinel, stop_loss_on_fill: StopLossDetails= sentinel, trailing_stop_loss_on_fill: TrailingStopLossDetails= sentinel, trade_client_extensions: ClientExtensions= sentinel)

Replace a pending Limit Order

Parameters:
  • instrumentInstrumentName The Limit Order’s Instrument.
  • order_specifierOrderSpecifier The ID of the Limit Order to replace
  • unitsUnit The quantity requested to be filled by the Limit Order. A posititive number of units results in a long Order, and a negative number of units results in a short Order.
  • pricePriceValue The price threshold specified for the Limit Order. The Limit Order will only be filled by a market price that is equal to or better than this price.
  • time_in_forceTimeInForce The time-in-force requested for the Limit Order.
  • gtd_timeDateTime The date/time when the Limit Order will be cancelled if its timeInForce is “GTD”.
  • position_fillOrderPositionFill Specification of how Positions in the Account are modified when the Order is filled.
  • trigger_conditionOrderTriggerCondition Specification of what component of a price should be used for comparison when determining if the Order should be filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
  • take_profit_on_fillTakeProfitDetails TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s dependent Take Profit Order is modified directly through the Trade.
  • stop_loss_on_fillStopLossDetails StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent Stop Loss Order is modified directly through the Trade.
  • trailing_stop_loss_on_fillTrailingStopLossDetails TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
  • trade_client_extensionsClientExtensions Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCancelTransaction= OrderCancelTransaction, orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, replacingOrderCancelTransaction= OrderCancelTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderCancelRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.stop_order(self, instrument: InstrumentName, trade_id: TradeID, price: PriceValue, client_trade_id: ClientID= sentinel, time_in_force: TimeInForce=GTC, gtd_time: DateTime= sentinel, trigger_condition: OrderTriggerCondition=DEFAULT, client_extensions: ClientExtensions= sentinel)

Create a Stop Order

Parameters:
  • instrumentInstrumentName The StopOrder’s Instrument.
  • trade_idTradeID The ID of the Trade to close when the price threshold is breached.
  • client_trade_idTradeID The client ID of the Trade to be closed when the price threshold is breached.
  • pricePriceValue The price threshold specified for the StopLoss Order. The associated Trade will be closed by a market price that is equal to or worse than this threshold.
  • time_in_forceTimeInForce The time-in-force requested for the StopLoss Order. Restricted to “GTC”, “GFD” and “GTD” for StopLoss Orders.
  • gtd_timeDateTime The date/time when the StopLoss Order will be cancelled if its timeInForce is “GTD”.
  • trigger_conditionOrderTriggerCondition Specification of what component of a price should be used for comparison when determining if the Order should be filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderCancelTransaction= OrderCancelTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.stop_replace_order(self, instrument: InstrumentName, order_specifier: OrderSpecifier, units: DecimalNumber, price: PriceValue, price_bound: PriceValue= sentinel, time_in_force: TimeInForce=GTC, gtd_time: DateTime= sentinel, position_fill: OrderPositionFill=DEFAULT, trigger_condition: OrderTriggerCondition=DEFAULT, client_extensions: ClientExtensions= sentinel, take_profit_on_fill: TakeProfitDetails= sentinel, stop_loss_on_fill: StopLossDetails= sentinel, trailing_stop_loss_on_fill: TrailingStopLossDetails= sentinel, trade_client_extensions: ClientExtensions= sentinel)

Replace a pending Stop Order

Parameters:
  • instrumentInstrumentName The Stop Order’s Instrument.
  • order_specifierOrderSpecifier The ID of the Stop Order to replace
  • unitsUnit The quantity requested to be filled by the Stop Order. A posititive number of units results in a long Order, and a negative number of units results in a short Order.
  • pricePriceValue The price threshold specified for the Stop Order. The Stop Order will only be filled by a market price that is equal to or worse than this price.
  • price_boundPriceValue The worst market price that may be used to fill this Stop Order. If the market gaps and crosses through both the price and the priceBound, the Stop Order will be cancelled instead of being filled.
  • time_in_forceTimeInForce The time-in-force requested for the Stop Order.
  • gtd_timeDateTime The date/time when the Stop Order will be cancelled if its timeInForce is “GTD”.
  • position_fillOrderPositionFill Specification of how Positions in the Account are modified when the Order is filled.
  • trigger_conditionOrderTriggerCondition Specification of what component of a price should be used for comparison when determining if the Order should be filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
  • take_profit_on_fillTakeProfitDetails TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s dependent Take Profit Order is modified directly through the Trade.
  • stop_loss_on_fillStopLossDetails StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent Stop Loss Order is modified directly through the Trade.
  • trailing_stop_loss_on_fillTrailingStopLossDetails TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
  • trade_client_extensionsClientExtensions Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCancelTransaction= OrderCancelTransaction, orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, replacingOrderCancelTransaction= OrderCancelTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderCancelRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.market_if_touched_order(self, instrument: InstrumentName, units: DecimalNumber, price: PriceValue, price_bound: PriceValue= sentinel, time_in_force: TimeInForce=GTC, gtd_time: DateTime= sentinel, position_fill: OrderPositionFill=DEFAULT, trigger_condition: OrderTriggerCondition=DEFAULT, client_extensions: ClientExtensions= sentinel, take_profit_on_fill: TakeProfitDetails= sentinel, stop_loss_on_fill: StopLossDetails= sentinel, trailing_stop_loss_on_fill: TrailingStopLossDetails= sentinel, trade_client_extensions: ClientExtensions= sentinel)

Create a market if touched order

Parameters:
  • instrumentInstrumentName The MarketIfTouched Order’s Instrument.
  • unitsUnit The quantity requested to be filled by the MarketIfTouched Order. A posititive number of units results in a long Order, and a negative number of units results in a short Order.
  • pricePriceValue The price threshold specified for the MarketIfTouched Order. The MarketIfTouched Order will only be filled by a market price that crosses this price from the direction of the market price at the time when the Order was created (the initialMarketPrice). Depending on the value of the Order’s price and initialMarketPrice, the MarketIfTouchedOrder will behave like a Limit or a Stop Order.
  • price_boundPriceValue The worst market price that may be used to fill this MarketIfTouched Order.
  • time_in_forceTimeInForce The time-in-force requested for the MarketIfTouched Order. Restricted to “GTC”, “GFD” and “GTD” for MarketIfTouched Orders.
  • gtd_timeDateTime The date/time when the MarketIfTouched Order will be cancelled if its timeInForce is “GTD”.
  • position_fillOrderPositionFill Specification of how Positions in the Account are modified when the Order is filled.
  • trigger_conditionOrderTriggerCondition Specification of what component of a price should be used for comparison when determining if the Order should be filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
  • take_profit_on_fillTakeProfitDetails TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s dependent Take Profit Order is modified directly through the Trade.
  • stop_loss_on_fillStopLossDetails StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent Stop Loss Order is modified directly through the Trade.
  • trailing_stop_loss_on_fillTrailingStopLossDetails TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
  • trade_client_extensionsClientExtensions Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderCancelTransaction= OrderCancelTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.market_if_touched_replace_order(self, instrument: InstrumentName, order_specifier: OrderSpecifier, units: DecimalNumber, price: PriceValue, price_bound: PriceValue= sentinel, time_in_force: TimeInForce=GTC, gtd_time: DateTime= sentinel, position_fill: OrderPositionFill=DEFAULT, trigger_condition: OrderTriggerCondition=DEFAULT, client_extensions: ClientExtensions= sentinel, take_profit_on_fill: TakeProfitDetails= sentinel, stop_loss_on_fill: StopLossDetails= sentinel, trailing_stop_loss_on_fill: TrailingStopLossDetails= sentinel, trade_client_extensions: ClientExtensions= sentinel)

Replace a pending market if touched order

Parameters:
  • instrumentInstrumentName The MarketIfTouched Order’s Instrument.
  • order_specifierOrderSpecifier The ID of the MarketIfTouched Order to replace
  • unitsUnit The quantity requested to be filled by the MarketIfTouched Order. A posititive number of units results in a long Order, and a negative number of units results in a short Order.
  • pricePriceValue The price threshold specified for the MarketIfTouched Order. The MarketIfTouched Order will only be filled by a market price that crosses this price from the direction of the market price at the time when the Order was created (the initialMarketPrice). Depending on the value of the Order’s price and initialMarketPrice, the MarketIfTouchedOrder will behave like a Limit or a Stop Order.
  • price_boundPriceValue The worst market price that may be used to fill this MarketIfTouched Order.
  • time_in_forceTimeInForce The time-in-force requested for the MarketIfTouched Order. Restricted to “GTC”, “GFD” and “GTD” for MarketIfTouched Orders.
  • gtd_timeDateTime The date/time when the MarketIfTouched Order will be cancelled if its timeInForce is “GTD”.
  • position_fillOrderPositionFill Specification of how Positions in the Account are modified when the Order is filled.
  • trigger_conditionOrderTriggerCondition Specification of what component of a price should be used for comparison when determining if the Order should be filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
  • take_profit_on_fillTakeProfitDetails TakeProfitDetails specifies the details of a Take Profit Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Take Profit, or when a Trade’s dependent Take Profit Order is modified directly through the Trade.
  • stop_loss_on_fillStopLossDetails StopLossDetails specifies the details of a Stop Loss Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Stop Loss, or when a Trade’s dependent Stop Loss Order is modified directly through the Trade.
  • trailing_stop_loss_on_fillTrailingStopLossDetails TrailingStopLossDetails specifies the details of a Trailing Stop Loss Order to be created on behalf of a client. This may happen when an Order is filled that opens a Trade requiring a Trailing Stop Loss, or when a Trade’s dependent Trailing Stop Loss Order is modified directly through the Trade.
  • trade_client_extensionsClientExtensions Client Extensions to add to the Trade created when the Order is filled (if such a Trade is created). Do not set, modify, or delete tradeClientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCancelTransaction= OrderCancelTransaction, orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, replacingOrderCancelTransaction= OrderCancelTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderCancelRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.take_profit_order(self, instrument: InstrumentName, trade_id: TradeID, price: PriceValue, client_trade_id: ClientID= sentinel, time_in_force: TimeInForce=GTC, gtd_time: DateTime= sentinel, trigger_condition: OrderTriggerCondition=DEFAULT, client_extensions: ClientExtensions= sentinel)

Create a take profit order

Parameters:
  • instrumentInstrumentName The TakeProfitOrder’s Instrument.
  • trade_idTradeID The ID of the Trade to close when the price threshold is breached.
  • client_trade_idTradeID The client ID of the Trade to be closed when the price threshold is breached.
  • pricePriceValue The price threshold specified for the TakeProfit Order. The associated Trade will be closed by a market price that is equal to or better than this threshold.
  • time_in_forceTimeInForce The time-in-force requested for the TakeProfit Order. Restricted to “GTC”, “GFD” and “GTD” for TakeProfit Orders.
  • gtd_timeDateTime The date/time when the TakeProfit Order will be cancelled if its timeInForce is “GTD”.
  • trigger_conditionOrderTriggerCondition Specification of what component of a price should be used for comparison when determining if the Order should be filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderCancelTransaction= OrderCancelTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.take_profit_replace_order(self, instrument: InstrumentName, order_specifier: OrderSpecifier, trade_id: TradeID, price: PriceValue, client_trade_id: ClientID= sentinel, time_in_force: TimeInForce=GTC, gtd_time: DateTime= sentinel, trigger_condition: OrderTriggerCondition=DEFAULT, client_extensions: ClientExtensions= sentinel)

Replace a pending take profit order

Parameters:
  • instrumentInstrumentName The TakeProfitOrder’s Instrument.
  • order_specifierOrderSpecifier The ID of the Take Profit Order to replace
  • trade_idTradeID The ID of the Trade to close when the price threshold is breached.
  • client_trade_idTradeID The client ID of the Trade to be closed when the price threshold is breached.
  • pricePriceValue The price threshold specified for the TakeProfit Order. The associated Trade will be closed by a market price that is equal to or better than this threshold.
  • time_in_forceTimeInForce The time-in-force requested for the TakeProfit Order. Restricted to “GTC”, “GFD” and “GTD” for TakeProfit Orders.
  • gtd_timeDateTime The date/time when the TakeProfit Order will be cancelled if its timeInForce is “GTD”.
  • trigger_conditionOrderTriggerCondition Specification of what component of a price should be used for comparison when determining if the Order should be filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCancelTransaction= OrderCancelTransaction, orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, replacingOrderCancelTransaction= OrderCancelTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderCancelRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.stop_loss_order(self, instrument: InstrumentName, trade_id: TradeID, price: PriceValue, client_trade_id: ClientID= sentinel, time_in_force: TimeInForce=GTC, gtd_time: DateTime= sentinel, trigger_condition: OrderTriggerCondition=DEFAULT, client_extensions: ClientExtensions= sentinel)

Create a Stop Loss Order

Parameters:
  • instrumentInstrumentName The StopLossOrder’s Instrument.
  • trade_idTradeID The ID of the Trade to close when the price threshold is breached.
  • client_trade_idTradeID The client ID of the Trade to be closed when the price threshold is breached.
  • pricePriceValue The price threshold specified for the StopLoss Order. The associated Trade will be closed by a market price that is equal to or worse than this threshold.
  • time_in_forceTimeInForce The time-in-force requested for the StopLoss Order. Restricted to “GTC”, “GFD” and “GTD” for StopLoss Orders.
  • gtd_timeDateTime The date/time when the StopLoss Order will be cancelled if its timeInForce is “GTD”.
  • trigger_conditionOrderTriggerCondition Specification of what component of a price should be used for comparison when determining if the Order should be filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderCancelTransaction= OrderCancelTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.stop_loss_replace_order(self, instrument: InstrumentName, order_specifier: OrderSpecifier, trade_id: TradeID, price: PriceValue, client_trade_id: ClientID= sentinel, time_in_force: TimeInForce=GTC, gtd_time: DateTime= sentinel, trigger_condition: OrderTriggerCondition=DEFAULT, client_extensions: ClientExtensions= sentinel)

Replace a pending Stop Loss Order

Parameters:
  • instrumentInstrumentName The StopLossOrder’s Instrument.
  • order_specifierOrderSpecifier The ID of the Stop Loss Order to replace
  • trade_idTradeID The ID of the Trade to close when the price threshold is breached.
  • client_trade_idTradeID The client ID of the Trade to be closed when the price threshold is breached.
  • pricePriceValue The price threshold specified for the StopLoss Order. The associated Trade will be closed by a market price that is equal to or worse than this threshold.
  • time_in_forceTimeInForce The time-in-force requested for the StopLoss Order. Restricted to “GTC”, “GFD” and “GTD” for StopLoss Orders.
  • gtd_timeDateTime The date/time when the StopLoss Order will be cancelled if its timeInForce is “GTD”.
  • trigger_conditionOrderTriggerCondition Specification of what component of a price should be used for comparison when determining if the Order should be filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCancelTransaction= OrderCancelTransaction, orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, replacingOrderCancelTransaction= OrderCancelTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderCancelRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.trailing_stop_loss_order(self, instrument: InstrumentName, trade_id: TradeID, distance: PriceValue, client_trade_id: ClientID= sentinel, time_in_force: TimeInForce=GTC, gtd_time: DateTime= sentinel, trigger_condition: OrderTriggerCondition=DEFAULT, client_extensions: ClientExtensions= sentinel)

Create a Trailing Stop Loss Order

Parameters:
  • instrumentInstrumentName The TrailingStopLossOrder’s Instrument.
  • trade_idTradeID The ID of the Trade to close when the price threshold is breached.
  • client_trade_idTradeID The client ID of the Trade to be closed when the price threshold is breached.
  • distancePriceValue The price distance specified for the TrailingStopLoss Order.
  • time_in_forceTimeInForce The time-in-force requested for the TrailingStopLoss Order. Restricted to “GTC”, “GFD” and “GTD” for TrailingStopLoss Orders.
  • gtd_timeDateTime The date/time when the StopLoss Order will be cancelled if its timeInForce is “GTD”.
  • trigger_conditionOrderTriggerCondition Specification of what component of a price should be used for comparison when determining if the Order should be filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderCancelTransaction= OrderCancelTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

OandaClient.trailing_stop_loss_replace_order(self, instrument: InstrumentName, order_specifier: OrderSpecifier, trade_id: TradeID, distance: PriceValue, client_trade_id: ClientID= sentinel, time_in_force: TimeInForce=GTC, gtd_time: DateTime= sentinel, trigger_condition: OrderTriggerCondition=DEFAULT, client_extensions: ClientExtensions= sentinel)

Replace a pending Trailing Stop Loss Order

Parameters:
  • instrumentInstrumentName The TrailingStopLossOrder’s Instrument.
  • order_specifierOrderSpecifier The ID of the Take Profit Order to replace
  • trade_idTradeID The ID of the Trade to close when the price threshold is breached.
  • client_trade_idTradeID The client ID of the Trade to be closed when the price threshold is breached.
  • distancePriceValue The price distance specified for the TrailingStopLoss Order.
  • time_in_forceTimeInForce The time-in-force requested for the TrailingStopLoss Order. Restricted to “GTC”, “GFD” and “GTD” for TrailingStopLoss Orders.
  • gtd_timeDateTime The date/time when the StopLoss Order will be cancelled if its timeInForce is “GTD”.
  • trigger_conditionOrderTriggerCondition Specification of what component of a price should be used for comparison when determining if the Order should be filled.
  • client_extensionsClientExtensions The client extensions to add to the Order. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
Returns:

status [201]

Response (orderCancelTransaction= OrderCancelTransaction, orderCreateTransaction= Transaction, orderFillTransaction= OrderFillTransaction, orderReissueTransaction= Transaction, orderReissueRejectTransaction= Transaction, replacingOrderCancelTransaction= OrderCancelTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (orderCancelRejectTransaction= Transaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

Position

OandaClient.list_positions(self)

List all Positions for an Account. The Positions returned are for every instrument that has had a position during the lifetime of an the Account.

Returns:
status [200]
Response (positions=( Position, …), lastTransactionID= TransactionID)
OandaClient.list_open_positions(self)

List all open Positions for an Account. An open Position is a Position in an Account that currently has a Trade opened for it.

Returns:
status [200]
Response (positions=( Position, …), lastTransactionID= TransactionID)
OandaClient.get_position(self, instrument: InstrumentName= sentinel)

Get the details of a single Instrument’s Position in an Account. The Position may by open or not.

Parameters:instrumentInstrumentName Name of the Instrument
Returns:
status [200]
Response (position= Position, lastTransactionID= TransactionID)
OandaClient.close_position(self, instrument: InstrumentName= sentinel, long_units: LongUnits= sentinel, long_client_extensions: LongClientExtensions= sentinel, short_units: ShortUnits= sentinel, short_client_extensions: ShortClientExtensions= sentinel)

Closeout the open Position for a specific instrument in an Account.

Note

  • Either long_units or short_units MUST be specified.
  • Do NOT specify ALL for long_units or short_units if there are no units to close.
Parameters:
  • instrumentInstrumentName Name of the Instrument
  • long_unitsLongUnits Indication of how much of the long Position to closeout. Either the string “ALL”, the string “NONE”, or a DecimalNumber representing how many units of the long position to close using a PositionCloseout MarketOrder. The units specified must always be positive.
  • long_client_extensionsLongClientExtensions The client extensions to add to the MarketOrder used to close the long position.
  • short_unitsShortUnits Indication of how much of the short Position to closeout. Either the string “ALL”, the string “NONE”, or a DecimalNumber representing how many units of the short position to close using a PositionCloseout MarketOrder. The units specified must always be positive.
  • short_client_extensionsShortClientExtensions The client extensions to add to the MarketOrder used to close the short position.
Returns:

status [200]

Response (longOrderCreateTransaction= MarketOrderTransaction, longOrderFillTransaction= OrderFillTransaction, longOrderCancelTransaction= OrderCancelTransaction, shortOrderCreateTransaction= MarketOrderTransaction, shortOrderFillTransaction= OrderFillTransaction, shortOrderCancelTransaction= OrderCancelTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (longOrderRejectTransaction= MarketOrderRejectTransaction, shortOrderRejectTransaction= MarketOrderRejectTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

status [401]

Response (longOrderRejectTransaction= MarketOrderRejectTransaction, shortOrderRejectTransaction= MarketOrderRejectTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID, errorCode= str, errorMessage= str)

Pricing

OandaClient.get_pricing(self, instruments: Instruments= sentinel, since: DateTime= sentinel)

Get pricing information for a specified list of Instruments within an Account.

Parameters:
  • instrumentsInstruments
  • of Instruments to get pricing for. (list) –
  • sinceDateTime Date/Time filter to apply to the returned prices. Only prices with a time later than this filter will be provided.
Returns:

status [200]

Response (prices=( Price, …), time= DateTime)

OandaClient.stream_pricing(self, instruments: Instruments= sentinel, snapshot: Snapshot= sentinel)

Get a stream of Account Prices starting from when the request is made. This pricing stream does not include every single price created for the Account, but instead will provide at most 4 prices per second (every 250 milliseconds) for each instrument being requested. If more than one price is created for an instrument during the 250 millisecond window, only the price in effect at the end of the window is sent. This means that during periods of rapid price movement, subscribers to this stream will not be sent every price. Pricing windows for different connections to the price stream are not all aligned in the same way (i.e. they are not all aligned to the top of the second). This means that during periods of rapid price movement, different subscribers may observe different prices depending on their alignment.

Parameters:
  • instrumentsInstruments
  • of Instruments to stream Prices for. (list) –
  • snapshotSnapshot Flag that enables/disables the sending of a pricing snapshot when initially connecting to the stream.
Returns:

status [200]

Response (price= Price)

OR

Response (heartbeat= PricingHeartbeat)

Trade

OandaClient.list_trades(self, ids: Ids= sentinel, state: TradeStateFilter= sentinel, instrument: InstrumentName= sentinel, count: Count= sentinel, trade_id: TradeID= sentinel)

Get a list of Trades for an Account

Parameters:
  • idsIds List of Trade IDs to retrieve.
  • stateTradeStateFilter The state to filter the requested Trades by.
  • instrumentInstrumentName The instrument to filter the requested Trades by.
  • countCount The maximum number of Trades to return.
  • trade_idTradeID The maximum Trade ID to return. If not provided the most recent Trades in the Account are returned.
Returns:

status [200]

Response (trades=( Trade, …), lastTransactionID= TransactionID)

OandaClient.list_open_trades(self)

Get the list of open Trades for an Account

Returns:
status [200]
Response (trades=( Trade, …), lastTransactionID= TransactionID)
OandaClient.get_trade(self, trade_specifier: TradeSpecifier= sentinel)

Get the details of a specific Trade in an Account

Parameters:trade_specifierTradeSpecifier Specifier for the Trade
Returns:
status [200]
Response (trade= Trade, lastTransactionID= TransactionID)
OandaClient.close_trade(self, trade_specifier: TradeSpecifier= sentinel, units: Units= sentinel)

Close (partially or fully) a specific open Trade in an Account

Parameters:
  • trade_specifierTradeSpecifier Specifier for the Trade
  • unitsUnits Indication of how much of the Trade to close. Either the string “ALL” (indicating that all of the Trade should be closed), or a DecimalNumber representing the number of units of the open Trade to Close using a TradeClose MarketOrder. The units specified must always be positive, and the magnitude of the value cannot exceed the magnitude of the Trade’s open units.
Returns:

status [200]

Response (orderCreateTransaction= MarketOrderTransaction, orderFillTransaction= OrderFillTransaction, orderCancelTransaction= OrderCancelTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (orderRejectTransaction= MarketOrderRejectTransaction, errorCode= str, errorMessage= str)

status [401]

Response (orderRejectTransaction= MarketOrderRejectTransaction, lastTransactionID= TransactionID, relatedTransactionIDs=( TransactionID, …), errorCode= str, errorMessage= str)

OandaClient.close_all_trades()[source]

Close all open trades

Returns:class`~async_v20.interface.response.Response`, …])
Return type:tuple (bool, [
OandaClient.set_client_extensions_trade(self, trade_specifier: TradeSpecifier= sentinel, client_extensions: ClientExtensions= sentinel)

Update the Client Extensions for a Trade. Do not add, update, or delete the Client Extensions if your account is associated with MT4.

Parameters:
  • trade_specifierTradeSpecifier Specifier for the Trade
  • client_extensionsClientExtensions The Client Extensions to update the Trade with. Do not add, update, or delete the Client Extensions if your account is associated with MT4.
Returns:

status [200]

Response (tradeClientExtensionsModifyTransaction= TradeClientExtensionsModifyTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (tradeClientExtensionsModifyRejectTransaction= TradeClientExtensionsModifyRejectTransaction, lastTransactionID= TransactionID, relatedTransactionIDs=( TransactionID, …), errorCode= str, errorMessage= str)

status [401]

Response (tradeClientExtensionsModifyRejectTransaction= TradeClientExtensionsModifyRejectTransaction, lastTransactionID= TransactionID, relatedTransactionIDs=( TransactionID, …), errorCode= str, errorMessage= str)

OandaClient.set_dependent_orders_trade(self, trade_specifier: TradeSpecifier= sentinel, take_profit: TakeProfitDetails= sentinel, stop_loss: StopLossDetails= sentinel, trailing_stop_loss: TrailingStopLossDetails= sentinel)

Create, replace and cancel a Trade’s dependent Orders (Take Profit, Stop Loss and Trailing Stop Loss) through the Trade itself

Parameters:
  • trade_specifierTradeSpecifier Specifier for the Trade
  • take_profitTakeProfitDetails The specification of the Take Profit to create/modify/cancel. If takeProfit is set to null, the Take Profit Order will be cancelled if it exists. If takeProfit is not provided, the existing Take Profit Order will not be modified. If a sub- field of takeProfit is not specified, that field will be set to a default value on create, and be inherited by the replacing order on modify.
  • stop_lossStopLossDetails The specification of the Stop Loss to create/modify/cancel. If stopLoss is set to null, the Stop Loss Order will be cancelled if it exists. If stopLoss is not provided, the existing Stop Loss Order will not be modified. If a sub-field of stopLoss is not specified, that field will be set to a default value on create, and be inherited by the replacing order on modify.
  • trailing_stop_lossTrailingStopLossDetails The specification of the Trailing Stop Loss to create/modify/cancel. If trailingStopLoss is set to null, the Trailing Stop Loss Order will be cancelled if it exists. If trailingStopLoss is not provided, the existing Trailing Stop Loss Order will not be modified. If a sub-field of trailingStopLoss is not specified, that field will be set to a default value on create, and be inherited by the replacing order on modify.
Returns:

status [200]

Response (takeProfitOrderCancelTransaction= OrderCancelTransaction, takeProfitOrderTransaction= TakeProfitOrderTransaction, takeProfitOrderFillTransaction= OrderFillTransaction, takeProfitOrderCreatedCancelTransaction= OrderCancelTransaction, stopLossOrderCancelTransaction= OrderCancelTransaction, stopLossOrderTransaction= StopLossOrderTransaction, stopLossOrderFillTransaction= OrderFillTransaction, stopLossOrderCreatedCancelTransaction= OrderCancelTransaction, trailingStopLossOrderCancelTransaction= OrderCancelTransaction, trailingStopLossOrderTransaction= TrailingStopLossOrderTransaction, relatedTransactionIDs=( TransactionID, …), lastTransactionID= TransactionID)

status [400]

Response (takeProfitOrderCancelRejectTransaction= OrderCancelRejectTransaction, takeProfitOrderRejectTransaction= TakeProfitOrderRejectTransaction, stopLossOrderCancelRejectTransaction= OrderCancelRejectTransaction, stopLossOrderRejectTransaction= StopLossOrderRejectTransaction, trailingStopLossOrderCancelRejectTransaction= OrderCancelRejectTransaction, trailingStopLossOrderRejectTransaction= TrailingStopLossOrderRejectTransaction, lastTransactionID= TransactionID, relatedTransactionIDs=( TransactionID, …), errorCode= str, errorMessage= str)

Transaction

OandaClient.list_transactions(self, from_time: FromTime= sentinel, to_time: ToTime= sentinel, page_size: PageSize=100, type_: Type= sentinel)

Get a list of Transactions pages that satisfy a time-based Transaction query.

Parameters:
  • from_timeFromTime The starting time (inclusive) of the time range for the Transactions being queried.
  • to_timeToTime The ending time (inclusive) of the time range for the Transactions being queried.
  • page_sizePageSize The number of Transactions to include in each page of the results.
  • typeType A filter for restricting the types of Transactions to retrieve.
Returns:

status [200]

Response (from= DateTime, to= DateTime, pageSize= int, type=( TransactionFilter, …), count= int, pages=( str, …), lastTransactionID= TransactionID)

OandaClient.get_transaction(self, transaction_id: TransactionID)

Get the details of a single Account Transaction.

Parameters:transaction_idTransactionID A Transaction ID
Returns:
status [200]
Response (transaction= Transaction, lastTransactionID= TransactionID)
OandaClient.transaction_range(self, from_transaction: FromTransactionID, to_transaction: ToTransactionID, type_: Type= sentinel)

Get a range of Transactions for an Account based on the Transaction IDs.

Parameters:
  • from_transactionFromTransactionID The starting Transaction ID (inclusive) to fetch.
  • to_transactionToTransactionID The ending Transaction ID (inclusive) to fetch.
  • typeType The filter that restricts the types of Transactions to retrieve.
Returns:

status [200]

Response (transactions=( Transaction, …), lastTransactionID= TransactionID)

OandaClient.since_transaction(self, transaction_id: TransactionID= sentinel)

Get a range of Transactions for an Account starting at (but not including) a provided Transaction ID.

Parameters:transaction_idTransactionID The ID of the last Transaction fetched. This query will return all Transactions newer than the TransactionID.
Returns:
status [200]
Response (transactions=( Transaction, …), lastTransactionID= TransactionID)
OandaClient.stream_transactions(self)

Get a stream of Transactions for an Account starting from when the request is made.

Returns:
status [200]
Response (transaction= Transaction)

OR

Response (Heartbeat= TransactionHeartbeat)

User

OandaClient.get_user_info(self, user_specifier: UserSpecifier)

Fetch the user information for the specified user. This endpoint is intended to be used by the user thyself to obtain their own information.

Parameters:user_specifierUserSpecifier The User Specifier
Returns:
status [200]
Response (userInfo= UserInfo)
OandaClient.get_external_user_info(self, user_specifier: UserSpecifier)

Fetch the externally-available user information for the specified user. This endpoint is intended to be used by 3rd parties that have been authorized by a user to view their personal information.

Parameters:user_specifierUserSpecifier The User Specifier
Returns:
status [200]
Response (userInfo= UserInfoExternal)

Health

OandaClient.get_current_event(self, service_id: ServiceID)

Get the current event for a service

Parameters:service_idServiceID The service to get the current event for
Returns:
status [200]
Response (Event= Event)
OandaClient.get_event(self, service_id: ServiceID, event_sid: EventSid)

Get an individual event

Parameters:
  • service_idServiceID The service to event for
  • event_sidEventSid The event to get from the specified service
Returns:

status [200]

Response (Event= Event)

OandaClient.get_service(self, service_id: ServiceID)

Get a single service

Parameters:service_idServiceID Name of the service to get
Returns:
status [200]
Response (Service= Service)
OandaClient.get_service_list(self, service_list_id: ServiceListID)

Get a single service list

Parameters:service_list_idServiceListID The service list to get.
Returns:
status [200]
Response (lists= ServiceList)
OandaClient.get_status(self, status_id: StatusID)

Get an individual status

Parameters:status_idStatusID The status to get
Returns:
status [200]
Response (Status= Status)
OandaClient.list_events(self, service_id: ServiceID)

List all events for a service

Parameters:service_idServiceID The service to get events for.
Returns:
status [200]
Response (lists=( Event,…))
OandaClient.list_images(self)

List all status images

Returns:
status [200]
Response (images=( Image, …))
OandaClient.list_service_lists(self)

List all service lists

Returns:
status [200]
Response (lists=( ServiceList, …))
OandaClient.list_services(self)

List all the services

Returns:
status [200]
Response (services=( Service, …))
OandaClient.list_statuses(self)

List all statuses

Returns:
status [200]
Response (statuses=( Event, …))