Skip to content

Commit 5c86678

Browse files
fix kt example
1 parent be8cda6 commit 5c86678

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

  • examples/consumer-test/src/main/kotlin/com/marketdata/examples

examples/consumer-test/src/main/kotlin/com/marketdata/examples/Quickstart.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import com.marketdata.sdk.stocks.StockQuoteRequest
1414
* Run: `./gradlew runKotlinQuickstart`
1515
*/
1616
fun main() {
17-
// `use {}` closes the client when the block ends — the Kotlin equivalent of try-with-resources.
18-
MarketDataClient().use { client ->
19-
try {
17+
try {
18+
// `use {}` closes the client when the block ends — the Kotlin equivalent of try-with-resources.
19+
// Construction is inside the `try` so the no-arg constructor's startup validation (a real
20+
// `/user/` probe) is covered by the catch below on a missing/expired token.
21+
MarketDataClient().use { client ->
2022
// Sync: blocks and returns the typed response.
2123
val quote = client.stocks().quote(StockQuoteRequest.of("AAPL")).values()[0]
2224
println("Sync: ${quote.symbol()} last=${quote.last()}")
@@ -27,8 +29,8 @@ fun main() {
2729
.quoteAsync(StockQuoteRequest.of("AAPL"))
2830
.thenAccept { resp -> println("Async: ${resp.values()[0].last()}") }
2931
.join()
30-
} catch (e: AuthenticationError) {
31-
println("Set MARKETDATA_TOKEN (env var or .env) to run this example.")
3232
}
33+
} catch (e: AuthenticationError) {
34+
println("Set MARKETDATA_TOKEN (env var or .env) to run this example.")
3335
}
3436
}

0 commit comments

Comments
 (0)