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.
Text ping / pong (recommended)
Send the plain text frame ping (exactly four characters, case-insensitive). The server replies with the plain text frame pong.
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:
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
Take the current timestamp, e.g.
1657157345159Sign the string
"1657157345159"with HMAC-SHA256Attach
apiKey,timestamp, andsignatureto the subscribe payload
Account
event: api_account
Extra request fields
symbol
String
Yes
Settlement coin, e.g. USD
Subscribe
Ack
Push
Order updates
event: api_entrust
Extra request fields
pair
String
Yes
Trading pair, e.g. ETH-USD
Subscribe
Push
Position updates
event: api_position
Extra request fields
pair
String
Yes
Trading pair
Push
Kline
event: api_kline
Extra request fields
pair
String
Yes
Trading pair
period
String
Yes
e.g. 1MIN
Push
Order book
event: api_depth
Extra request fields
pair
String
Yes
Trading pair
Push
Recent trades
event: api_trade
Extra request fields
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
pair
String
Yes
Trading pair
Push
User fills
event: api_deal_user
Extra request fields
pair
String
Yes
Trading pair
Push
Last updated