-
Notifications
You must be signed in to change notification settings - Fork 29
/
KotlinIteratorSample.kt
41 lines (34 loc) · 1.51 KB
/
KotlinIteratorSample.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package io.polygon.kotlin.sdk.sample
import io.polygon.kotlin.sdk.rest.PolygonRestClient
import io.polygon.kotlin.sdk.rest.QuotesParameters
import io.polygon.kotlin.sdk.rest.TradesParameters
import io.polygon.kotlin.sdk.rest.reference.SupportedTickersParameters
fun iteratorExample(polygonClient: PolygonRestClient) {
println("10 Supported Tickers:")
val params = SupportedTickersParameters(
sortBy = "ticker",
sortDescending = false,
market = "stocks",
limit = 3
)
// Take only the first 10 so this sample ends quickly.
// Note that since the limit = 3 in the params,
// this iterator will make 4 requests under the hood
polygonClient.referenceClient.listSupportedTickers(params).asSequence()
.take(10)
.forEachIndexed { index, tickerDTO -> println("${index}: ${tickerDTO.ticker}") }
}
fun tradesIteratorExample(polygonClient: PolygonRestClient) {
println("Running trade iterator:")
val params = TradesParameters(limit = 1)
polygonClient.listTrades("F", params).asSequence()
.take(2)
.forEachIndexed { index, tradeRes -> println("${index}: ${tradeRes.price}") }
}
fun quotesIteratorExample(polygonClient: PolygonRestClient) {
println("Running quote iterator:")
val params = QuotesParameters(limit = 1)
polygonClient.listQuotes("F", params).asSequence()
.take(2)
.forEachIndexed { index, quoteRes -> println("${index}: (${quoteRes.participantTimestamp}) | ${quoteRes.bidPrice} / ${quoteRes.askPrice}") }
}