Coder Social home page Coder Social logo

scalanda-v20's Introduction

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.

Join the chat at https://gitter.im/scalanda-v20/Lobby Maven Central Travis Codecov

scalanda-v20

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.

Install

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"

Usage

For the full description of Oanda's REST and Stream APIs please consult their great documentation.

Creating a new client

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.

Usage examples

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.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT License

scalanda-v20's People

Contributors

gitter-badger avatar msilb avatar ylaurent avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.