Note: this is Scala wrapper for Oanda REST API v2. If you are looking for a Scala wrapper for the older Oanda REST API v1, please have a look at the scalanda project.
scalanda-v20 is a light-weight Scala/Akka HTTP based client for Oanda's REST and Stream API v20, which supports completely asynchronous non-blocking communication with the API. If you are using (or planning to use) Oanda as a broker for your automated trading needs, this library might be of interest.
scalanda-v20
is compiled for Scala 2.12. If you are using sbt
just drop this dependency into your build.sbt
and you should be good to go.
libraryDependencies += "com.msilb" %% "scalanda-v20" % "0.1.5"
For the full description of Oanda's REST and Stream APIs please consult their great documentation.
Create new instance of the API client using your auth bearer token:
val client = new OandaApiClient(Practice, "YOUR_AUTH_BEARER_TOKEN")
where Practice
indicates that you want to connect to Oanda's fxTrade Practice environment. Other possible value is Production
for live trading.
Here is a quick example of how to fetch historical data and place a limit order at the high of the previous candle:
val orderIdFut = for {
candlesticks <- client.getCandlesticks(
"EUR_USD",
granularity = Some(H1),
count = Some(4),
includeFirst = Some(false)
).collect { case Right(r) => r.candles.filter(_.complete) }
marketOrder <- client.createOrder(
accountId,
CreateOrderRequest(
LimitOrderRequest(
instrument = "EUR_USD",
price = candlesticks.last.mid.get.h,
units = -1500,
takeProfitOnFill = Some(TakeProfitDetails(price = "1.09"))
)
)
).collect { case Right(r) => r }
} yield marketOrder match {
case r: CreateOrderSuccessResponse => r.orderCreateTransaction.id
case r: CreateOrderFailureResponse => throw new RuntimeException(r.errorMessage)
}
println("New Limit Order created @ previous high with order ID " + Await.result(orderIdFut, Duration.Inf))
Further sample requests can be found here.
For more detailed information on request / response parameters see Oanda API specs, e.g. specs for the accounts endpoint.
- Fork it!
- Create your feature branch: git checkout -b my-new-feature
- Commit your changes: git commit -am 'Add some feature'
- Push to the branch: git push origin my-new-feature
- Submit a pull request :D