oandapyV20.endpoints package¶
Submodules¶
oandapyV20.endpoints.apirequest module¶
Handling of API requests.
-
class
oandapyV20.endpoints.apirequest.
APIRequest
(endpoint, method='GET', expected_status=200)¶ Bases:
object
Base Class for API-request classes.
-
__init__
(endpoint, method='GET', expected_status=200)¶ Instantiate an API request.
Parameters: - endpoint (string) – the URL format string
- method (string) – the method for the request. Default: GET.
-
__str__
()¶ return the endpoint.
-
expected_status
¶
-
response
¶ response - get the response of the request.
-
status_code
¶
-
oandapyV20.endpoints.accounts module¶
Handle account endpoints.
-
class
oandapyV20.endpoints.accounts.
AccountChanges
(accountID, params=None)¶ Bases:
oandapyV20.endpoints.accounts.Accounts
AccountChanges.
Endpoint used to poll an Account for its current state and changes since a specified TransactionID.
-
ENDPOINT
= 'v3/accounts/{accountID}/changes'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, params=None)¶ Instantiate an AccountChanges request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- params (dict (optional)) – query params to send, check developer.oanda.com for details.
Query Params example:
{ "sinceTransactionID": 2308 }
>>> import oandapyV20 >>> import oandapyV20.endpoints.accounts as accounts >>> client = oandapyV20.API(access_token=...) >>> params = ... >>> r = accounts.AccountChanges(accountID=..., params=params) >>> client.request(r) >>> print r.response
Output:
{ "state": { "trades": [], "marginCloseoutNAV": "33848.2663", "marginUsed": "0.0000", "marginAvailable": "33848.2663", "marginCallPercent": "0.00000", "NAV": "33848.2663", "marginCloseoutMarginUsed": "0.0000", "orders": [], "withdrawalLimit": "33848.2663", "marginCloseoutPercent": "0.00000", "positions": [], "unrealizedPL": "0.0000", "marginCallMarginUsed": "0.0000", "marginCloseoutUnrealizedPL": "0.0000", "positionValue": "0.0000" }, "changes": { "tradesReduced": [], "tradesOpened": [], "ordersFilled": [], "tradesClosed": [], "transactions": [ { "price": "1.20000", "stopLossOnFill": { "timeInForce": "GTC", "price": "1.22000" }, "timeInForce": "GTC", "reason": "CLIENT_ORDER", "id": "2309", "batchID": "2309", "triggerCondition": "TRIGGER_DEFAULT", "positionFill": "DEFAULT", "userID": 1435156, "instrument": "EUR_USD", "time": "2016-10-25T21:07:21.065554321Z", "units": "-100", "type": "LIMIT_ORDER", "accountID": "101-004-1435156-001" } ], "ordersCreated": [ { "partialFill": "DEFAULT_FILL", "price": "1.20000", "stopLossOnFill": { "timeInForce": "GTC", "price": "1.22000" }, "timeInForce": "GTC", "createTime": "2016-10-25T21:07:21.065554321Z", "triggerCondition": "TRIGGER_DEFAULT", "positionFill": "POSITION_DEFAULT", "id": "2309", "instrument": "EUR_USD", "state": "PENDING", "units": "-100", "type": "LIMIT" } ], "positions": [], "ordersTriggered": [], "ordersCancelled": [] }, "lastTransactionID": "2309" }
-
-
class
oandapyV20.endpoints.accounts.
AccountConfiguration
(accountID, data)¶ Bases:
oandapyV20.endpoints.accounts.Accounts
Set the client-configurable portions of an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/configuration'¶
-
EXPECTED_STATUS
= 200¶
-
HEADERS
= {'Content-Type': 'application/json'}¶
-
METHOD
= 'PATCH'¶
-
__init__
(accountID, data)¶ Instantiate an AccountConfiguration request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- data (dict (required)) – json body to send
body example:
{ "marginRate": "0.05" }
>>> import oandapyV20 >>> import oandapyV20.endpoints.accounts as accounts >>> client = oandapyV20.API(access_token=...) >>> r = accounts.AccountConfiguration(accountID, data=data) >>> client.request(r) >>> print r.response
{ "lastTransactionID": "830", "clientConfigureTransaction": { "userID": 1435156, "marginRate": "0.05", "batchID": "830", "time": "2016-07-12T19:48:11.657494168Z", "type": "CLIENT_CONFIGURE", "id": "830", "accountID": "101-004-1435156-001" } }
-
-
class
oandapyV20.endpoints.accounts.
AccountDetails
(accountID)¶ Bases:
oandapyV20.endpoints.accounts.Accounts
AccountDetails.
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.
-
ENDPOINT
= 'v3/accounts/{accountID}'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID)¶ Instantiate an AccountDetails request.
Parameters: accountID (string (required)) – id of the account to perform the request on. >>> import oandapyV20 >>> import oandapyV20.endpoints.accounts as accounts >>> client = oandapyV20.API(access_token=...) >>> r = accounts.AccountDetails(accountID) >>> client.request(r) >>> print r.response
{ "account": { "marginCloseoutNAV": "35454.4740", "marginUsed": "10581.5000", "currency": "EUR", "resettablePL": "-13840.3525", "NAV": "35454.4740", "marginCloseoutMarginUsed": "10581.5000", "marginCloseoutPositionValue": "211630.0000", "openTradeCount": 2, "id": "101-004-1435156-001", "hedgingEnabled": false, "marginCloseoutPercent": "0.14923", "marginCallMarginUsed": "10581.5000", "openPositionCount": 1, "positionValue": "211630.0000", "pl": "-13840.3525", "lastTransactionID": "2123", "marginAvailable": "24872.9740", "marginRate": "0.05", "marginCallPercent": "0.29845", "pendingOrderCount": 0, "withdrawalLimit": "24872.9740", "unrealizedPL": "0.0000", "alias": "hootnotv20", "createdByUserID": 1435156, "marginCloseoutUnrealizedPL": "0.0000", "createdTime": "2016-06-24T21:03:50.914647476Z", "balance": "35454.4740" }, "lastTransactionID": "2123" }
-
-
class
oandapyV20.endpoints.accounts.
AccountInstruments
(accountID, params=None)¶ Bases:
oandapyV20.endpoints.accounts.Accounts
AccountInstruments.
Get the list of tradable 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.
-
ENDPOINT
= 'v3/accounts/{accountID}/instruments'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, params=None)¶ Instantiate an AccountInstruments request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- params (dict (optional)) – query params to send, check developer.oanda.com for details.
Query Params example:
{ "instruments": "EU50_EUR,EUR_USD,US30_USD,FR40_EUR,EUR_CHF,DE30_EUR" }
>>> import oandapyV20 >>> import oandapyV20.endpoints.accounts as accounts >>> client = oandapyV20.API(access_token=...) >>> params = ... >>> r = accounts.AccountInstruments(accountID=..., params=params) >>> client.request(r) >>> print r.response
Output:
{ "instruments": [ { "marginRate": "0.05", "minimumTrailingStopDistance": "5.0", "maximumPositionSize": "0", "minimumTradeSize": "1", "displayName": "Europe 50", "name": "EU50_EUR", "displayPrecision": 1, "maximumTrailingStopDistance": "10000.0", "maximumOrderUnits": "3000", "tradeUnitsPrecision": 0, "pipLocation": 0, "type": "CFD" }, { "marginRate": "0.05", "minimumTrailingStopDistance": "0.00050", "maximumPositionSize": "0", "minimumTradeSize": "1", "displayName": "EUR/USD", "name": "EUR_USD", "displayPrecision": 5, "maximumTrailingStopDistance": "1.00000", "maximumOrderUnits": "100000000", "tradeUnitsPrecision": 0, "pipLocation": -4, "type": "CURRENCY" }, { "marginRate": "0.05", "minimumTrailingStopDistance": "5.0", "maximumPositionSize": "0", "minimumTradeSize": "1", "displayName": "US Wall St 30", "name": "US30_USD", "displayPrecision": 1, "maximumTrailingStopDistance": "10000.0", "maximumOrderUnits": "1000", "tradeUnitsPrecision": 0, "pipLocation": 0, "type": "CFD" }, { "marginRate": "0.05", "minimumTrailingStopDistance": "5.0", "maximumPositionSize": "0", "minimumTradeSize": "1", "displayName": "France 40", "name": "FR40_EUR", "displayPrecision": 1, "maximumTrailingStopDistance": "10000.0", "maximumOrderUnits": "2000", "tradeUnitsPrecision": 0, "pipLocation": 0, "type": "CFD" }, { "marginRate": "0.05", "minimumTrailingStopDistance": "0.00050", "maximumPositionSize": "0", "minimumTradeSize": "1", "displayName": "EUR/CHF", "name": "EUR_CHF", "displayPrecision": 5, "maximumTrailingStopDistance": "1.00000", "maximumOrderUnits": "100000000", "tradeUnitsPrecision": 0, "pipLocation": -4, "type": "CURRENCY" }, { "marginRate": "0.05", "minimumTrailingStopDistance": "5.0", "maximumPositionSize": "0", "minimumTradeSize": "1", "displayName": "Germany 30", "name": "DE30_EUR", "displayPrecision": 1, "maximumTrailingStopDistance": "10000.0", "maximumOrderUnits": "2500", "tradeUnitsPrecision": 0, "pipLocation": 0, "type": "CFD" } ], "lastTransactionID": "2124" }
-
-
class
oandapyV20.endpoints.accounts.
AccountList
¶ Bases:
oandapyV20.endpoints.accounts.Accounts
Get a list of all Accounts authorized for the provided token.
-
ENDPOINT
= 'v3/accounts'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
()¶ Instantiate an AccountList request.
>>> import oandapyV20 >>> import oandapyV20.endpoints.accounts as accounts >>> client = oandapyV20.API(access_token=...) >>> r = accounts.AccountList() >>> client.request(r) >>> print r.response
{ "account": { "positions": [ { "short": { "units": "0", "resettablePL": "0.0000", "unrealizedPL": "0.0000", "pl": "0.0000" }, "unrealizedPL": "0.0000", "long": { "units": "0", "resettablePL": "-3.8046", "unrealizedPL": "0.0000", "pl": "-3.8046" }, "instrument": "EUR_USD", "resettablePL": "-3.8046", "pl": "-3.8046" }, { "short": { "unrealizedPL": "682.0000", "units": "-20", "resettablePL": "-1744.8000", "tradeIDs": [ "821", "823" ], "averagePrice": "9984.7", "pl": "-1744.8000" }, "unrealizedPL": "682.0000", "long": { "units": "0", "resettablePL": "447.6000", "unrealizedPL": "0.0000", "pl": "447.6000" }, "instrument": "DE30_EUR", "resettablePL": "-1297.2000", "pl": "-1297.2000" } ], "unrealizedPL": "682.0000", "marginCloseoutNAV": "49393.6580", "marginUsed": "9948.9000", "currency": "EUR", "resettablePL": "-1301.0046", "NAV": "49377.6580", "marginCloseoutMarginUsed": "9949.8000", "id": "101-004-1435156-001", "marginCloseoutPositionValue": "198996.0000", "openTradeCount": 2, "orders": [ { "partialFill": "DEFAULT_FILL", "price": "0.87000", "stopLossOnFill": { "timeInForce": "GTC", "price": "0.88000" }, "timeInForce": "GTC", "clientExtensions": { "comment": "myComment", "id": "myID" }, "id": "204", "triggerCondition": "TRIGGER_DEFAULT", "replacesOrderID": "200", "positionFill": "POSITION_DEFAULT", "createTime": "2016-07-08T07:18:47.623211321Z", "instrument": "EUR_GBP", "state": "PENDING", "units": "-50000", "type": "LIMIT" } ], "openPositionCount": 1, "marginCloseoutPercent": "0.10072", "marginCallMarginUsed": "9949.8000", "hedgingEnabled": false, "positionValue": "198978.0000", "pl": "-1301.0046", "lastTransactionID": "833", "marginAvailable": "39428.7580", "marginRate": "0.05", "marginCallPercent": "0.20144", "pendingOrderCount": 1, "withdrawalLimit": "39428.7580", "trades": [ { "instrument": "DE30_EUR", "financing": "0.0000", "openTime": "2016-07-12T09:32:18.062823776Z", "initialUnits": "-10", "currentUnits": "-10", "price": "9984.7", "unrealizedPL": "341.0000", "realizedPL": "0.0000", "state": "OPEN", "id": "821" }, { "instrument": "DE30_EUR", "financing": "0.0000", "openTime": "2016-07-12T09:32:18.206929733Z", "initialUnits": "-10", "currentUnits": "-10", "price": "9984.7", "unrealizedPL": "341.0000", "realizedPL": "0.0000", "state": "OPEN", "id": "823" } ], "alias": "hootnotv20", "createdByUserID": 1435156, "marginCloseoutUnrealizedPL": "698.0000", "createdTime": "2016-06-24T21:03:50.914647476Z", "balance": "48695.6580" }, "lastTransactionID": "833" }
-
-
class
oandapyV20.endpoints.accounts.
AccountSummary
(accountID)¶ Bases:
oandapyV20.endpoints.accounts.Accounts
Get a summary for a single Account that a client has access to.
-
ENDPOINT
= 'v3/accounts/{accountID}/summary'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID)¶ Instantiate an AccountSummary request.
Parameters: accountID (string (required)) – id of the account to perform the request on. >>> import oandapyV20 >>> import oandapyV20.endpoints.accounts as accounts >>> client = oandapyV20.API(access_token=...) >>> r = accounts.AccountSummary(accountID) >>> client.request(r) >>> print r.response
{ "account": { "marginCloseoutNAV": "35454.4740", "marginUsed": "10581.5000", "currency": "EUR", "resettablePL": "-13840.3525", "NAV": "35454.4740", "marginCloseoutMarginUsed": "10581.5000", "marginCloseoutPositionValue": "211630.0000", "openTradeCount": 2, "id": "101-004-1435156-001", "hedgingEnabled": false, "marginCloseoutPercent": "0.14923", "marginCallMarginUsed": "10581.5000", "openPositionCount": 1, "positionValue": "211630.0000", "pl": "-13840.3525", "lastTransactionID": "2123", "marginAvailable": "24872.9740", "marginRate": "0.05", "marginCallPercent": "0.29845", "pendingOrderCount": 0, "withdrawalLimit": "24872.9740", "unrealizedPL": "0.0000", "alias": "hootnotv20", "createdByUserID": 1435156, "marginCloseoutUnrealizedPL": "0.0000", "createdTime": "2016-06-24T21:03:50.914647476Z", "balance": "35454.4740" }, "lastTransactionID": "2123" }
-
-
class
oandapyV20.endpoints.accounts.
Accounts
(accountID=None)¶ Bases:
oandapyV20.endpoints.apirequest.APIRequest
Accounts - class to handle the accounts endpoints.
-
ENDPOINT
= ''¶
-
METHOD
= 'GET'¶
-
__init__
(accountID=None)¶ Instantiate an Accounts APIRequest instance.
Parameters: accountID (string (optional)) – the accountID of the account. Optional when requesting all accounts. For all other requests to the endpoint it is required.
-
oandapyV20.endpoints.instruments module¶
Handle instruments endpoints.
-
class
oandapyV20.endpoints.instruments.
Instruments
(instrument)¶ Bases:
oandapyV20.endpoints.apirequest.APIRequest
Instruments - abstract class to handle instruments endpoint.
-
ENDPOINT
= ''¶
-
METHOD
= 'GET'¶
-
__init__
(instrument)¶ Instantiate a Instrument APIRequest instance.
Parameters: - instrument (string (required)) – the instrument to operate on
- params (dict with query parameters) –
-
-
class
oandapyV20.endpoints.instruments.
InstrumentsCandles
(instrument, params=None)¶ Bases:
oandapyV20.endpoints.instruments.Instruments
Get candle data for a specified Instrument.
-
ENDPOINT
= 'v3/instruments/{instrument}/candles'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(instrument, params=None)¶ Instantiate an InstrumentsCandles request.
Parameters: - instrument (string (required)) – the instrument to fetch candle data for
- params (dict) – optional request query parameters, check developer.oanda.com for details
Params example:
{ "count": 5, "granularity": "M5" }
Candle data example:
>>> import oandapyV20 >>> import oandapyV20.endpoints.instruments as instruments >>> client = oandapyV20.API(access_token=...) >>> params = ... >>> r = instruments.InstrumentsCandles(instrument="DE30_EUR", >>> params=params) >>> client.request(r) >>> print r.response
Output:
{ "candles": [ { "volume": 132, "mid": { "h": "10508.0", "c": "10506.0", "l": "10503.8", "o": "10503.8" }, "complete": true, "time": "2016-10-17T19:35:00.000000000Z" }, { "volume": 162, "mid": { "h": "10507.0", "c": "10504.9", "l": "10502.0", "o": "10506.0" }, "complete": true, "time": "2016-10-17T19:40:00.000000000Z" }, { "volume": 196, "mid": { "h": "10509.8", "c": "10505.0", "l": "10502.6", "o": "10504.9" }, "complete": true, "time": "2016-10-17T19:45:00.000000000Z" }, { "volume": 153, "mid": { "h": "10510.1", "c": "10509.0", "l": "10504.2", "o": "10505.0" }, "complete": true, "time": "2016-10-17T19:50:00.000000000Z" }, { "volume": 172, "mid": { "h": "10509.8", "c": "10507.8", "l": "10503.2", "o": "10509.0" }, "complete": true, "time": "2016-10-17T19:55:00.000000000Z" } ], "granularity": "M5", "instrument": "DE30/EUR" }
-
oandapyV20.endpoints.orders module¶
Handle orders and pendingOrders endpoints.
-
class
oandapyV20.endpoints.orders.
OrderCancel
(accountID, orderID)¶ Bases:
oandapyV20.endpoints.orders.Orders
Cancel a pending Order in an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/orders/{orderID}/cancel'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'PUT'¶
-
__init__
(accountID, orderID)¶ Instantiate an OrdersCancel request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- orderID (string (required)) – id of the account to perform the request on.
Example:
>>> import oandapyV20 >>> import oandapyV20.endpoints.orders as orders >>> client = oandapyV20.API(access_token=...) >>> r = orders.OrderCancel(accountID= ..., orderID=...) >>> client.request(r) >>> print r.response
Output:
{ "orderCancelTransaction": { "orderID": "2307", "clientOrderID": "myID", "reason": "CLIENT_REQUEST", "batchID": "2308", "time": "2016-10-25T20:53:03.789670387Z", "type": "ORDER_CANCEL", "userID": 1435156, "id": "2308", "accountID": "101-004-1435156-001" }, "lastTransactionID": "2308", "relatedTransactionIDs": [ "2308" ] }
-
-
class
oandapyV20.endpoints.orders.
OrderClientExtensions
(accountID, orderID, data)¶ Bases:
oandapyV20.endpoints.orders.Orders
Update the Client Extensions for an Order in an Account.
Warning
Do not set, modify or delete clientExtensions if your account is associated with MT4.
-
ENDPOINT
= 'v3/accounts/{accountID}/orders/{orderID}/clientExtensions'¶
-
EXPECTED_STATUS
= 200¶
-
HEADERS
= {'Content-Type': 'application/json'}¶
-
METHOD
= 'PUT'¶
-
__init__
(accountID, orderID, data)¶ Instantiate an OrderCreate request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- orderID (string (required)) – id of the order to perform the request on.
- data (JSON (required)) – json orderbody to send
Orderbody example:
{ "clientExtensions": { "comment": "myComment", "id": "myID" } }
>>> import oandapyV20 >>> import oandapyV20.endpoints.orders as orders >>> client = oandapyV20.API(access_token=...) >>> r = orders.OrderClientExtensions(accountID, orderID, data=data) >>> client.request(r) >>> print r.response
{ "lastTransactionID": "2305", "orderClientExtensionsModifyTransaction": { "orderID": "2304", "batchID": "2305", "clientExtensionsModify": { "comment": "myComment", "id": "myID" }, "time": "2016-10-25T15:56:43.075594239Z", "type": "ORDER_CLIENT_EXTENSIONS_MODIFY", "userID": 1435156, "id": "2305", "accountID": "101-004-1435156-001" }, "relatedTransactionIDs": [ "2305" ] }
-
-
class
oandapyV20.endpoints.orders.
OrderCreate
(accountID, data)¶ Bases:
oandapyV20.endpoints.orders.Orders
Create an Order for an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/orders'¶
-
EXPECTED_STATUS
= 201¶
-
HEADERS
= {'Content-Type': 'application/json'}¶
-
METHOD
= 'POST'¶
-
__init__
(accountID, data)¶ Instantiate an OrderCreate request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- data (JSON (required)) – json orderbody to send
Orderbody example:
{ "order": { "price": "1.2", "stopLossOnFill": { "timeInForce": "GTC", "price": "1.22" }, "timeInForce": "GTC", "instrument": "EUR_USD", "units": "-100", "type": "LIMIT", "positionFill": "DEFAULT" } }
>>> import oandapyV20 >>> import oandapyV20.endpoints.orders as orders >>> client = oandapyV20.API(access_token=...) >>> r = orders.OrderCreate(accountID, data=data) >>> client.request(r) >>> print r.response
{ "orderCreateTransaction": { "price": "1.20000", "stopLossOnFill": { "timeInForce": "GTC", "price": "1.22000" }, "timeInForce": "GTC", "reason": "CLIENT_ORDER", "id": "2304", "batchID": "2304", "triggerCondition": "TRIGGER_DEFAULT", "positionFill": "DEFAULT", "userID": 1435156, "instrument": "EUR_USD", "time": "2016-10-24T21:48:18.593753865Z", "units": "-100", "type": "LIMIT_ORDER", "accountID": "101-004-1435156-001" }, "lastTransactionID": "2304", "relatedTransactionIDs": [ "2304" ] }
-
-
class
oandapyV20.endpoints.orders.
OrderDetails
(accountID, orderID)¶ Bases:
oandapyV20.endpoints.orders.Orders
Get details for a single Order in an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/orders/{orderID}'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, orderID)¶ Instantiate an OrderDetails request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- orderID (string (required)) – id of the order to perform the request on.
>>> import oandapyV20 >>> import oandapyV20.endpoints.orders as orders >>> client = oandapyV20.API(access_token=...) >>> r = orders.OrderDetails(accountID=..., orderID=...) >>> client.request(r) >>> print r.response
Output:
{ "order": { "partialFill": "DEFAULT_FILL", "price": "1.20000", "stopLossOnFill": { "timeInForce": "GTC", "price": "1.22000" }, "timeInForce": "GTC", "createTime": "2016-10-25T21:07:21.065554321Z", "triggerCondition": "TRIGGER_DEFAULT", "positionFill": "POSITION_DEFAULT", "id": "2309", "instrument": "EUR_USD", "state": "PENDING", "units": "-100", "type": "LIMIT" }, "lastTransactionID": "2309" }
-
-
class
oandapyV20.endpoints.orders.
OrderList
(accountID, params=None)¶ Bases:
oandapyV20.endpoints.orders.Orders
Create an Order for an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/orders'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, params=None)¶ Instantiate an OrderList request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- params (dict) – optional request query parameters, check developer.oanda.com for details
Example:
>>> import oandapyV20 >>> import oandapyV20.endpoints.orders as orders >>> client = oandapyV20.API(access_token=...) >>> r = orders.OrderList(accountID) >>> client.request(r) >>> print r.response
Output:
{ "orders": [ { "partialFill": "DEFAULT_FILL", "price": "1.20000", "stopLossOnFill": { "timeInForce": "GTC", "price": "1.22000" }, "timeInForce": "GTC", "createTime": "2016-10-05T10:25:47.627003645Z", "triggerCondition": "TRIGGER_DEFAULT", "positionFill": "POSITION_DEFAULT", "id": "2125", "instrument": "EUR_USD", "state": "PENDING", "units": "-100", "type": "LIMIT" } ], "lastTransactionID": "2129" }
-
-
class
oandapyV20.endpoints.orders.
OrderReplace
(accountID, orderID, data)¶ Bases:
oandapyV20.endpoints.orders.Orders
OrderReplace.
Replace an Order in an Account by simultaneously cancelling it and createing a replacement Order.
-
ENDPOINT
= 'v3/accounts/{accountID}/orders/{orderID}'¶
-
EXPECTED_STATUS
= 201¶
-
HEADERS
= {'Content-Type': 'application/json'}¶
-
METHOD
= 'PUT'¶
-
__init__
(accountID, orderID, data)¶ Instantiate an OrderReplace request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- orderID (string (required)) – id of the order to perform the request on.
- data (JSON (required)) – json orderbody to send
Orderbody example:
{ "order": { "units": "-500000", "instrument": "EUR_USD", "price": "1.25000", "type": "LIMIT" } }
>>> import oandapyV20 >>> import oandapyV20.endpoints.orders as orders >>> client = oandapyV20.API(access_token=...) >>> data = { "order": { "units": "-500000", "instrument": "EUR_USD", "price": "1.25000", "type": "LIMIT" } }
>>> r = orders.OrderReplace(accountID=..., orderID=..., data=data) >>> client.request(r) >>> print r.response
Output:
{ "orderCreateTransaction": { "price": "1.25000", "timeInForce": "GTC", "reason": "REPLACEMENT", "clientExtensions": { "comment": "myComment", "id": "myID" }, "id": "2307", "batchID": "2306", "triggerCondition": "TRIGGER_DEFAULT", "replacesOrderID": "2304", "positionFill": "DEFAULT", "userID": 1435156, "instrument": "EUR_USD", "time": "2016-10-25T19:45:38.558056359Z", "units": "-500000", "type": "LIMIT_ORDER", "accountID": "101-004-1435156-001" }, "orderCancelTransaction": { "orderID": "2304", "clientOrderID": "myID", "reason": "CLIENT_REQUEST_REPLACED", "batchID": "2306", "time": "2016-10-25T19:45:38.558056359Z", "type": "ORDER_CANCEL", "replacedByOrderID": "2307", "userID": 1435156, "id": "2306", "accountID": "101-004-1435156-001" }, "lastTransactionID": "2307", "relatedTransactionIDs": [ "2306", "2307" ] }
-
-
class
oandapyV20.endpoints.orders.
Orders
(accountID, orderID=None)¶ Bases:
oandapyV20.endpoints.apirequest.APIRequest
Orders - abstract base class to handle the orders endpoints.
-
ENDPOINT
= ''¶
-
EXPECTED_STATUS
= 0¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, orderID=None)¶ Instantiate an Orders request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- orderID (string) – id of the order to perform the request for.
-
-
class
oandapyV20.endpoints.orders.
OrdersPending
(accountID)¶ Bases:
oandapyV20.endpoints.orders.Orders
List all pending Orders in an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/pendingOrders'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID)¶ Instantiate an OrdersPending request.
Parameters: accountID (string (required)) – id of the account to perform the request on. Example:
>>> import oandapyV20 >>> import oandapyV20.endpoints.orders as orders >>> client = oandapyV20.API(access_token=...) >>> r = orders.OrdersPending(accountID) >>> client.request(r) >>> print r.response
Output:
{ "orders": [ { "partialFill": "DEFAULT_FILL", "price": "1.20000", "stopLossOnFill": { "timeInForce": "GTC", "price": "1.22000" }, "timeInForce": "GTC", "clientExtensions": { "comment": "myComment", "id": "myID" }, "id": "2304", "triggerCondition": "TRIGGER_DEFAULT", "positionFill": "POSITION_DEFAULT", "createTime": "2016-10-24T21:48:18.593753865Z", "instrument": "EUR_USD", "state": "PENDING", "units": "-100", "type": "LIMIT" } ], "lastTransactionID": "2305" }
-
oandapyV20.endpoints.positions module¶
Handle position endpoints.
-
class
oandapyV20.endpoints.positions.
OpenPositions
(accountID)¶ Bases:
oandapyV20.endpoints.positions.Positions
OpenPositions.
List all open Positions for an Account. An open Position is a Position in an Account that currently has a Trade opened for it.
-
ENDPOINT
= 'v3/accounts/{accountID}/openPositions'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID)¶ Instantiate an OpenPositions request.
Parameters: accountID (string (required)) – id of the account to perform the request on. >>> import oandapyV20 >>> import oandapyV20.endpoints.positions as positions >>> accountID = ... >>> client = oandapyV20.API(access_token=...) >>> r = positions.OpenPositions(accountID=accountID) >>> client.request(r) >>> print r.response
Output:
{ "positions": [ { "short": { "units": "0", "resettablePL": "-14164.3000", "unrealizedPL": "0.0000", "pl": "-14164.3000" }, "unrealizedPL": "-284.0000", "long": { "unrealizedPL": "-284.0000", "tradeIDs": [ "2315" ], "resettablePL": "404.5000", "units": "10", "averagePrice": "10678.3", "pl": "404.5000" }, "instrument": "DE30_EUR", "resettablePL": "-13759.8000", "pl": "-13759.8000" }, { "short": { "unrealizedPL": "-0.0738", "tradeIDs": [ "2323" ], "resettablePL": "0.0000", "units": "-100", "averagePrice": "1.09843", "pl": "0.0000" }, "unrealizedPL": "-0.0738", "long": { "units": "0", "resettablePL": "-44.6272", "unrealizedPL": "0.0000", "pl": "-44.6272" }, "instrument": "EUR_USD", "resettablePL": "-44.6272", "pl": "-44.6272" } ], "lastTransactionID": "2327" }
-
-
class
oandapyV20.endpoints.positions.
PositionClose
(accountID, instrument, data)¶ Bases:
oandapyV20.endpoints.positions.Positions
Closeout the open Position regarding instrument in an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/positions/{instrument}/close'¶
-
EXPECTED_STATUS
= 200¶
-
HEADERS
= {'Content-Type': 'application/json'}¶
-
METHOD
= 'PUT'¶
-
__init__
(accountID, instrument, data)¶ Instantiate a PositionClose request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- instrument (string (required)) – instrument to close partially or fully.
- data (dict (required)) – closeout specification data to send, check developer.oanda.com for details.
Data body example:
{ "longUnits": "ALL" }
>>> import oandapyV20 >>> import oandapyV20.endpoints.positions as positions >>> accountID = ... >>> instrument = ... >>> client = oandapyV20.API(access_token=...) >>> data = { "longUnits": "ALL" }
>>> r = positions.PositionClose(accountID=accountID, >>> instrument=instrument, >>> data=data) >>> client.request(r) >>> print r.response
Output:
{ "longOrderCreateTransaction": { "longPositionCloseout": { "units": "ALL", "instrument": "EUR_USD" }, "batchID": "6390", "reason": "POSITION_CLOSEOUT", "id": "6390", "timeInForce": "FOK", "positionFill": "REDUCE_ONLY", "userID": "<USERID>", "instrument": "EUR_USD", "time": "2016-06-22T18:41:35.034041665Z", "units": "-251", "type": "MARKET_ORDER", "accountID": "<ACCOUNT>" }, "relatedTransactionIDs": [ "6390", "6391" ], "lastTransactionID": "6391", "longOrderFillTransaction": { "price": "1.13018", "batchID": "6390", "accountBalance": "43650.69807", "reason": "MARKET_ORDER_POSITION_CLOSEOUT", "tradesClosed": [ { "units": "-1", "financing": "0.00000", "realizedPL": "-0.00013", "tradeID": "6383" }, { "units": "-250", "financing": "0.00000", "realizedPL": "-0.03357", "tradeID": "6385" } ], "id": "6391", "orderID": "6390", "financing": "0.00000", "userID": "<USERID>", "instrument": "EUR_USD", "time": "2016-06-22T18:41:35.034041665Z", "units": "-251", "type": "ORDER_FILL", "pl": "-0.03370", "accountID": "<ACCOUNT>" } }
-
-
class
oandapyV20.endpoints.positions.
PositionDetails
(accountID, instrument)¶ Bases:
oandapyV20.endpoints.positions.Positions
PositionDetails.
Get the details of a single instrument’s position in an Account. The position may be open or not.
-
ENDPOINT
= 'v3/accounts/{accountID}/positions/{instrument}'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, instrument)¶ Instantiate a PositionDetails request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- instrument (string (required)) – id of the instrument to get the position details for.
>>> import oandapyV20 >>> import oandapyV20.endpoints.positions as positions >>> accountID = ... >>> instrument = ... >>> client = oandapyV20.API(access_token=...) >>> r = positions.PositionDetails(accountID=accountID, instrument) >>> client.request(r) >>> print r.response
Output:
{ "position": { "short": { "unrealizedPL": "-0.0738", "tradeIDs": [ "2323" ], "resettablePL": "0.0000", "units": "-100", "averagePrice": "1.09843", "pl": "0.0000" }, "unrealizedPL": "-0.0738", "long": { "units": "0", "resettablePL": "-44.6272", "unrealizedPL": "0.0000", "pl": "-44.6272" }, "instrument": "EUR_USD", "resettablePL": "-44.6272", "pl": "-44.6272" }, "lastTransactionID": "2327" }
-
-
class
oandapyV20.endpoints.positions.
PositionList
(accountID)¶ Bases:
oandapyV20.endpoints.positions.Positions
PositionList.
List all Positions for an Account. The Positions returned are for every instrument that has had a position during the lifetime of the Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/positions'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID)¶ Instantiate a PositionList request.
Parameters: accountID (string (required)) – id of the account to perform the request on. >>> import oandapyV20 >>> import oandapyV20.endpoints.positions as positions >>> accountID = ... >>> client = oandapyV20.API(access_token=...) >>> r = positions.PositionList(accountID=accountID) >>> client.request(r) >>> print r.response
Output:
{ "positions": [ { "short": { "units": "0", "resettablePL": "-272.6805", "unrealizedPL": "0.0000", "pl": "-272.6805" }, "unrealizedPL": "0.0000", "long": { "units": "0", "resettablePL": "0.0000", "unrealizedPL": "0.0000", "pl": "0.0000" }, "instrument": "EUR_GBP", "resettablePL": "-272.6805", "pl": "-272.6805" }, { "short": { "unrealizedPL": "870.0000", "tradeIDs": [ "2121", "2123" ], "resettablePL": "-13959.3000", "units": "-20", "averagePrice": "10581.5", "pl": "-13959.3000" }, "unrealizedPL": "870.0000", "long": { "units": "0", "resettablePL": "404.5000", "unrealizedPL": "0.0000", "pl": "404.5000" }, "instrument": "DE30_EUR", "resettablePL": "-13554.8000", "pl": "-13554.8000" }, { "short": { "units": "0", "resettablePL": "0.0000", "unrealizedPL": "0.0000", "pl": "0.0000" }, "unrealizedPL": "0.0000", "long": { "units": "0", "resettablePL": "-12.8720", "unrealizedPL": "0.0000", "pl": "-12.8720" }, "instrument": "EUR_USD", "resettablePL": "-12.8720", "pl": "-12.8720" } ], "lastTransactionID": "2124" }
-
-
class
oandapyV20.endpoints.positions.
Positions
(accountID, instrument=None)¶ Bases:
oandapyV20.endpoints.apirequest.APIRequest
Positions - abstractbase class to handle the ‘positions’ endpoints.
-
ENDPOINT
= ''¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, instrument=None)¶ Instantiate a Positions APIRequest instance.
Parameters: - accountID (string (required)) – the id of the account to perform the request on.
- instrument (string (optional)) – the instrument for the Positions request
-
oandapyV20.endpoints.pricing module¶
Handle pricing endpoints.
-
class
oandapyV20.endpoints.pricing.
Pricing
(accountID)¶ Bases:
oandapyV20.endpoints.apirequest.APIRequest
Pricing - class to handle pricing endpoint.
-
ENDPOINT
= ''¶
-
METHOD
= 'GET'¶
-
__init__
(accountID)¶ Instantiate a Pricing APIRequest instance.
Parameters: accountID (string (required)) – the accountID of the account.
-
-
class
oandapyV20.endpoints.pricing.
PricingInfo
(accountID, params=None)¶ Bases:
oandapyV20.endpoints.pricing.Pricing
Pricing.
Get pricing information for a specified list of Instruments within an account.
-
ENDPOINT
= 'v3/accounts/{accountID}/pricing'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, params=None)¶ Instantiate a PricingStream APIRequest instance.
Parameters: - accountID (string (required)) – the accountID of the account.
- params (dict (required)) – parameters for the request, check developer.oanda.com for details.
Example
>>> import oandapyV20 >>> from oandapyV20 import API >>> import oandapyV20.endpoints.pricing as pricing >>> accountID = "..." >>> api = API(access_token="...") >>> params = { "instruments": "EUR_USD,EUR_JPY" }
>>> r = pricing.PricingInfo(accountID=accountID, params=params) >>> rv = api.request(r) >>> print r.response
Output:
{ "prices": [ { "status": "tradeable", "instrument": "EUR_USD", "quoteHomeConversionFactors": { "negativeUnits": "0.89160730", "positiveUnits": "0.89150397" }, "asks": [ { "price": "1.12170", "liquidity": 10000000 }, { "price": "1.12172", "liquidity": 10000000 } ], "time": "2016-10-05T05:28:16.729643492Z", "closeoutAsk": "1.12174", "bids": [ { "price": "1.12157", "liquidity": 10000000 }, { "price": "1.12155", "liquidity": 10000000 } ], "closeoutBid": "1.12153", "unitsAvailable": { "default": { "short": "506246", "long": "506128" }, "reduceOnly": { "short": "0", "long": "0" }, "openOnly": { "short": "506246", "long": "506128" }, "reduceFirst": { "short": "506246", "long": "506128" } } }, { "status": "tradeable", "instrument": "EUR_JPY", "quoteHomeConversionFactors": { "negativeUnits": "0.00867085", "positiveUnits": "0.00866957" }, "asks": [ { "price": "115.346", "liquidity": 1000000 }, { "price": "115.347", "liquidity": 2000000 }, { "price": "115.348", "liquidity": 5000000 }, { "price": "115.350", "liquidity": 10000000 } ], "time": "2016-10-05T05:28:15.621238671Z", "closeoutAsk": "115.350", "bids": [ { "price": "115.329", "liquidity": 1000000 }, { "price": "115.328", "liquidity": 2000000 }, { "price": "115.327", "liquidity": 5000000 }, { "price": "115.325", "liquidity": 10000000 } ], "closeoutBid": "115.325", "unitsAvailable": { "default": { "short": "506262", "long": "506112" }, "reduceOnly": { "short": "0", "long": "0" }, "openOnly": { "short": "506262", "long": "506112" }, "reduceFirst": { "short": "506262", "long": "506112" } } } ] }
-
-
class
oandapyV20.endpoints.pricing.
PricingStream
(accountID, params=None)¶ Bases:
oandapyV20.endpoints.pricing.Pricing
PricingStream.
Get realtime pricing information for a specified list of Instruments.
-
ENDPOINT
= 'v3/accounts/{accountID}/pricing/stream'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
STREAM
= True¶
-
__init__
(accountID, params=None)¶ Instantiate a PricingStream APIRequest instance.
Parameters: - accountID (string (required)) – the accountID of the account.
- params (dict (required)) – parameters for the request, check developer.oanda.com for details.
Example
>>> import oandapyV20 >>> from oandapyV20 import API >>> import oandapyV20.endpoints.pricing as pricing >>> accountID = "..." >>> api = API(access_token="...") >>> params = { "instruments": "EUR_USD,EUR_JPY" }
>>> r = pricing.PricingStream(accountID=accountID, params=params) >>> rv = api.request(r) >>> maxrecs = 100 >>> for ticks in r: >>> print json.dumps(R, indent=4),"," >>> if maxrecs == 0: >>> r.terminate("maxrecs records received")
Output:
{ "status": "tradeable", "asks": [ { "price": "114.312", "liquidity": 1000000 }, { "price": "114.313", "liquidity": 2000000 }, { "price": "114.314", "liquidity": 5000000 }, { "price": "114.316", "liquidity": 10000000 } ], "closeoutBid": "114.291", "bids": [ { "price": "114.295", "liquidity": 1000000 }, { "price": "114.294", "liquidity": 2000000 }, { "price": "114.293", "liquidity": 5000000 }, { "price": "114.291", "liquidity": 10000000 } ], "instrument": "EUR_JPY", "time": "2016-10-27T08:38:43.094548890Z", "closeoutAsk": "114.316" }, { "type": "HEARTBEAT", "time": "2016-10-27T08:38:44.327443673Z" }, { "status": "tradeable", "asks": [ { "price": "1.09188", "liquidity": 10000000 }, { "price": "1.09190", "liquidity": 10000000 } ], "closeoutBid": "1.09173", "bids": [ { "price": "1.09177", "liquidity": 10000000 }, { "price": "1.09175", "liquidity": 10000000 } ], "instrument": "EUR_USD", "time": "2016-10-27T08:38:45.664613867Z", "closeoutAsk": "1.09192" }, { "status": "tradeable", "asks": [ { "price": "114.315", "liquidity": 1000000 }, { "price": "114.316", "liquidity": 2000000 }, { "price": "114.317", "liquidity": 5000000 }, { "price": "114.319", "liquidity": 10000000 } ], "closeoutBid": "114.294", "bids": [ { "price": "114.298", "liquidity": 1000000 }, { "price": "114.297", "liquidity": 2000000 }, { "price": "114.296", "liquidity": 5000000 }, { "price": "114.294", "liquidity": 10000000 } ], "instrument": "EUR_JPY", "time": "2016-10-27T08:38:45.681572782Z", "closeoutAsk": "114.319" }
-
terminate
(message='')¶ terminate the stream.
Calling this method will stop the generator yielding tickrecords. A message can be passed optionally.
-
oandapyV20.endpoints.trades module¶
Handle trades endpoints.
-
class
oandapyV20.endpoints.trades.
OpenTrades
(accountID)¶ Bases:
oandapyV20.endpoints.trades.Trades
Get the list of open Trades for an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/openTrades'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID)¶ Instantiate an OpenTrades request.
Parameters: accountID (string (required)) – id of the account to perform the request on. >>> import oandapyV20 >>> import oandapyV20.endpoints.trades as trades >>> client = oandapyV20.API(access_token=...) >>> r = trades.OpenTrades(accountID=...) >>> client.request(r) >>> print r.response
Output:
{ "trades": [ { "instrument": "DE30_EUR", "financing": "0.0000", "openTime": "2016-10-28T14:28:05.231759081Z", "initialUnits": "10", "currentUnits": "10", "price": "10678.3", "unrealizedPL": "136.0000", "realizedPL": "0.0000", "state": "OPEN", "id": "2315" } ], "lastTransactionID": "2317" }
-
-
class
oandapyV20.endpoints.trades.
TradeCRCDO
(accountID, tradeID, data)¶ Bases:
oandapyV20.endpoints.trades.Trades
Trade Create Replace Cancel Dependent Orders.
-
ENDPOINT
= 'v3/accounts/{accountID}/trades/{tradeID}/orders'¶
-
EXPECTED_STATUS
= 200¶
-
HEADERS
= {'Content-Type': 'application/json'}¶
-
METHOD
= 'PUT'¶
-
__init__
(accountID, tradeID, data)¶ Instantiate a TradeClientExtensions request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- tradeID (string (required)) – id of the trade to update client extensions for.
- data (dict (required)) – clientextension data to send, check developer.oanda.com for details.
Data body example:
{ "takeProfit": { "timeInForce": "GTC", "price": "1.05" }, "stopLoss": { "timeInForce": "GTC", "price": "1.10" } }
>>> import oandapyV20 >>> import oandapyV20.endpoints.trades as trades >>> accountID = ... >>> tradeID = ... >>> client = oandapyV20.API(access_token=...) >>> data = { "takeProfit": { "timeInForce": "GTC", "price": "1.05" }, "stopLoss": { "timeInForce": "GTC", "price": "1.10" } }
>>> r = trades.TradeCRCDO(accountID=accountID, >>> tradeID=tradeID, >>> data=data) >>> client.request(r) >>> print r.response
Output:
{ "lastTransactionID": "2327", "stopLossOrderCancelTransaction": { "orderID": "2324", "batchID": "2325", "reason": "CLIENT_REQUEST_REPLACED", "time": "2016-10-28T21:00:19.978476830Z", "type": "ORDER_CANCEL", "replacedByOrderID": "2327", "userID": 1435156, "id": "2326", "accountID": "101-004-1435156-001" }, "stopLossOrderTransaction": { "tradeID": "2323", "price": "1.10000", "timeInForce": "GTC", "reason": "REPLACEMENT", "id": "2327", "batchID": "2325", "triggerCondition": "TRIGGER_DEFAULT", "replacesOrderID": "2324", "userID": 1435156, "time": "2016-10-28T21:00:19.978476830Z", "cancellingTransactionID": "2326", "type": "STOP_LOSS_ORDER", "accountID": "101-004-1435156-001" }, "relatedTransactionIDs": [ "2325", "2326", "2327" ], "takeProfitOrderTransaction": { "tradeID": "2323", "price": "1.05000", "timeInForce": "GTC", "reason": "CLIENT_ORDER", "id": "2325", "batchID": "2325", "triggerCondition": "TRIGGER_DEFAULT", "userID": 1435156, "time": "2016-10-28T21:00:19.978476830Z", "type": "TAKE_PROFIT_ORDER", "accountID": "101-004-1435156-001" } }
-
-
class
oandapyV20.endpoints.trades.
TradeClientExtensions
(accountID, tradeID, data=None)¶ Bases:
oandapyV20.endpoints.trades.Trades
TradeClientExtensions.
Update the Client Extensions for a Trade. Do not add, update or delete the Client Extensions if your account is associated with MT4.
-
ENDPOINT
= 'v3/accounts/{accountID}/trades/{tradeID}/clientExtensions'¶
-
EXPECTED_STATUS
= 200¶
-
HEADERS
= {'Content-Type': 'application/json'}¶
-
METHOD
= 'PUT'¶
-
__init__
(accountID, tradeID, data=None)¶ Instantiate a TradeClientExtensions request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- tradeID (string (required)) – id of the trade to update client extensions for.
- data (dict (required)) – clientextension data to send, check developer.oanda.com for details.
Data body example:
{ "clientExtensions": { "comment": "myComment", "id": "myID2315" } }
>>> import oandapyV20 >>> import oandapyV20.endpoints.trades as trades >>> accountID = ... >>> tradeID = ... >>> client = oandapyV20.API(access_token=...) >>> data = { "clientExtensions": { "comment": "myComment", "id": "myID2315" } }
>>> r = trades.TradeClientExtensions(accountID=accountID, >>> tradeID=tradeID, >>> data=data) >>> client.request(r) >>> print r.response
Output:
{ "tradeClientExtensionsModifyTransaction": { "batchID": "2319", "tradeID": "2315", "time": "2016-10-28T20:32:39.356516787Z", "tradeClientExtensionsModify": { "comment": "myComment", "id": "myID2315" }, "type": "TRADE_CLIENT_EXTENSIONS_MODIFY", "userID": 1435156, "id": "2319", "accountID": "101-004-1435156-001" }, "lastTransactionID": "2319", "relatedTransactionIDs": [ "2319" ] }
-
-
class
oandapyV20.endpoints.trades.
TradeClose
(accountID, tradeID, data=None)¶ Bases:
oandapyV20.endpoints.trades.Trades
TradeClose.
Close (partially or fully) a specific open Trade in an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/trades/{tradeID}/close'¶
-
EXPECTED_STATUS
= 200¶
-
HEADERS
= {'Content-Type': 'application/json'}¶
-
METHOD
= 'PUT'¶
-
__init__
(accountID, tradeID, data=None)¶ Instantiate a TradeClose request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- tradeID (string (required)) – id of the trade to close.
- data (dict (optional)) – data to send, use this to close a trade partially. Check developer.oanda.com for details.
Data body example:
{ "units": 100 }
>>> import oandapyV20 >>> import oandapyV20.endpoints.trades as trades >>> client = oandapyV20.API(access_token=...) >>> data = { "units": 100 }
>>> r = trades.TradeClose(accountID=..., data=data) >>> client.request(r) >>> print r.response
Output:
{ "orderFillTransaction": { "price": "1.09289", "batchID": "2316", "accountBalance": "33848.1208", "reason": "MARKET_ORDER_TRADE_CLOSE", "tradesClosed": [ { "units": "-100", "financing": "0.0000", "realizedPL": "-0.1455", "tradeID": "2313" } ], "id": "2317", "orderID": "2316", "financing": "0.0000", "userID": 1435156, "instrument": "EUR_USD", "time": "2016-10-28T15:11:58.023004583Z", "units": "-100", "type": "ORDER_FILL", "pl": "-0.1455", "accountID": "101-004-1435156-001" }, "orderCreateTransaction": { "timeInForce": "FOK", "reason": "TRADE_CLOSE", "tradeClose": { "units": "100", "tradeID": "2313" }, "id": "2316", "batchID": "2316", "positionFill": "REDUCE_ONLY", "userID": 1435156, "instrument": "EUR_USD", "time": "2016-10-28T15:11:58.023004583Z", "units": "-100", "type": "MARKET_ORDER", "accountID": "101-004-1435156-001" }, "lastTransactionID": "2317", "relatedTransactionIDs": [ "2316", "2317" ] }
-
-
class
oandapyV20.endpoints.trades.
TradeDetails
(accountID, tradeID)¶ Bases:
oandapyV20.endpoints.trades.Trades
Get the details of a specific Trade in an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/trades/{tradeID}'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, tradeID)¶ Instantiate a TradeDetails request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- tradeID (string (required)) – id of the trade.
>>> import oandapyV20 >>> import oandapyV20.endpoints.trades as trades >>> client = oandapyV20.API(access_token=...) >>> r = accounts.TradeDetails(accountID=..., tradeID=...) >>> client.request(r) >>> print r.response
Output:
{ "lastTransactionID": "2317", "trade": { "instrument": "DE30_EUR", "financing": "0.0000", "openTime": "2016-10-28T14:28:05.231759081Z", "initialUnits": "10", "currentUnits": "10", "price": "10678.3", "unrealizedPL": "226.0000", "realizedPL": "0.0000", "state": "OPEN", "id": "2315" } }
-
-
class
oandapyV20.endpoints.trades.
Trades
(accountID, tradeID=None)¶ Bases:
oandapyV20.endpoints.apirequest.APIRequest
Trades - abstract baseclass to handle the trades endpoints.
-
ENDPOINT
= ''¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, tradeID=None)¶ Instantiate a Trades APIRequest instance.
Parameters: - accountID (string) – the account_id of the account.
- tradeID (string) – ID of the trade
-
-
class
oandapyV20.endpoints.trades.
TradesList
(accountID, params=None)¶ Bases:
oandapyV20.endpoints.trades.Trades
Get a list of trades for an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/trades'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, params=None)¶ Instantiate a TradesList request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- params (dict (optional)) – query params to send, check developer.oanda.com for details.
Query Params example:
{ "instrument": "DE30_EUR,EUR_USD" }
>>> import oandapyV20 >>> import oandapyV20.endpoints.trades as trades >>> client = oandapyV20.API(access_token=...) >>> params = { "instrument": "DE30_EUR,EUR_USD" }
>>> r = trades.TradesList(accountID=..., params=params) >>> client.request(r) >>> print r.response
Output:
{ "trades": [ { "instrument": "DE30_EUR", "financing": "0.0000", "openTime": "2016-10-28T14:28:05.231759081Z", "initialUnits": "10", "currentUnits": "10", "price": "10678.3", "unrealizedPL": "25.0000", "realizedPL": "0.0000", "state": "OPEN", "id": "2315" }, { "instrument": "EUR_USD", "financing": "0.0000", "openTime": "2016-10-28T14:27:19.011002322Z", "initialUnits": "100", "currentUnits": "100", "price": "1.09448", "unrealizedPL": "-0.0933", "realizedPL": "0.0000", "state": "OPEN", "id": "2313" } ], "lastTransactionID": "2315" }
-
oandapyV20.endpoints.transactions module¶
Handle transactions endpoints.
-
class
oandapyV20.endpoints.transactions.
TransactionDetails
(accountID, transactionID)¶ Bases:
oandapyV20.endpoints.transactions.Transactions
Get the details of a single Account Transaction.
-
ENDPOINT
= 'v3/accounts/{accountID}/transactions/{transactionID}'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, transactionID)¶ Instantiate a TransactionDetails request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- transactionID (string (required)) – id of the transaction
>>> import oandapyV20 >>> import oandapyV20.endpoints.transactions as trans >>> client = oandapyV20.API(access_token=...) >>> r = trans.TransactionDetails(accountID=..., transactionID=...) >>> client.request(r) >>> print r.response
Output:
{ "transaction": { "price": "1.20000", "stopLossOnFill": { "timeInForce": "GTC", "price": "1.22000" }, "timeInForce": "GTC", "reason": "CLIENT_ORDER", "id": "2304", "batchID": "2304", "triggerCondition": "TRIGGER_DEFAULT", "positionFill": "DEFAULT", "userID": 1435156, "instrument": "EUR_USD", "time": "2016-10-24T21:48:18.593753865Z", "units": "-100", "type": "LIMIT_ORDER", "accountID": "101-004-1435156-001" }, "lastTransactionID": "2311" }
-
-
class
oandapyV20.endpoints.transactions.
TransactionIDRange
(accountID, params=None)¶ Bases:
oandapyV20.endpoints.transactions.Transactions
TransactionIDRange.
Get a range of Transactions for an Account based on Transaction IDs.
-
ENDPOINT
= 'v3/accounts/{accountID}/transactions/idrange'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, params=None)¶ Instantiate an TransactionIDRange request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- params (dict (required)) – query params to send, check developer.oanda.com for details.
Query Params example:
{ "to": 2306, "from": 2304 }
>>> import oandapyV20 >>> import oandapyV20.endpoints.transactions as trans >>> client = oandapyV20.API(access_token=...) >>> params = { "to": 2306, "from": 2304 }
>>> r = trans.TransactionIDRange(accountID=..., params=params) >>> client.request(r) >>> print r.response
Output:
{ "lastTransactionID": "2311", "transactions": [ { "price": "1.20000", "stopLossOnFill": { "timeInForce": "GTC", "price": "1.22000" }, "timeInForce": "GTC", "reason": "CLIENT_ORDER", "id": "2304", "batchID": "2304", "triggerCondition": "TRIGGER_DEFAULT", "positionFill": "DEFAULT", "userID": 1435156, "instrument": "EUR_USD", "time": "2016-10-24T21:48:18.593753865Z", "units": "-100", "type": "LIMIT_ORDER", "accountID": "101-004-1435156-001" }, { "orderID": "2304", "batchID": "2305", "clientExtensionsModify": { "comment": "myComment", "id": "myID" }, "time": "2016-10-25T15:56:43.075594239Z", "type": "ORDER_CLIENT_EXTENSIONS_MODIFY", "userID": 1435156, "id": "2305", "accountID": "101-004-1435156-001" }, { "orderID": "2304", "clientOrderID": "myID", "reason": "CLIENT_REQUEST_REPLACED", "batchID": "2306", "time": "2016-10-25T19:45:38.558056359Z", "type": "ORDER_CANCEL", "replacedByOrderID": "2307", "userID": 1435156, "id": "2306", "accountID": "101-004-1435156-001" } ] }
-
-
class
oandapyV20.endpoints.transactions.
TransactionList
(accountID, params=None)¶ Bases:
oandapyV20.endpoints.transactions.Transactions
TransactionList.
Get a list of Transactions pages that satisfy a time-based Transaction query.
-
ENDPOINT
= 'v3/accounts/{accountID}/transactions'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, params=None)¶ Instantiate a TransactionList request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- params (dict (optional)) – query params to send, check developer.oanda.com for details.
Query Params example:
{ "pageSize": 200 }
>>> import oandapyV20 >>> import oandapyV20.endpoints.transactions as trans >>> client = oandapyV20.API(access_token=...) >>> r = trans.TransactionList(accountID) # params optional >>> client.request(r) >>> print r.response
Output:
{ "count": 2124, "from": "2016-06-24T21:03:50.914647476Z", "lastTransactionID": "2124", "pageSize": 100, "to": "2016-10-05T06:54:14.025946546Z", "pages": [ "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=1&to=100", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=101&to=200", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=201&to=300", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=301&to=400", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=401&to=500", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=501&to=600", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=601&to=700", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=701&to=800", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=801&to=900", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=901&to=1000", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=1001&to=1100", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=1101&to=1200", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=1201&to=1300", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=1301&to=1400", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=1401&to=1500", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=1501&to=1600", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=1601&to=1700", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=1701&to=1800", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=1801&to=1900", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=1901&to=2000", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=2001&to=2100", "https://api-fxpractice.oanda.com/v3/accounts/101-004-1435156-001/transactions/idrange?from=2101&to=2124" ] }
-
-
class
oandapyV20.endpoints.transactions.
Transactions
(accountID, transactionID=None)¶ Bases:
oandapyV20.endpoints.apirequest.APIRequest
Transactions - abstract baseclass to handle transaction endpoints.
-
ENDPOINT
= ''¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, transactionID=None)¶ Instantiate a Transactions APIRequest instance.
Parameters: - accountID (string (required)) – the id of the account.
- transactionID (string) – the id of the transaction
-
-
class
oandapyV20.endpoints.transactions.
TransactionsSinceID
(accountID, params=None)¶ Bases:
oandapyV20.endpoints.transactions.Transactions
TransactionsSinceID.
Get a range of Transactions for an Account starting at (but not including) a provided Transaction ID.
-
ENDPOINT
= 'v3/accounts/{accountID}/transactions/sinceid'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
__init__
(accountID, params=None)¶ Instantiate an TransactionsSince request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- params (dict (required)) – query params to send, check developer.oanda.com for details.
Query Params example:
{ "id": 2306 }
>>> import oandapyV20 >>> import oandapyV20.endpoints.transactions as trans >>> client = oandapyV20.API(access_token=...) >>> params = { "id": 2306 }
>>> r = trans.TransactionsSinceID(accountID=..., params=params) >>> client.request(r) >>> print r.response
Output:
{ "lastTransactionID": "2311", "transactions": [ { "price": "1.25000", "timeInForce": "GTC", "reason": "REPLACEMENT", "clientExtensions": { "comment": "myComment", "id": "myID" }, "id": "2307", "batchID": "2306", "triggerCondition": "TRIGGER_DEFAULT", "replacesOrderID": "2304", "positionFill": "DEFAULT", "userID": 1435156, "instrument": "EUR_USD", "time": "2016-10-25T19:45:38.558056359Z", "units": "-500000", "type": "LIMIT_ORDER", "accountID": "101-004-1435156-001" }, { "orderID": "2307", "clientOrderID": "myID", "reason": "CLIENT_REQUEST", "batchID": "2308", "time": "2016-10-25T20:53:03.789670387Z", "type": "ORDER_CANCEL", "userID": 1435156, "id": "2308", "accountID": "101-004-1435156-001" }, { "price": "1.20000", "stopLossOnFill": { "timeInForce": "GTC", "price": "1.22000" }, "timeInForce": "GTC", "reason": "CLIENT_ORDER", "id": "2309", "batchID": "2309", "triggerCondition": "TRIGGER_DEFAULT", "positionFill": "DEFAULT", "userID": 1435156, "instrument": "EUR_USD", "time": "2016-10-25T21:07:21.065554321Z", "units": "-100", "type": "LIMIT_ORDER", "accountID": "101-004-1435156-001" }, { "userID": 1435156, "marginRate": "0.01", "batchID": "2310", "time": "2016-10-26T13:28:00.507651360Z", "type": "CLIENT_CONFIGURE", "id": "2310", "accountID": "101-004-1435156-001" }, { "userID": 1435156, "marginRate": "0.01", "batchID": "2311", "time": "2016-10-26T13:28:13.597103123Z", "type": "CLIENT_CONFIGURE", "id": "2311", "accountID": "101-004-1435156-001" } ] }
-
-
class
oandapyV20.endpoints.transactions.
TransactionsStream
(accountID, params=None)¶ Bases:
oandapyV20.endpoints.transactions.Transactions
TransactionsStream.
Get a stream of Transactions for an Account starting from when the request is made.
-
ENDPOINT
= 'v3/accounts/{accountID}/transactions/stream'¶
-
EXPECTED_STATUS
= 200¶
-
METHOD
= 'GET'¶
-
STREAM
= True¶
-
__init__
(accountID, params=None)¶ Instantiate an TransactionsStream request.
Performing this request will result in a generator yielding transactions.
Parameters: accountID (string (required)) – id of the account to perform the request on. >>> import oandapyV20 >>> import oandapyV20.endpoints.transactions as trans >>> client = oandapyV20.API(access_token=...) >>> r = trans.TransactionsStream(accountID=...) >>> rv = client.request(r) >>> maxrecs = 5 >>> try: >>> for T in r.response: # or rv ... >>> print json.dumps(R, indent=4), "," >>> maxrecs -= 1 >>> if maxrecs == 0: >>> r.terminate("Got them all") >>> except StreamTerminated as e: >>> print("Finished: {msg}".format(msg=e))
Output:
{ "type": "HEARTBEAT", "lastTransactionID": "2311", "time": "2016-10-28T11:56:12.002855862Z" }, { "type": "HEARTBEAT", "lastTransactionID": "2311", "time": "2016-10-28T11:56:17.059535527Z" }, { "type": "HEARTBEAT", "lastTransactionID": "2311", "time": "2016-10-28T11:56:22.142256403Z" }, { "type": "HEARTBEAT", "lastTransactionID": "2311", "time": "2016-10-28T11:56:27.238853774Z" }, { "type": "HEARTBEAT", "lastTransactionID": "2311", "time": "2016-10-28T11:56:32.289316796Z" } Finished: Got them all
-
terminate
(message='')¶ terminate the stream.
Calling this method will stop the generator yielding transaction records. A message can be passed optionally.
-