-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Pim Feltkamp edited this page Apr 27, 2026
·
1 revision
This page walks you from zero to a first authenticated call against the Cryptohopper API in Kotlin.
Maven Central publishing is pending the first stable release. Until then, build from source:
git clone https://github.com/cryptohopper/cryptohopper-kotlin-sdk
cd cryptohopper-kotlin-sdk
./gradlew publishToMavenLocalThen depend on it from your project's build.gradle.kts:
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation("com.cryptohopper:cryptohopper:0.1.0-alpha.1")
}Once Maven Central is set up, the local-publish step disappears — mavenCentral() will resolve com.cryptohopper:cryptohopper directly.
| Target | Minimum |
|---|---|
| Kotlin | 2.3 |
| JVM | 17 |
| Android | API 26 (minSdk = 26) |
| Java interop | 17+ |
The artifact is plain JVM — works on Android and on server-side Kotlin / Java alike. There's no Android-only artifact.
import com.cryptohopper.Client
import kotlinx.coroutines.runBlocking
fun main() = runBlocking {
val token = System.getenv("CRYPTOHOPPER_TOKEN")
?: error("Set CRYPTOHOPPER_TOKEN to a 40-char OAuth bearer first.")
val ch = Client.create(token)
val me = ch.user.get()
println("Logged in as $me")
val ticker = ch.exchange.ticker(exchange = "binance", market = "BTC/USDT")
println("BTC/USDT: $ticker")
}Run with:
export CRYPTOHOPPER_TOKEN=your-40-char-bearer
./gradlew run-
JsonElement?returns — every resource method returnskotlinx.serialization.json.JsonElement?. Use.jsonObject,.jsonArray,.jsonPrimitive, or pattern-match withwhen. The README and the per-resource KDoc tell you what to expect for each endpoint. -
Clientis safe to share across coroutines — under the hood it owns one OkHttp connection pool. Build it once at startup and reuse for the lifetime of your process. Building a newClientper request leaks file descriptors. -
Client.create(...)validates eagerly — passing an emptyapiKeythrowsIllegalArgumentExceptionat construction, not on the first request. That's intentional: fail fast rather than silently issue unauthenticated calls. -
Coroutine cancellation propagates — cancelling the surrounding scope cancels the in-flight HTTP request. Underlying
okhttp3.Callis cancelled cleanly; no goroutine-style leaks.
- Authentication — token handling, env vars, Android Keystore
-
Error Handling —
CryptohopperErrorcodes andwhenpatterns - Rate Limits — what 429 means and how the SDK handles it
- Recipes — copyable patterns: backtest polling, structured-concurrency fan-out, custom OkHttp, MockWebServer testing