Using a WebSocket Client to Consume Market Data

In the video below, we connect to the public Kraken WebSocket endpoint: wss://ws.kraken.com/v2

We then send the following subscription command to receive real-time ticker information for BTC/USD, XRP/USD, ETH/USD, and DOGE/USD:

Minimal Example with coroio

COROIO includes a WebSocket client that supports both ws:// and wss:// protocols. Below is a simple example usage:

TWebSocket ws(socket);

// Connect to the Kraken WebSocket endpoint
co_await ws.Connect("ws.kraken.com", "/v2");

// Send a subscription request
ws.SendText(R"({"method":"subscribe","params":{"channel":"ticker","symbol":["BTC/USD","XRP/USD","ETH/USD","DOGE/USD"]}})");

// Read incoming frames
auto data = co_await ws.ReceiveText();
std::cout << "Received message: " << data << std::endl;

For full implementation details, see the WebSocket class in coroio. To explore a complete working example, check out wsclient.cpp.