-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update WebSocket message parsing and types w/ feedback updates (#122)
* Update WebSocket message parsing and types
- Loading branch information
1 parent
c92592d
commit 23166d0
Showing
11 changed files
with
587 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
sample/src/main/java/io/polygon/kotlin/sdk/sample/KotlinCryptoWebsocketSample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.polygon.kotlin.sdk.sample | ||
|
||
import io.polygon.kotlin.sdk.websocket.* | ||
import kotlinx.coroutines.delay | ||
|
||
suspend fun cryptoWebsocketSample(polygonKey: String) { | ||
val websocketClient = PolygonWebSocketClient( | ||
polygonKey, | ||
Feed.RealTime, | ||
Market.Crypto, | ||
object : PolygonWebSocketListener { | ||
override fun onAuthenticated(client: PolygonWebSocketClient) { | ||
println("Connected!") | ||
} | ||
|
||
override fun onReceive( | ||
client: PolygonWebSocketClient, | ||
message: PolygonWebSocketMessage | ||
) { | ||
when (message) { | ||
is PolygonWebSocketMessage.RawMessage -> println(String(message.data)) | ||
else -> println("Receieved Message: $message") | ||
} | ||
} | ||
|
||
override fun onDisconnect(client: PolygonWebSocketClient) { | ||
println("Disconnected!") | ||
} | ||
|
||
override fun onError(client: PolygonWebSocketClient, error: Throwable) { | ||
println("Error: ") | ||
error.printStackTrace() | ||
} | ||
|
||
}) | ||
|
||
val subscriptions = listOf( | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Crypto.Trades, "ETH-USD"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Crypto.Trades, "BTC-USD") | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Crypto.Trades, "*"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Crypto.Quotes, "*"), | ||
PolygonWebSocketSubscription(PolygonWebSocketChannel.Crypto.AggPerSecond, "*"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Crypto.AggPerMinute, "*") | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Crypto.Level2Books, "*") | ||
) | ||
|
||
websocketClient.connect() | ||
websocketClient.subscribe(subscriptions) | ||
delay(65_000) | ||
websocketClient.unsubscribe(subscriptions) | ||
websocketClient.disconnect() | ||
} |
48 changes: 48 additions & 0 deletions
48
sample/src/main/java/io/polygon/kotlin/sdk/sample/KotlinForexWebsocketSample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.polygon.kotlin.sdk.sample | ||
|
||
import io.polygon.kotlin.sdk.websocket.* | ||
import kotlinx.coroutines.delay | ||
|
||
suspend fun forexWebsocketSample(polygonKey: String) { | ||
val websocketClient = PolygonWebSocketClient( | ||
polygonKey, | ||
Feed.RealTime, | ||
Market.Forex, | ||
object : PolygonWebSocketListener { | ||
override fun onAuthenticated(client: PolygonWebSocketClient) { | ||
println("Connected!") | ||
} | ||
|
||
override fun onReceive( | ||
client: PolygonWebSocketClient, | ||
message: PolygonWebSocketMessage | ||
) { | ||
when (message) { | ||
is PolygonWebSocketMessage.RawMessage -> println(String(message.data)) | ||
else -> println("Receieved Message: $message") | ||
} | ||
} | ||
|
||
override fun onDisconnect(client: PolygonWebSocketClient) { | ||
println("Disconnected!") | ||
} | ||
|
||
override fun onError(client: PolygonWebSocketClient, error: Throwable) { | ||
println("Error: ") | ||
error.printStackTrace() | ||
} | ||
|
||
}) | ||
|
||
val subscriptions = listOf( | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Forex.Quotes, "*"), | ||
PolygonWebSocketSubscription(PolygonWebSocketChannel.Forex.AggPerSecond, "*"), | ||
PolygonWebSocketSubscription(PolygonWebSocketChannel.Forex.AggPerMinute, "*"), | ||
) | ||
|
||
websocketClient.connect() | ||
websocketClient.subscribe(subscriptions) | ||
delay(65_000) // make sure we get a agg minute | ||
websocketClient.unsubscribe(subscriptions) | ||
websocketClient.disconnect() | ||
} |
49 changes: 49 additions & 0 deletions
49
sample/src/main/java/io/polygon/kotlin/sdk/sample/KotlinIndicesWebsocketSample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.polygon.kotlin.sdk.sample | ||
|
||
import io.polygon.kotlin.sdk.websocket.* | ||
import kotlinx.coroutines.delay | ||
|
||
suspend fun indicesWebsocketSample(polygonKey: String) { | ||
val websocketClient = PolygonWebSocketClient( | ||
polygonKey, | ||
Feed.RealTime, | ||
Market.Indices, | ||
object : PolygonWebSocketListener { | ||
override fun onAuthenticated(client: PolygonWebSocketClient) { | ||
println("Connected!") | ||
} | ||
|
||
override fun onReceive( | ||
client: PolygonWebSocketClient, | ||
message: PolygonWebSocketMessage | ||
) { | ||
when (message) { | ||
is PolygonWebSocketMessage.RawMessage -> println(String(message.data)) | ||
else -> println("Receieved Message: $message") | ||
} | ||
} | ||
|
||
override fun onDisconnect(client: PolygonWebSocketClient) { | ||
println("Disconnected!") | ||
} | ||
|
||
override fun onError(client: PolygonWebSocketClient, error: Throwable) { | ||
println("Error: ") | ||
error.printStackTrace() | ||
} | ||
|
||
}) | ||
|
||
val subscriptions = listOf( | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Indices.Value, "*"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Indices.Value, "I:NDX"), | ||
PolygonWebSocketSubscription(PolygonWebSocketChannel.Indices.AggPerSecond, "I:SPX") | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Indices.AggPerMinute, "I:SPX") | ||
) | ||
|
||
websocketClient.connect() | ||
websocketClient.subscribe(subscriptions) | ||
delay(65_000) | ||
websocketClient.unsubscribe(subscriptions) | ||
websocketClient.disconnect() | ||
} |
53 changes: 53 additions & 0 deletions
53
sample/src/main/java/io/polygon/kotlin/sdk/sample/KotlinLaunchpadWebsocketSample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.polygon.kotlin.sdk.sample | ||
|
||
import io.polygon.kotlin.sdk.websocket.* | ||
import kotlinx.coroutines.delay | ||
|
||
suspend fun launchpadWebsocketSample(polygonKey: String) { | ||
val websocketClient = PolygonWebSocketClient( | ||
polygonKey, | ||
Feed.LaunchpadFeed, | ||
Market.LaunchpadStocks, // replace with LaunchpadCrypto, LaunchpadForex, LaunchpadForex, etc | ||
object : PolygonWebSocketListener { | ||
override fun onAuthenticated(client: PolygonWebSocketClient) { | ||
println("Connected!") | ||
} | ||
|
||
override fun onReceive( | ||
client: PolygonWebSocketClient, | ||
message: PolygonWebSocketMessage | ||
) { | ||
when (message) { | ||
is PolygonWebSocketMessage.RawMessage -> println(String(message.data)) | ||
else -> println("Receieved Message: $message") | ||
} | ||
} | ||
|
||
override fun onDisconnect(client: PolygonWebSocketClient) { | ||
println("Disconnected!") | ||
} | ||
|
||
override fun onError(client: PolygonWebSocketClient, error: Throwable) { | ||
println("Error: ") | ||
error.printStackTrace() | ||
} | ||
|
||
}) | ||
|
||
val subscriptions = listOf( | ||
PolygonWebSocketSubscription(PolygonWebSocketChannel.LaunchpadStocks.LaunchpadValue, "*"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.LaunchpadStocks.AggPerMinute, "*") | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.c.LaunchpadValue, "*"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.LaunchpadOptions.AggPerMinute, "*") | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.LaunchpadForex.LaunchpadValue, "*"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.LaunchpadForex.AggPerMinute, "*") | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.LaunchpadCrypto.LaunchpadValue, "*"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.c.AggPerMinute, "*") | ||
) | ||
|
||
websocketClient.connect() | ||
websocketClient.subscribe(subscriptions) | ||
delay(65_000) | ||
websocketClient.unsubscribe(subscriptions) | ||
websocketClient.disconnect() | ||
} |
49 changes: 49 additions & 0 deletions
49
sample/src/main/java/io/polygon/kotlin/sdk/sample/KotlinOptionsWebsocketSample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.polygon.kotlin.sdk.sample | ||
|
||
import io.polygon.kotlin.sdk.websocket.* | ||
import kotlinx.coroutines.delay | ||
|
||
suspend fun optionsWebsocketSample(polygonKey: String) { | ||
val websocketClient = PolygonWebSocketClient( | ||
polygonKey, | ||
Feed.RealTime, | ||
Market.Options, | ||
object : PolygonWebSocketListener { | ||
override fun onAuthenticated(client: PolygonWebSocketClient) { | ||
println("Connected!") | ||
} | ||
|
||
override fun onReceive( | ||
client: PolygonWebSocketClient, | ||
message: PolygonWebSocketMessage | ||
) { | ||
when (message) { | ||
is PolygonWebSocketMessage.RawMessage -> println(String(message.data)) | ||
else -> println("Receieved Message: $message") | ||
} | ||
} | ||
|
||
override fun onDisconnect(client: PolygonWebSocketClient) { | ||
println("Disconnected!") | ||
} | ||
|
||
override fun onError(client: PolygonWebSocketClient, error: Throwable) { | ||
println("Error: ") | ||
error.printStackTrace() | ||
} | ||
|
||
}) | ||
|
||
val subscriptions = listOf( | ||
PolygonWebSocketSubscription(PolygonWebSocketChannel.Options.Trades, "*"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Options.Quotes, "O:GOOGL230915P00067500"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Options.AggPerSecond, "*"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Options.AggPerMinute, "*") | ||
) | ||
|
||
websocketClient.connect() | ||
websocketClient.subscribe(subscriptions) | ||
delay(65_000) | ||
websocketClient.unsubscribe(subscriptions) | ||
websocketClient.disconnect() | ||
} |
49 changes: 49 additions & 0 deletions
49
sample/src/main/java/io/polygon/kotlin/sdk/sample/KotlinStocksWebsocketSample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.polygon.kotlin.sdk.sample | ||
|
||
import io.polygon.kotlin.sdk.websocket.* | ||
import kotlinx.coroutines.delay | ||
|
||
suspend fun stocksWebsocketSample(polygonKey: String) { | ||
val websocketClient = PolygonWebSocketClient( | ||
polygonKey, | ||
Feed.RealTime, | ||
Market.Stocks, | ||
object : PolygonWebSocketListener { | ||
override fun onAuthenticated(client: PolygonWebSocketClient) { | ||
println("Connected!") | ||
} | ||
|
||
override fun onReceive( | ||
client: PolygonWebSocketClient, | ||
message: PolygonWebSocketMessage | ||
) { | ||
when (message) { | ||
is PolygonWebSocketMessage.RawMessage -> println(String(message.data)) | ||
else -> println("Receieved Message: $message") | ||
} | ||
} | ||
|
||
override fun onDisconnect(client: PolygonWebSocketClient) { | ||
println("Disconnected!") | ||
} | ||
|
||
override fun onError(client: PolygonWebSocketClient, error: Throwable) { | ||
println("Error: ") | ||
error.printStackTrace() | ||
} | ||
|
||
}) | ||
|
||
val subscriptions = listOf( | ||
PolygonWebSocketSubscription(PolygonWebSocketChannel.Stocks.Trades, "*"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Stocks.Quotes, "*"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Stocks.AggPerSecond, "*"), | ||
//PolygonWebSocketSubscription(PolygonWebSocketChannel.Stocks.AggPerMinute, "*") | ||
) | ||
|
||
websocketClient.connect() | ||
websocketClient.subscribe(subscriptions) | ||
delay(65_000) | ||
websocketClient.unsubscribe(subscriptions) | ||
websocketClient.disconnect() | ||
} |
Oops, something went wrong.