Skip to main content

A platform to enable automated trading and market analysis with Python on the Oanda brokerage API

Project description

Build Status codecov

Automated Trading Platform that runs on Oanda

This repository is being developed to create a base trading platform to build automated trading strategies on. It is designed to use the Oanda brokerage v20 API. And it's primary purpose is to collect market prices, evaluate them and execute trades whilst monitoring your trading account. It is designed to run on a virtual machine, however it can easily be run from a local terminal too!

For visualising the trades and charting there are free desktop and web based software programs available from Oanda

If you would like more information about the Oanda API architecture used within this repo or have more questions on obtaining your Oanda tokens and credentials, you can view the full Oanda v20 developer documentation here

Current Features

Included test strategies:

This repo is designed as a base platform to build strategies upon. As such, everything functional, but it does not contain any profitable automated algorithms. The strategies included can be used to test everything is working. You can view the included algorithms in the strategies/forex_bots_python folder here.

Included is a simple price printer, a basic order execution bot and a simple RSI execution bot.

Email and text notifications

As part of the functionality, this platform includes automated email notifications sent for each up and down occurrence of the platform. If you wish to enable this, you will need pass those arguments into your config.ini (see below). This also means you will need to configure a gmail account to use an application password to use for the email sending options if you keep those enabled. There are optional Twilio SMS notifications you can configure as well.

Database

The data/marketdata.py module collects and stores the last 60 days of market data. It includes details such as margin rates, average spreads, historic high and lows for all the available trading instruments. It is intended to provide easy access to the data for developing and running trading strategies and for working out the cost of trades and money management strategies. The marketdata.py module runs to build the database the first time the platform is run. It will only run once for a given day.

DB Browser https://sqlitebrowser.org/ is good software for viewing and querying of the database.

Upstream remote

This repository was originally forked and developed from Eric Lingren's version Oanda V20 Platform Public. He has other useful server scripts and backtesting systems that are worth checking out and using in conjunction with this code.

Installation

Written and tested on Python 3.7.4, Not yet tested on other Python versions Tested on Windows, Mac and Linux The list of required dependencies is in requirements.txt

To instal run:

git clone --branch=master https://github.com/ant358/oanda_v20_platform_public.git ant358/oanda_v20_platform_public  

cd ant358/oanda_v20_platform_public

Create a virtual environment and activate it.
for ref: https://docs.python.org/3/tutorial/venv.html

Create a .env file in the oanda_v20_platform_public/ folder and add your account number and token. You can add multiple accounts here e.g. live, practice, different accounts for different strategies etc. The classes in the oanda.py module are setup to default to account=PRACTICE_ACCOUNT and token=PRACTICE_TOKEN, when writing strategies to use different accounts simply pass these as keyword arguments to replace the default ones.
Add .env to your .gitignore to keep your account details local.

PRACTICE_ACCOUNT=XXX-XXX-XXXXXXXX-XXX
PRACTICE_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  
$ pip install -e .
$ pip install -r requirements.txt

Usage:

To start the trading platform in a terminal:

cd oanda_v20_platform
python main.py --bot "rsi_bot" --pair "EUR_USD"
  • change python to python3 on linux

Additional Config settings

The arguments listed above are all required for operation but there are optional ones available also for email and sms notifications. To view the full list of all arguments the python script will accept, you can check the config.ini file contained within the config folder here

Syntax for args

Currency pairs passed in must adhere to Oandas v20 schema - capital letters separated by an underscore. i.e. You must use EUR_USD rather than eur_usd or eurusd or EURUSD or some other variation. If you would like more information on this, you can view the Oanda Instrument developer docs here.

None of the automated trading strategies are profitable! They are for demonstration and testing purposes only

Disclaimer:

Trading foreign exchange carries a high level of risk, and may not be suitable for all investors. Past performance is not indicative of future results. Leverage can work against you as well as for you. Before deciding to invest in foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts.

I take no responsibility for any losses or gains you may incur from using my software. I also take no responsibility for any architecture, security, or server configurations.

This software is provided as is. No warranties or guarantees will be provided for its accuracy, completeness, reliability, or security if used within your own environment.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oanda_v20_platform-ant358-0.1.0.tar.gz (22.0 kB view hashes)

Uploaded Source

Built Distribution

oanda_v20_platform_ant358-0.1.0-py3-none-any.whl (26.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page