Algorithmic trading using 100 lines of python code, using OANDA v20 API

After reading Dr. Yves Hilpisch’s article, “Algorithmic trading using 100 lines of python code,” I was inspired to give it a shot. I wanted to apply his guide on how to use a time series momentum algorithm because I have been interested in forex trading with cryptocurrencies. I set up a free forex trial account on OANDA, jumped into a jupyter notebook, and got to work. I hit an issue. OANDA changed their API from “v1” to “v20” and all new accounts default to the new API. I ended up rewriting his sample code to work with the new OANDA v20 API using a third party python library.

If you are still wanting to use the original v1 API sample code, you could reach out to OANDA chat support and manually request a v1 legacy demo account. It takes 2 business days. Ain’t nobody got time for that! Plus, you can’t hedge in the v1 API.

OANDA v20 - Do you even hedge, bro?
OANDA v20 – Do you even hedge, bro?

Here is my github repo with both the v1 and v20 sample code in jupyter notebooks, for comparison:

https://github.com/benjaminchodroff/oandamomentum

Here is the gist of my end result using the OANDA v20 API:

Thanks again, Dr. Hilpisch!

Leave a Reply

Your email address will not be published. Required fields are marked *