Scala REST client API for the Questrade trading platform http://www.questrade.com/api/documentation
TODO: Show what the library does as concisely as possible, developers should be able to figure out how your project solves their problem by looking at the code example. Make sure the API you are showing off is obvious, and that your code is short and concise.
After searching around for a Java/Scala client adapter for the Questrade API it became apparent that one did not exist yet. While there were projects in Python12, Node.js3 and Ruby4, I was not able to locate a Java/Scala based solution. This project exists to provide a Scala language client for the Questrade API, to enable AKKA and Play based projects.
This package currently includes the following features:
- Wrappers for all Account calls
- Error handling and logging
- Wrappers for all Market calls
- Wrappers for all Order calls
- Deploy the library to Maven Central
- Streaming quotes
- OAuth 2.0 API requests via HTTPS (TLS)
- Automatically request new access tokens via refresh tokens when necessary
To check your version of Java, open the terminal and type:
java -version
If you don't have version 1.8 you can download Java here
Install Scala, either by installing an IDE (such as IntelliJ), or Scala's build tool (sbt).
See https://www.scala-lang.org/download/2.12.3.html
for full details.
Set up a practice account to play around:
http://www.questrade.com/api/free-practice-account
Login with it at:
https://practicelogin.questrade.com/Signin.aspx?ReturnUrl=%2fAPIAccess%2fUserApps.aspx
Register a practice app (give it all permissions, this is a test account)
Generate a new device authorization token, you'll need that! It's considered a "refresh" token. After being used once, it's good no more, but you will get a new refresh token in the response.
git clone git@github.com:elcurto99/scala-questrade.git
- IntelliJ IDEA > File > New > Project from Existing Sources...
- Open the directory we just checked out
- Import Project from SBT
- Create project from existing sources
- Click Next through the setup modal to finish the setup
Update the value for questrade.api.refreshToken
in /test/resources/application.conf
with your own freshly generated practice account refresh token.
Navigate to the projects directory in a Terminal
cd ~/scala-questrade/
Run the tests from sbt
sbt test
The Unit & Integration tests will run
[info] QuestradeClientUnitTests:
[info] The Questrade API client
[info] - should authenticate with the server
[info] - should retrieve the current server time
[info] - should retrieve the accounts list
[info] - should retrieve the positions for an account
[info] - should retrieve the balances for an account
[info] should retrieve the account executions that
[info] - occurred today
[info] - occurred from a date
[info] - occurred in a date range
[info] - occurred across the daylight savings boundary (UTC-5 => UTC-4)
[info] should retrieve the account orders that
[info] - occurred today
[info] - occurred from a date
[info] - occurred in a date range
[info] - occurred across the daylight savings boundary (UTC-5 => UTC-4)
[info] - have a specific state
[info] - have a specific orderId
[info] - should retrieve a single order for an account
[info] should retrieve account activities that
[info] - occurred from a date
[info] - occurred in a date range
[info] - occurred over the API maximum of 31 days
[info] - occurred across the daylight savings boundary (UTC-5 => UTC-4)
[info] - occurred across the daylight savings boundary (UTC-4 => UTC-5)
[info] should throw an exception
[info] - when getting account activities with a start date in the future
[info] QuestradeClientIntegrationTests:
[info] The Questrade API client
[info] - should authenticate with the server
[info] - should retrieve the current server time
[info] - should retrieve the accounts list
[info] - should retrieve the positions for an account
[info] - should retrieve the balances for an account
[info] should retrieve the account executions that
[info] - occurred today
[info] - occurred from a date
[info] - occurred in a date range
[info] should retrieve the account orders that
[info] - occurred today
[info] - occurred from a date
[info] - occurred in a date range
[info] - have a specific state
[info] - have a specific orderId
[info] - should retrieve a single order for an account
[info] should retrieve the account activities that
[info] - occurred from a date
[info] - occurred under the API maximum of 31 days
[info] - occurred over the API maximum of 31 days
[info] - occurred over the API maximum of 31 days up until now
[info] Run completed in 13 seconds, 504 milliseconds.
[info] Total number of tests run: 40
[info] Suites: completed 2, aborted 0
[info] Tests: succeeded 40, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 29 s, completed 7-Sep-2017 7:03:21 AM
To include this as a dependency in a SBT project:
Add this build.properties
file to your /project/
directory.
sbt.version = 0.13.16
Add this Build.scala
field to your /project/
directory.
import sbt._
object MyBuild extends Build {
lazy val root = Project("root", file(".")) dependsOn(apiClient)
lazy val apiClient = RootProject(uri("git://github.com/elcurto99/scala-questrade.git#master"))
}
Now we can use the API client as a dependency in our project:
import elcurto99.scalaquestrade.QuestradeClient
object Test extends App {
val apiClient = new QuestradeClient()
val login = apiClient.login("https://practicelogin.questrade.com/", "AbCdefGhIjKlmnoPQrStUvwXYzOP1234567890")
val accounts = apiClient.getAccounts(login.access_token, login.api_server)
}
SemVer is used for versioning. For the versions available, see the tags on this repository.
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details
This software is not affiliated with Questrade in any way. Use at your own risk. Test all operations in a sandbox before executing them with a real account and real money. Don't be an idiot.