Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WebSocket service links as per the error message #110

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Tutorial

Usage
---
In this example, we read the realtime Bitcoin price from [Gdax WebSocket Feed][gdax-websocket-feed].
In this example, we read the realtime Bitcoin price from [Coinbase WebSocket Feed][https://docs.pro.coinbase.com/].
For more information, please check out the [demo app][demo-app].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll probably need to update the demo to make it consistent

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaronhe42 I think so. Do you want me to update the demo accordingly?


Declare a WebSocket client using an interface:

~~~ kotlin
interface GdaxService {
interface CoinbaseService {
@Receive
fun observeWebSocketEvent(): Flowable<WebSocket.Event>
@Send
Expand All @@ -36,12 +36,12 @@ Use Scarlet to create an implementation:

~~~ kotlin
val scarletInstance = Scarlet.Builder()
.webSocketFactory(okHttpClient.newWebSocketFactory("wss://ws-feed.gdax.com"))
.webSocketFactory(okHttpClient.newWebSocketFactory("wss://ws-feed-public.sandbox.pro.coinbase.com"))
.addMessageAdapterFactory(MoshiMessageAdapter.Factory())
.addStreamAdapterFactory(RxJava2StreamAdapter.Factory())
.build()

val gdaxService = scarletInstance.create<GdaxService>()
val coinbaseService = scarletInstance.create<CoinbaseService>()
~~~

Send a `Subscribe` message upon connection open and the server will start streaming tickers which contain the latest price.
Expand All @@ -53,13 +53,13 @@ val BITCOIN_TICKER_SUBSCRIBE_MESSAGE = Subscribe(
channels = listOf("ticker")
)

gdaxService.observeWebSocketEvent()
coinbaseService.observeWebSocketEvent()
.filter { it is WebSocket.Event.OnConnectionOpened<*> }
.subscribe({
gdaxService.sendSubscribe(BITCOIN_TICKER_SUBSCRIBE_MESSAGE)
})

gdaxService.observeTicker()
coinbaseService.observeTicker()
.subscribe({ ticker ->
Log.d("Bitcoin price is ${ticker.price} at ${ticker.time}")
})
Expand Down