-
Notifications
You must be signed in to change notification settings - Fork 29
/
KotlinUsageSample.kt
202 lines (185 loc) · 7.15 KB
/
KotlinUsageSample.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package io.polygon.kotlin.sdk.sample
import com.tylerthrailkill.helpers.prettyprint.pp
import io.ktor.client.plugins.*
import io.polygon.kotlin.sdk.DefaultOkHttpClientProvider
import io.polygon.kotlin.sdk.HttpClientProvider
import io.polygon.kotlin.sdk.rest.*
import io.polygon.kotlin.sdk.rest.crypto.CryptoDailyOpenCloseParameters
import io.polygon.kotlin.sdk.rest.experimental.ExperimentalAPI
import io.polygon.kotlin.sdk.rest.experimental.FinancialsParameters
import io.polygon.kotlin.sdk.rest.forex.RealTimeConversionParameters
import io.polygon.kotlin.sdk.rest.indices.SnapshotIndicesParameters
import io.polygon.kotlin.sdk.rest.options.SnapshotChainParameters
import io.polygon.kotlin.sdk.rest.reference.*
import io.polygon.kotlin.sdk.rest.stocks.GainersOrLosersDirection
import io.polygon.kotlin.sdk.websocket.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import okhttp3.Interceptor
import okhttp3.Response
import kotlin.system.exitProcess
val okHttpClientProvider: HttpClientProvider
get() = DefaultOkHttpClientProvider(
applicationInterceptors = listOf(object : okhttp3.Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
println("Intercepting application level")
println("request: ${chain.request().url}")
return chain.proceed(chain.request())
}
}),
networkInterceptors = listOf(object : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
println("Intercepting network level")
return chain.proceed(chain.request())
}
})
)
suspend fun main() {
val polygonKey = System.getenv("POLYGON_API_KEY")
if (polygonKey.isNullOrEmpty()) {
println("Make sure you set your polygon API key in the POLYGON_API_KEY environment variable!")
exitProcess(1)
}
val polygonClient = PolygonRestClient(
polygonKey,
httpClientProvider = okHttpClientProvider
)
/**
* Stocks REST - access to stocks data depends on your entitlements
*/
//stocksAggregatesBars(polygonClient)
//stocksConditions(polygonClient)
//stocksDailyOpenClose(polygonClient)
//stocksDividends(polygonClient)
//stocksExchanges(polygonClient)
//stocksGroupedDailyBars(polygonClient)
//stocksLastQuote(polygonClient)
//stocksLastTrade(polygonClient)
//stocksMarketHolidays(polygonClient)
//stocksMarketStatus(polygonClient)
//stocksPreviousClose(polygonClient)
//stocksQuotes(polygonClient)
//stocksSnapshotsAll(polygonClient)
//stocksSnapshotsGainersLosers(polygonClient)
//stocksSnapshotsTicker(polygonClient)
//stocksStockFinancials(polygonClient) // not working yet
//stocksStockSplits(polygonClient)
//stocksTechnicalIndicatorsEMA(polygonClient)
//stocksTechnicalIndicatorsMACD(polygonClient)
//stocksTechnicalIndicatorsRSI(polygonClient)
//stocksTechnicalIndicatorsSMA(polygonClient)
//stocksTickerDetails(polygonClient)
//stocksTickerEvents(polygonClient)
//stocksTickerNews(polygonClient)
//stocksTickerTypes(polygonClient)
//stocksTickers(polygonClient)
//stocksTrades(polygonClient)
//universalSnapshot(polygonClient)
/**
* Stocks WebSocket - access to streaming stocks data depends on your entitlements
*/
//stocksWebsocketSample(polygonKey)
/**
* Options REST - access to options data depends on your entitlements
*/
//optionsAggregatesBars(polygonClient)
//optionsConditions(polygonClient)
//optionsContract(polygonClient)
//optionsContracts(polygonClient)
//optionsDailyOpenClose(polygonClient)
//optionsExchanges(polygonClient)
//optionsLastTrade(polygonClient)
//optionsMarketHolidays(polygonClient)
//optionsMarketStatus(polygonClient)
//optionsPreviousClose(polygonClient)
//optionsQuotes(polygonClient)
//optionsSnapshotsOptionContract(polygonClient)
//optionsSnapshotsOptionsChain(polygonClient)
//optionsTechnicalIndicatorsEMA(polygonClient)
//optionsTechnicalIndicatorsMACD(polygonClient)
//optionsTechnicalIndicatorsRSI(polygonClient)
//optionsTechnicalIndicatorsSMA(polygonClient)
//optionsTickerDetails(polygonClient)
//optionsTickerNews(polygonClient)
//optionsTickers(polygonClient)
//optionsTrades(polygonClient)
/**
* Options WebSocket - access to streaming options data depends on your entitlements
*/
//optionsWebsocketSample(polygonKey)
/**
* Indices REST - access to indices data depends on your entitlements
*/
//indicesAggregatesBars(polygonClient)
//indicesDailyOpenClose(polygonClient)
//indicesMarketHolidays(polygonClient)
//indicesMarketStatus(polygonClient)
//indicesPreviousClose(polygonClient)
//indicesSnapshots(polygonClient)
//indicesTechnicalIndicatorsEMA(polygonClient)
//indicesTechnicalIndicatorsMACD(polygonClient)
//indicesTechnicalIndicatorsRSI(polygonClient)
//indicesTechnicalIndicatorsSMA(polygonClient)
//indicesTickerTypes(polygonClient)
//indicesTickers(polygonClient)
/**
* Indices WebSocket - access to streaming indices data depends on your entitlements
*/
//indicesWebsocketSample(polygonKey)
/**
* Forex REST - access to forex data depends on your entitlements
*/
//forexAggregatesBars(polygonClient)
//forexConditions(polygonClient)
//forexExchanges(polygonClient)
//forexGroupedDailyBars(polygonClient)
//forexLastQuoteForCurrencyPair(polygonClient)
//forexMarketHolidays(polygonClient)
//forexMarketStatus(polygonClient)
//forexPreviousClose(polygonClient)
//forexQuotes(polygonClient)
//forexRealTimeCurrencyConversion(polygonClient)
//forexSnapshotsAllTickers(polygonClient)
//forexSnapshotsGainersLosers(polygonClient)
//forexSnapshotsTicker(polygonClient) // not working yes
//forexTechnicalIndicatorsEMA(polygonClient)
//forexTechnicalIndicatorsMACD(polygonClient)
//forexTechnicalIndicatorsRSI(polygonClient)
//forexTechnicalIndicatorsSMA(polygonClient)
//forexTickers(polygonClient)
/**
* Forex WebSocket - access to streaming forex data depends on your entitlements
*/
//forexWebsocketSample(polygonKey)
/**
* Crypto REST - access to crypto data depends on your entitlements
*/
//cryptoAggregatesBars(polygonClient)
//cryptoConditions(polygonClient)
//cryptoDailyOpenClose(polygonClient)
//cryptoExchanges(polygonClient)
//cryptoGroupedDailyBars(polygonClient)
//cryptoLastTradeForCryptoPair(polygonClient)
//cryptoMarketHolidays(polygonClient)
//cryptoMarketStatus(polygonClient)
//cryptoPreviousClose(polygonClient)
//cryptoSnapshotsAllTickers(polygonClient)
//cryptoSnapshotsGainersLosers(polygonClient)
//cryptoSnapshotsTicker(polygonClient)
//cryptoSnapshotsTickerFullBookL2(polygonClient)
//cryptoTechnicalIndicatorsEMA(polygonClient)
//cryptoTechnicalIndicatorsMACD(polygonClient)
//cryptoTechnicalIndicatorsRSI(polygonClient)
//cryptoTechnicalIndicatorsSMA(polygonClient)
//cryptoTickers(polygonClient)
//cryptoTrades(polygonClient)
/**
* Crypto WebSocket - access to streaming crypto data depends on your entitlements
*/
//cryptoWebsocketSample(polygonKey)
/**
* Launchpad WebSocket - access to streaming launchpad data depends on your entitlements
*/
//launchpadWebsocketSample(polygonKey)
}