Skip to main content

WebSocket Guide

Overview​

The BlockWyre platform provides a WebSocket API that streams real-time market prices. Connect, subscribe once, and you receive the bid and ask of every trading product as they change.

Connecting to the WebSocket​

Endpoint​

Endpoint

WSS

/api/v2/market

EnvironmentURL
Sandboxwss://api-sandbox.blockwyre.xyz/api/v2/market
Productionwss://api.blockwyre.com/api/v2/market

Use a key from the same environment (see Environments).

Authentication​

Sign the WebSocket upgrade request like any other API request, and send the JWT in the Authorization header (see Authentication):

ClaimValue
uri/api/v2/market, plus its query string if you send one
methodGET
bodyHashSHA-256 of an empty body
GET wss://api-sandbox.blockwyre.xyz/api/v2/market
Authorization: APIKey {signed-jwt}

Any API key of the workspace can open the stream, account-scoped keys included.

Browsers cannot set headers on a WebSocket, so connect from your server, where the private key lives.

When authentication fails, the server still completes the upgrade (101 Switching Protocols) and then closes the connection with close code 4401 and the reason unauthorized: missing or expired token. It does not answer an HTTP 401. Sign a new JWT (fresh iat, exp and nonce) before you reconnect; reconnecting with the same token fails the same way.

Deprecated: the token in the URL

/api/v2/market still accepts the JWT as an Authorization query parameter (wss://api.blockwyre.com/api/v2/market?Authorization={signed-jwt}). Its uri is signed without that parameter: the path, plus any remaining query parameters sorted by name and URL-encoded (just /api/v2/market when there are none). It will be removed together with the deprecated v2 format. Send the header instead.

Messages​

Every message, in both directions, is a JSON object routed on its event field. A message without a known event (for example one that uses type) is ignored.

Subscribing to Market Data​

Once connected, send:

{ "event": "subscribe" }

This subscribes the connection to every product. There is no per-product subscription, and a list of products in the message is ignored: filter the ticks you receive on their product field.

Receiving Real-Time Updates​

After subscribing, you receive a tick message each time a price changes:

{
"event": "tick",
"product": "BTC-USD",
"bid": "67250.12",
"ask": "67262.40",
"time": "2026-10-20T14:03:21.123Z"
}

Message Structure​

  • event: tick for market data.
  • product: The trading pair, in the BASE-QUOTE form (e.g. BTC-USD, USDC-MXN). See Supported Assets & Pairs.
  • bid: The current bid price, as a decimal string.
  • ask: The current ask price, as a decimal string.
  • time: When the price was observed, as an RFC 3339 timestamp.

Keepalive​

Send a ping at any time:

{ "event": "ping" }

The server answers:

{ "event": "pong" }

When no ticks arrive, send a ping about every 30 seconds to keep the connection open, and reconnect (with a freshly signed JWT) if no pong comes back.

Key Terminology​

  • WebSocket: A protocol providing full-duplex communication channels over a single TCP connection.
  • API Key: The key you sign requests with, including the WebSocket upgrade. See Authentication.
  • Product: A pair of currencies being traded (e.g., "BTC-USD").
  • Bid Price: The highest price a buyer is willing to pay for a currency pair.
  • Ask Price: The lowest price a seller is willing to accept for a currency pair.

Conclusion​

Connect to the endpoint of your environment with a signed upgrade request, send {"event":"subscribe"}, and filter the ticks on product. For any further assistance or questions, please contact BlockWyre support at support@blockwyre.com.

Support and Resources​

If you need assistance or have any questions, our support team is here to help. You can contact our support team at support@blockwyre.com.

Stay Updated​

Stay up-to-date with the latest news, updates, and features from BlockWyre by following us on social media:

We are excited to have you on board and look forward to seeing how you leverage BlockWyre's powerful tools to enhance your financial operations. Happy integrating!