Skip to content

Latest commit

 

History

History
93 lines (57 loc) · 2.64 KB

getting_started.rst

File metadata and controls

93 lines (57 loc) · 2.64 KB

Getting started

Creating an Account

To use async_v20 you must have an account with OANDA

Setting up environment

  • Install async_v20 as per installation
  • Create a new environment variable with the name OANDA_TOKEN and value as the token generated from create-account.

environment_variables

Note

  • It is considered best practice use a virtual environment
  • It is not required to store the token in an environment variable. The token can be passed to OandaClient

Using async_v20

Once an account has been created as per create-account and the environment is configured as per setting-up-environment, we are ready to begin.

Lets first take a look at this code example, then go though it line by line.

../../bin/account.py

First we need to import asyncio this allows us to run our coroutine

../../bin/account.py

We then import OandaClient which provides us the means to interact with OANDA

../../bin/account.py

Because OandaClient returns coroutines we use async def. This allows the use of the await syntax

../../bin/account.py

OandaClient is a context manager, we use async with to instantiate a client instance. Doing so will automatically close the http session when we're done

../../bin/account.py

We then create and await the coroutine by calling client. account()

../../bin/account.py

Now we have defined our coroutine we need to execute it. To do so we need an event loop. Achieved using asyncio. get_event_loop()

../../bin/account.py

The value returned by executing the account coroutine is accessed through the event loop.

../../bin/account.py

async_v20 objects have a Model. series() method that returns a pandas. Series

../../bin/account.py

Note

Each application should only instantiate ONE OandaClient instance per account. See best-practices.