Supported streams
Endpoint: Stream WS
Kline/Candlestick: perp_candle/<market_id>/<interval>
Orderbook: perp_depth/<market_id>/<level>
Ticker: perp_ticker/<market_id>
Kline/Candlestick stream
The Kline/Candlestick Stream push updates to the current klines/candlestick every 250 milliseconds (if existing).
Subscribe
Stream Name: perp_candle/<market_id>/<interval>
Kline/Candlestick chart intervals
m -> minutes; h -> hours; d -> days; w -> weeks; M -> months
{
"marketId": 1,
"ts": 1715678700000, // time start
"tc": 1715679000000, // time end
"interval": "5m",
"o": "61877.200000000000000000", // open
"h": "62260.600000000000000000", // high
"l": "61700.800000000000000000", // low
"c": "61700.800000000000000000", // close
"base_volume": "20.960000000000000000", // base asset volume
"quote_volume": "1296614.320000000000000000", // quote asset volume
"base_buy_volume": "11.028000000000000000", // taker buy base asset volume
"quote_buy_volume": "682167.113700000000000000", // taker buy quote asset volume
"E": 1715753860794 // event time
}
Orderbook stream
Top bids and asks, Valid are 1,5,10,20,100,200.
Subscribe
Stream Name: perp_depth/<market_id>/<level>
{
"marketId": 1,
"asks":[
// [price, amount, cumulative amount]
[
"58062.1",
"0.0090000000000000000000000000",
"0.0090000000000000000000000000"
],
[
"58062.2",
"0.149",
"0.1580000000000000000000000000"
]
],
"bids":[
[
"58061.9",
"0.0750000000000000000000000000",
"0.0750000000000000000000000000"
],
[
"58061.8",
"0.155",
"0.2300000000000000000000000000"
]
]
}
Ticker stream
Subscribe
Stream Name: perp_ticker/<market_id>
{
"H": "60904.000000000000000000",
"L": "59335.580000000000000000",
"O": "60694.100000000000000000",
"C": "59335.580000000000000000",
"base_volume": "0.809130000000000000",
"quote_volume": "49154.622020400000000000",
"best_bid": "59335.58",
"best_ask": "59335.59",
"bidSz": "5.16167",
"askSz": "3.99586",
"ts": 1724210499298
}
Code Example
import mqtt from 'mqtt'
const endpoint = 'wss://testnet-stream.foundation.network'
const clientId = `client_xxx_${Math.random().toString(16).substring(2, 8)}`
const marketId = 1
const level = 1
const channel = `perp_depth/${marketId}_${level}`
const options: mqtt.IClientOptions = {
clientId: clientId,
protocolId: 'MQTT',
protocolVersion: 5,
clean: true,
reconnectPeriod: 1_000,
connectTimeout: 30_000,
auth: 'sub:1',
}
const client = mqtt.connect(endpoint, options)
client.on('connect', () => {
console.debug('[MQTT] Socket connected')
client.subscribe(channel)
})
client.on('close', () => {
console.debug('[MQTT] Socket closed')
})
client.on('message', (topic, message) => {
console.log(message.toString())
})
client.on('error', (err) => {
console.debug('[MQTT] Connection error: ', err)
})
client.on('reconnect', () => {
console.debug('[MQTT] Reconnecting...')
})