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.Note: this is Scala wrapper for
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
libraryDependencies += "com.msilb" %% "scalanda" % "0.3.7"
For the full description of Oanda's REST and Stream APIs please consult their great documentation.
Creating an Instance of the REST Connector
From within your Akka system instantiate the REST connector actor like this:
val restConnector = system.actorOf(RestConnector.props(Practice, Some(authTokenPractice), practiceAccountId))
Practiceindicates you want to connect to Oanda's fxTrade Practice environment. Other possible values are
authTokenPracticeis your Personal Access Token. For details how to obtain one, please see here. Note:
SandBoxenvironment does not require authentication, hence just use
practiceAccountIdis your fxTrade Practice account ID.
Sending Requests to the REST Connector
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 ! 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.
Subscribing for Price and Event Streams Using the Stream API
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))
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