Note: this is Scala wrapper for Oanda REST API v1. If you are looking for a Scala wrapper for the newer Oanda REST API v2, please have a look at the scalanda-v20 project.
Scalanda is a light-weight Scala/Akka/Spray-based wrapper for Oanda's REST and Stream APIs, 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.
If you are using sbt
just drop this dependency into your build.sbt
:
libraryDependencies += "com.msilb" %% "scalanda" % "0.3.7"
For the full description of Oanda's REST and Stream APIs please consult their great documentation.
From within your Akka system instantiate the REST connector actor like this:
val restConnector = system.actorOf(RestConnector.props(Practice, Some(authTokenPractice), practiceAccountId))
where:
Practice
indicates you want to connect to Oanda's fxTrade Practice environment. Other possible values areSandBox
andProduction
.authTokenPractice
is your Personal Access Token. For details how to obtain one, please see here. Note:SandBox
environment does not require authentication, hence just useNone
practiceAccountId
is your fxTrade Practice account ID.
After creating an instance of the REST connector you can use it from within your trading actors to send requests to the API, e.g. to create a market order to buy 10,000 units of EUR/USD send this message to your restConnector
:
restConnector ! CreateOrderRequest("EUR_USD", 10000, Buy, Market)
Once the request is completed restConnector
will reply with an instance of CreateOrderResponse
containing details of the successfully created trade. Check out the full list of possible request and response types.
Create a new connector actor for the Stream API and send Connect
message to it:
val streamingConnector = system.actorOf(StreamingConnector.props)
streamingConnector ! Connect(Practice, Some(authTokenPractice))
then wait until streamingConnector
responds with the ConnectionEstablished
message. Register listeners that should be notified of price tick or event updates by sending
streamingConnector ! AddListeners(Set(listener1, listener2, listener3))
to the streamingConnector
.
Finally, subscribe for the price stream with
streamingConnector ! StartRatesStreaming(accountId, instruments, sessionIdOpt)
or for the events stream with
streamingConnector ! StartEventsStreaming(accountIdsOpt)
For further information on request / response parameters see Oanda Stream API specification.
- 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