This project is an attepmt to bring research, backtest, trading, and monitoring using R wrapper around OANDA broker's HTTP API . It was motivated by a need to quickly turn research in to executable trades. There are three components:
- Prerequisites: Ensure that the following packages are installed
> install.packages(c("curl","jsonlite","devtools")) # only the package
> install.packages(c("curl","jsonlite","devtools","shiny","shinythemes","ini")) # package + dashboard
> install.packages(c("curl","jsonlite","devtools","shiny","shinythemes","ini","zoo")) #package + dashboard + demo backtest & toy algo trading
- Install oanda's api
> library(devtools)
> install_github(repo="ltekengineering/oanda", subdir="oanda")
- Additional features:
foo@bar: git clone git@github.com:ltekengineering/oanda.git
-
Implementation of the trading API in R for algorithmic trading. A complete tutorial is here.
> library(oanda)
- Point to the practice account and authenticate with code generated on https://www1.oanda.com/demo-account/login
> oanda.init("practice",'44667a4c1a94db7f245ea21fe2f82341-04efe2ed548b91e6bb2d7d7707668d8a')
> eur_usd <- oanda.instruments.bid("EUR_USD","M1",from = "1608064200") #2020-12-15 03:30 PM > usd_cad <- oanda.instruments.bid("USD_CAD","S5",from="2020-12-15T15:30:00") #with a resolution of 5 seconds > head(usd_cad$candles) complete volume time b_o b_h b_l b_c 1 TRUE 2 1608064200 1.26891 1.26891 1.26890 1.26890 2 TRUE 1 1608064210 1.26887 1.26887 1.26887 1.26887 3 TRUE 1 1608064215 1.26889 1.26889 1.26889 1.26889 4 TRUE 2 1608064230 1.26892 1.26892 1.26889 1.26889 5 TRUE 2 1608064245 1.26891 1.26891 1.26890 1.26890 6 TRUE 2 1608064260 1.26891 1.26891 1.26889 1.26889 > libray(plotly) > usd_cad$candles$time <- as.POSIXct(usd_cad$candles$time,origin="1970-01-01") > fig <- usd_cad$candles[1:50,] %>% plot_ly(x = ~time, type="candlestick",open = ~b_o, close = ~b_c, high = ~b_h, low = ~b_l) > fig <- fig %>% layout(title = "USD/CAD Candlestick Chart: Bid") > fig
> oanda.orders.createMarketOrder('101-001-3704066-001',"USD_MXN",10000) #long 10000 USD/MXN > oanda.orders.createMarketOrder('101-001-3704066-001',"USD_MXN",-10000) #short 10000 USD/MXN > oanda.orders.createMarketOrder('101-001-3704066-001',"USD_MXN",10000,priceBound=19.86263) #worst pirce of 19.86263 else kill the order > info <- oanda.orders.createClientExtensions("A comment","strategy_9","my_order_10000") > oanda.orders.createMarketOrder('101-001-3704066-001',"USD_MXN",10000,priceBound=19.86263, info) #add customization
- Point to the practice account and authenticate with code generated on https://www1.oanda.com/demo-account/login
- A shiny app to monitor account activity in real time. Visit the wiki page for a detailed tutorial.
- Go to dashboard directory
foo@bar: cd dasboard
- Edit token and accounts parameters in config_ppe.ini or config_prod.ini with your token and account numbers
- Start the dashboard
foo@bar: ln -s config_ppe.ini config.ini
foo@bar: Rscript --no-save dash.r
Point to config_prod.ini when you're ready to go live
- Go here http://localhost:8989/
- Back-testing demo scripts have been removed