For the complete documentation index, see llms.txt. This page is also available as Markdown.

WebSocket

WebSocket API for Astros

Endpoint: wss://api.astros.ag/api/market/ws

All WebSocket subscriptions require API key authentication. Sign the timestamp string with HMAC-SHA256 using app_secret (lowercase hex), the same algorithm as REST.

Keepalive (ping / pong)

Clients should implement an application-level ping/pong heartbeat. The server closes idle connections after about 120 seconds with no inbound traffic. Send a ping on a fixed interval (recommended every 15–30 seconds) and reconnect if no pong arrives.

Send the plain text frame ping (exactly four characters, case-insensitive). The server replies with the plain text frame pong.

Direction
Frame type
Payload

Client → server

Text

ping

Server → client

Text

pong

Example (browser / Node)

const ws = new WebSocket('wss://api.astros.ag/api/market/ws');

ws.onopen = () => {
  // Heartbeat: ping every 20s
  setInterval(() => {
    if (ws.readyState === WebSocket.OPEN) {
      ws.send('ping');
    }
  }, 20_000);
};

ws.onmessage = (event) => {
  if (event.data === 'pong') {
    // connection is healthy
    return;
  }
  // handle subscribe ack / channel pushes...
  console.log(JSON.parse(event.data));
};

Example (Python)

Protocol-level WebSocket ping

The server also answers standard WebSocket Ping control frames with a Pong control frame. Prefer the text ping / pong exchange above when your client library makes application messages easier to handle than control frames.

Client recommendations

  • Start the heartbeat as soon as the socket opens, before or after subscribe.

  • Treat a missed pong (for example no reply within 10 seconds) as a dead connection: close and reconnect with backoff.

  • Do not rely on subscribe traffic alone to keep the socket alive during quiet markets.

Subscription envelope

Every subscribe request shares these fields:

Name
Type
Required
Description

method

String

Yes

SUBSCRIBE

event

String

Yes

Channel name, e.g. api_account

apiKey

String

Yes

Your API key

timestamp

Number

Yes

Unix time in milliseconds

signature

String

Yes

HMAC-SHA256 of the timestamp string

Channel-specific fields (such as symbol, pair, period) are documented per event below.

Sign a subscribe request

  1. Take the current timestamp, e.g. 1657157345159

  2. Sign the string "1657157345159" with HMAC-SHA256

  3. Attach apiKey, timestamp, and signature to the subscribe payload


Account

event: api_account

Extra request fields

Name
Type
Required
Description

symbol

String

Yes

Settlement coin, e.g. USD

Subscribe

Ack

Push


Order updates

event: api_entrust

Extra request fields

Name
Type
Required
Description

pair

String

Yes

Trading pair, e.g. ETH-USD

Subscribe

Push


Position updates

event: api_position

Extra request fields

Name
Type
Required
Description

pair

String

Yes

Trading pair

Push


Kline

event: api_kline

Extra request fields

Name
Type
Required
Description

pair

String

Yes

Trading pair

period

String

Yes

e.g. 1MIN

Push


Order book

event: api_depth

Extra request fields

Name
Type
Required
Description

pair

String

Yes

Trading pair

Push


Recent trades

event: api_trade

Extra request fields

Name
Type
Required
Description

pair

String

Yes

Trading pair

period

String

No

Channel period if required by server

Push


Live trade prints

event: api_spot_deals

Extra request fields

Name
Type
Required
Description

pair

String

Yes

Trading pair

Push


User fills

event: api_deal_user

Extra request fields

Name
Type
Required
Description

pair

String

Yes

Trading pair

Push

Last updated