This repo contains a number of examples to demonstrate how to use OANDA's REST-V20 API with the oandapyV20 Python API-wrapper.
Clone the repository:
$ git clone https://github.com/hootnot/oandapyV20-examples
Install oandapyV20 and other pypi-packages the examples depend on. Maybe you want to do this from a virtual environment.
$ pip install -r requirements.txt
Access to the OANDA V20 REST-API requires a token. If you do not have a token you can obtain one. Check developer.oanda.com for details. Edit the file token.txt and put the token in it.
If you have a token, you have an account. Edit the file account.txt and put the accountID in it. Verify that it is your V20 accountID!
Make sure you have made the setup based on a practice account ! Leveraged trading is high risk. Losses can exceed investment!
All examples can be run from the cloned repo directory as:
$ python src/<example.py>
Source | Description |
---|---|
Account | |
src/instruments_list.py | Get list of tradable instruments for account |
Streams | |
src/streaming_prices.py | Simple streaming prices using pydantic to process records |
src/streaming_trans.py | Simple streaming transactions |
src/concurrent_streaming.py | Demonstrate concurrent streaming of prices and events along with the polling of account changes based on gevent greenlets |
Data | |
src/candle-data.py | Retrieve candle data |
Orders | |
src/market_order.py | Placing market orders / logging |
src/market_order_request.py | Placing market orders using contrib.requests / logging |
src/contrib_mo_tp_sl.py | Placing market order with takeprofit on-fill and stoploss on-fill |
Console | |
src/oanda_console.py | Console application showing realtime tickdata (Linux/Unix only / python 3 only) |
Auto Trading | |
src/simplebot.py | Simple trading bot based on a moving-average crossover. The bot gets initialized by retrieving the longest MA period of candles. After that new records are fabricated from the stream. When there is a state change an order is placed with a takeprofit and a stoploss order with it. The positions can be traced with the src/oanda_console application. |
The oanda-api-v20 / oandapyV20 software is a personal project. I have no prior or existing relationship with OANDA.
If you have any questions regarding this software, please take a look at the documentation first:
- oandapyV20 : http://oanda-api-v20.readthedocs.io/en/latest/?badge=latest
- OANDA developer docs : http://developer.oanda.com
- examples : https://github.com/hootnot/oandapyV20-examples
- Github: https://github.com/hootnot/oanda-api-v20 check the open and closed issues
If you still have questions/issues you can open an issue on Gitub: https://github.com/hootnot/oanda-api-v20