WebSocket Streams
Overview
Dipcoin Perpetual provides WebSocket endpoints for real-time market data and user account streams.
- WebSocket endpoint:
wss://gray-ws.dipcoin.io/stream/ws - Message format: client and server exchange JSON text messages in the following shape:
Where:
- op: operation type
"subscribe": subscribe to one or more topics"unsubscribe": unsubscribe from one or more topics"login": authenticate with a JWT token to enable private topics- args:
- for
login:["<JWT_TOKEN>"] - for
subscribe/unsubscribe:["<topic1>", "<topic2>", ...]
The server periodically sends ping; the client must reply with pong to keep the connection alive.
Authentication (login)
Before subscribing to private channels (such as user events, positions, and account updates), the client must authenticate via login.
After a successful login, you can subscribe to private topics, for example:
When the login session expires, the server will automatically cancel subscriptions to private topics.
Public Topics
All public topics start with the perp/ prefix and belong to the perpetual futures business.
1. Kline
- Subscription format:
perp/kline.<symbol>.<resolution>[.<size>] - Example:
Field description:
symbol: contract symbol, such asBTC-PERP,ETH-PERPresolution: kline interval- supported:
1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, D, W, M size(optional): max number of kline bars to return; if omitted, the default size is used
Kline data is written to Redis by the upstream market service; this service forwards the JSON to the client as-is. Example:
{
"topic": "perp/kline.ADA-PERP.1m",
"data": [
{
"t": 1773735420,
"o": 286100000000000000,
"h": 286700000000000000,
"l": 286100000000000000,
"c": 286700000000000000,
"v": 0,
"a": 0,
"vl": 0,
"al": 0
}
]
}
Note: kline price fields
o/h/l/care integers already multiplied by \(10^{18}\). To display human-readable decimal prices, divide by \(10^{18}\) on the client side.
2. Order Book
- Subscription format:
perp/orderBook.<symbol>[.<depth>] - Example:
Field description:
symbol: contract symbol, e.g.ETH-PERPdepth(optional): number of depth levels (for example5,10,20,50,100,200); if omitted, the default depth is used
Sample push message:
{
"topic": "perp/orderBook.SUI-PERP",
"action": "update",
"data": [
{
"bids": [],
"asks": [
["1041800000000000000", "8902000000000000000000"],
["1055500000000000000", "1000000000000000000000"]
],
"version": 18585082,
"timestamp": 1773735151791
}
],
"createTime": 0,
"sendTime": 0
}
Note: prices and quantities in the order book (as well as numeric fields in ticker/account/position messages) are integers already multiplied by \(10^{18}\). To display human-readable decimals, divide by \(10^{18}\) on the client side.
3. Trade List
- Subscription format:
perp/tradeList.<symbol> - Example:
Sample push message:
{
"topic": "perp/tradeList.SUI-PERP",
"data": [["1031900000000000000","0","282000000000000000000","1773734798252"]]
}
4. Ticker
- Subscribe all symbols:
perp/ticker.all - Subscribe a single symbol:
perp/ticker.<symbol>
Examples:
{ "op": "subscribe", "args": ["perp/ticker.all"] }
{ "op": "subscribe", "args": ["perp/ticker.BTC-PERP"] }
Sample response (single symbol):
{
"topic": "perp/ticker.SUI-PERP",
"data": [
{
"symbol": "SUI-PERP",
"lastPrice": "1032000000000000000",
"markPrice": "0",
"bestAskPrice": "1031400000000000000",
"bestBidPrice": "1031100000000000000",
"high24h": "1084200000000000000",
"low24h": "1021800000000000000",
"open24h": "1049500000000000000",
"amount24h": "377237000000000000000000",
"volume24h": "396516321200000000000000",
"bestAskAmount": "1996000000000000000000",
"bestBidAmount": "2399000000000000000000",
"timestamp": 1773734564612,
"change24h": "-17704490000000000",
"rate24h": "-16900000000000000.0000",
"openPrice": "1073100000000000000",
"oraclePrice": "1031795510000000000",
"fundingRate": "12500000000000",
"openInterest": "207568406427166000000000"
}
]
}
Private Topics
Private topics require a valid login (JWT), and are mainly used to push user-related events.
1. User Event
- Subscription format:
perp/userEvent - Example:
The server maintains an internal topic per user (for example perp/userEvent:<userId>). Messages usually include order status changes, liquidation notifications, etc. The exact JSON structure is defined by the business service.
2. User Account
- Subscription format:
perp/user.account - Push topic example:
perp/user.account:<userAddress>
{
"topic": "perp/user.account:0xab7f6e97...",
"data": [
{
"eventType": "AccountChange",
"payload": {
"address": "0xab7f6e97...",
"canTrade": true,
"updateTime": 1773734964282,
"feeTier": "DEFAULT",
"walletBalance": "1078762278966000000000",
"totalPositionMargin": "518499001383000000000",
"totalUnrealizedProfit": "-28071391442000000000",
"freeCollateral": "560263277583000000000",
"accountValue": "1050690887524000000000",
"accountDataByMarket": [
{
"symbol": "BTC-PERP",
"positionQtyReduced": "0",
"positionQtyReducible": "0",
"unrealizedProfit": "0",
"selectedLeverage": "10000000000000000000"
}
]
}
}
]
}
3. User Position
- Subscription format:
perp/user.position - Push topic example:
perp/user.position:<userAddress>
{
"topic": "perp/user.position:0xab7f6e97...",
"data": [
{
"eventType": "PositionChange",
"payload": [
{
"id": 19038,
"userAddress": "0xab7f6e97...",
"symbol": "SUI-PERP",
"avgEntryPrice": "1036546666666400000",
"margin": "518160584457000000000",
"leverage": "10000000000000000000",
"quantity": "5000000000000000000000",
"createdAt": 1773715924000,
"updatedAt": 1773734060000,
"marginType": "ISOLATED",
"oraclePrice": "1029504510000000000",
"midMarketPrice": "1028950000000000000",
"liquidationPrice": "956848664384615384",
"side": "BUY",
"positionValue": "5147522550000000000000",
"unrealizedProfit": "-35210783332000000000",
"roe": "-67938635981031357",
"fundingDue": "-64490000000000000",
"fundingFeeNext": "-64344031875000000",
"settlementFundingFee": "-127764000000000000",
"netMargin": "518225074457000000000",
"positionQtyReducible": "5000000000000000000000",
"tpPrice": null,
"slPrice": null,
"tpslNum": 0
}
]
}
]
}
Sample Client (JavaScript)
The following example shows how to create a WebSocket connection in a browser and subscribe to some public topics:
const socket = new WebSocket('wss://gray-ws.dipcoin.io/stream/ws?debug=1');
socket.onopen = () => {
// sub K line
socket.send('{"op":"subscribe","args":["perp/kline.ETH-PERP.1m"]}');
// sub Ticker.all
// socket.send(\'{"op":"subscribe","args":["perp/ticker.all"]}\');
};
socket.onmessage = (event) => {
if (event.data === "ping") {
socket.send("pong");
return;
}
console.log("message", event.data);
};