Robinhood API Client Library.
This library leverages Retrofit2, Gson and Kotlin to wrap the Unofficial Robinhood REST API.
Initial implementation for the Cryptocurrency endpoints is available. If there is interest the remaining endpoints could also be supported.
Usage
Artifacts are published on maven:
<dependency>
<groupId>com.willwinder.robinhood4j</groupId>
<artifactId>robinhood4j</artifactId>
<version>0.1</version>
</dependency>
API access is done through through the ApiClient
object:
ApiClient client = new ApiClient(<login>, <password>, <cached login-token or null>);
Call<Results<CryptoQuote>> call = client.getCryptoQuotes().getQuoteSymbols("ETHUSD");
Response<Results<CryptoQuote>> response = call.execute();
Results<CryptoQuote> result = response.body();
Example Kotlin code to make a limit purchase of 0.25 etherium at trading value of $600/ETH:
val quote = apiClient.cryptoQuotes.getQuote("ETHUSD").execute().body()!!
val pair = apiClient.crypto.getCurrencyPair(quote.id).execute().body()!!
apiClient.crypto.makeOrder(RobinhoodCryptoApi.OrderParameters(
OrderSide.SELL,
pair.id,
600.0,
0.25,
UUID.randomUUID().toString(),
TimeInForce.GTC,
OrderType.LIMIT
))
Unit Tests
Due to the nature of this API unit tests cannot be run without configuring your access credentials. Credentials must be stored as encrypted Base64 encoded environment variables, all of the code which accesses these variables can be seen in TestParent.kt, you are encouraged to thoroughly inspect this code.
Encrypted strings can be generated and setup as follows:
- Navigate to ./src/test/kotlin/com/willwinder/robinhood4j/utils/TestParent.kt
- Comment out the
init
section to prevent initializing a useless ApiClient. - Replace
LOGIN_HERE
andPASSW_HERE
with your credentials. - Run the
generateEncryption
test. - Set the resulting 24 character strings as
robinhood_login
androbinhood_password
environment variables. - Un-comment the
init
section. You should now be able to run tests.