Particularly Pertinent Programming Interface¶
There are two additional helper methods that OandaClient exposes, beyond OANDA’s
own v20 client;
account()
, close_all_trades()
.
Getting the Account Status¶
OANDA’s v20 API is a RESTful service. Meaning that the server only sends the changes to the account, rather then the full account. This is useful, in that it reduces network traffic, but requires addition computation on the client side. As changes sent from the server must be incorporated locally.
This functionality is implemented in the account()
method.
In order to check the status of the account. Use the await syntax, like so:
async def get_account():
async with OandaClient() as client:
return await client.account()
Note
The account()
method uses the response from
account_changes()
to update the local account object.
the response from account_changes()
contains more information
than the Account
specifies. Meaning that some
information contained in the account_changes()
response
is lost when updating the account. It has been chosen to only keep
Order
’s
Trade
’s
Position
’s,
in the account that are currently open.
This is to resemble the behaviour of OANDA’s Web based browser interface
Transaction
’s are stored on the
client as transactions
Closing all Trades¶
The close_all_trades()
method is provided to help facilitate
your risk management policy. async_v20 is intended to be used as an algorithmic trading platform,
which naturally raises concerns of run away losses, to the unbeknown user.
close_all_trades()
is intended to help mitigate this concern by allowing
users to programme a global stop loss by which all trades can be terminated.
Note
Users who implement this feature should account for the Two possible outcomes.
- A
CloseAllTradesFailure
is raised
OR
- returns (True, closed_trade_responses) - All trades were closed