RL model deployment on OANDA

Course Name: Deep Reinforcement Learning in Trading, Section No: 20, Unit No: 8, Unit type: Document

I'm tryng to create the script to deploy RL model on OANDA. In Deep Reinforcement Learning in Trading course deployment and live trading are related to use it with "Ibridgepy" with IB. Is there anyone who has already created a script to use machine learning algorithms with Oanda? Attached my RL trading bot script (without enviroment part)

Thanks for your query and congratulations on reaching the deploying RL model stage.



I would recommend performing basic steps to deploy on Oanda and then you can extend that on the reinforcement learning.



The basic steps are as follows:


  1. Connection Testing

    I see that you are using tpqoa package. Run the below lines in Jupyter notebook to confirm that the connection is successful

     
import tpqoa
oanda = tpqoa.tpqoa('oanda.cfg')
oanda.get_account_summary()

You will receive a json of your account details





2. Data retrieval



In this step, we access the data. We try to retrieve EUR_USD data. M5 indicates 5 minute data and price='M' indicates middle. You can change to A for Ask and so on.

data = oanda.get_history(instrument='EUR_USD',
                  start='2022-05-22 09:00 ',
                  end='2022-05-23 12:00',
                  granularity='M5',
                  price='M')
print(data)

3. Order Placement

The below code will place buy order for 100 units of EUR_USD. To place sell order set units to -100. Note: set the environment to practice in cfg file before placing order. This will ensure that orders are placed in practice environment.
oanda.create_order('EUR_USD', units=100)

Once the above steps run successfully, you can modify the code in RL python file you have shared

1. Connection Setup

You need to place the below code for connection inside initialize method
 
import tpqoa
oanda = tpqoa.tpqoa('oanda.cfg')
oanda.get_account_summary()

2. schedule_function

The schedule function is from ibridgepy. You need to define the logic for it in Python. That is when you want to call the strategy function such as every 5 minutes

3. Data

You need to change the data call to the one shown below. The end date needs to be dynamically adjusted based on recent date time so that you get the most recent data
 
data = oanda.get_history(instrument='EUR_USD',
                  start='2022-05-22 09:00 ',
                  end='2022-05-23 12:00',
                  granularity='M5',
                  price='M')

4. Ordering

Wherever order_target is used, you need to change to the create_order method of oanda.
 
oanda.create_order('EUR_USD', units=100)

Here the number of units is specified compared to the order target which specified the percentage of the capital required to place an order.


I hope this helps.


 

Thank you Ishan, your workfolw clarified many points. 

Thank you very much