alpaca-kotlin
0.0.11indexedFacilitates interaction with Alpaca Trading API for account management, order placement, and real-time data streaming, including historical trade data access and test mode for simulating stock prices.
Facilitates interaction with Alpaca Trading API for account management, order placement, and real-time data streaming, including historical trade data access and test mode for simulating stock prices.
A Kotlin Multiplatform library for interacting with the Alpaca Trading API.
Add the following to your build.gradle.kts file:
dependencies {
implementation("io.github.jeffreyliu8:alpaca-kotlin:0.0.11")
}
Please check out the test file here https://github.com/jeffreyliu8/alpaca-kotlin/blob/main/library/src/commonTest/kotlin/MyCommonUnitTest.kt
import alpaca.AlpacaClient
import alpaca.AlpacaClientImpl
// For paper trading
val client: AlpacaClient = AlpacaClientImpl(
isPaper = false,
apiKey = apiKey,
apiSecret = apiSecret,
)
liveClient = AlpacaClientImpl(
isPaper = ,
apiKey = apiKey,
apiSecret = apiSecret,
)
account = client.getAccount()
println(account)
positions = client.getPositions()
println(positions)
order = client.placeOrder(
AlpacaOrderRequest(
symbol = ,
qty = ,
side = AlpacaBuySell.BUY,
type = ,
timeInForce =
)
)
println(order)
You can stream account updates and stock prices using Kotlin Flows.
runBlocking {
launch {
client.streamAccount().collect { accountUpdate ->
println("Received account update: $accountUpdate")
}
}
}
runBlocking {
launch {
client.monitorStockPrice(setOf("AAPL", "GOOG")).collect { stockPriceUpdate ->
println("Received stock price update: $stockPriceUpdate")
}
}
}
You can use the test mode to get a fake stock price for testing purposes.
runBlocking {
client.monitorStockPrice(
setOf("FAKEPACA"),
stockExchange = AlpacaStockExchangeOption.TEST
).collect {
println(it)
}
}
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
Use ./gradlew publishToMavenCentral to make a new release
Surfaced from shared tags and platforms — no rankings paid for.