To run interactively, use Jupyter Notebook with Python2.7 (this is what I used). Python3.x could also be used but I cannot guarantee everything will work, simply because I have not tested the example using that Python version.
You'll need to create a separate config file called oanda.cfg containing your account_id and access_token (obtainable from Oanda after registering).
Adapted from the blog post by Dr Yves Hilpisch at https://www.oreilly.com/learning/algorithmic-trading-in-less-than-100-lines-of-python-code