![](https://static.x-sure.co/wp-content/uploads/2022/10/websocket-binance-coinbase.jpg)
In the previous article, we’ve integrated Elixir Phoenix with Binance WebSocket streams. In this part, we talk about how to work with Coinbase WebSocket streams.
For Coinbase WebSocket streams there is a Coinbase Pro REST and WebSocket client called GDEX for Elixir. It makes this job easier. So, firstly we need to add GDEX into the project and run “mix deps.get”
![](https://static.x-sure.co/wp-content/uploads/2022/11/image-7-1024x882.png)
Secondly, Define a module that uses the Gdex.Websocket
behavior:
![](https://static.x-sure.co/wp-content/uploads/2022/11/image-6-1024x693.png)
According to the Coinbase WebSocket channels doc, the “ticker_batch” channel meets our requirements, so once the WebSocket is connected, it will subscribe “ticker_batch” channel.
![](https://static.x-sure.co/wp-content/uploads/2022/11/image-4-1024x726.png)
def handle_connect(gdax, state) do
Logger.debug("Coinbase websocket Connected!")
symbols = Enum.reduce(XSureWss.TickerUtils.get_crypto_symbols(), [], fn (symbol, acc) ->
acc ++ ["#{symbol}-USD"]
end)
subscribe(gdax, :ticker_batch, symbols, authenticate: true)
{:ok, state}
end
Finally, start the WebSocket client with the handler and append XSureWss.Coinbase.Streamer to Phoenix application start:
![](https://static.x-sure.co/wp-content/uploads/2022/11/image-3-1024x481.png)
![](https://static.x-sure.co/wp-content/uploads/2022/11/image-2-1024x518.png)
![](https://static.x-sure.co/wp-content/uploads/2022/11/image-1-1024x843.png)
That is! Run mix phx.server
. If everything goes well, you will see the following stream logs.
![](https://static.x-sure.co/wp-content/uploads/2022/11/image-1024x576.png)
Source Code
You can find the complete finished code in this GitHub repository.