Skip to content

Getting Started

Pim Feltkamp edited this page Apr 27, 2026 · 1 revision

Getting Started

This page walks you from zero to a first authenticated call against the Cryptohopper API in Kotlin.

Install

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 publishToMavenLocal

Then 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.

Platform support

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.

Your first call

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

Common pitfalls

  • JsonElement? returns — every resource method returns kotlinx.serialization.json.JsonElement?. Use .jsonObject, .jsonArray, .jsonPrimitive, or pattern-match with when. The README and the per-resource KDoc tell you what to expect for each endpoint.
  • Client is 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 new Client per request leaks file descriptors.
  • Client.create(...) validates eagerly — passing an empty apiKey throws IllegalArgumentException at 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.Call is cancelled cleanly; no goroutine-style leaks.

Next steps

  • Authentication — token handling, env vars, Android Keystore
  • Error HandlingCryptohopperError codes and when patterns
  • Rate Limits — what 429 means and how the SDK handles it
  • Recipes — copyable patterns: backtest polling, structured-concurrency fan-out, custom OkHttp, MockWebServer testing

Clone this wiki locally