Subscribe to and receive different types of platform information - currently supports derivatives pair status and liquidation feed.
const ws = require('ws')
const w = new ws('wss://api-pub.bitfinex.com/ws/2')
w.on('message', (msg) => console.log(msg))
let msg = JSON.stringify({
event: 'subscribe',
channel: 'status',
key: 'deriv:tBTCF0:USTF0'
})
w.on('open', () => w.send(msg))
wscat -c wss://api-pub.bitfinex.com/ws/2
{ "event": "subscribe", "channel": "status", "key": "deriv:tBTCF0:USTF0" }
ws = websocket.WebSocketApp('wss://api-pub.bitfinex.com/ws/2')
ws.on_open = lambda self: self.send('{ "event": "subscribe", "channel": "status", "key": "deriv:tBTCF0:USTF0"}')
ws.on_message = lambda self, evt: print (evt)
// request
{
event: "subscribe",
channel: "status",
key: KEY
}
// response -
{
event: "subscribed",
channel: "status",
chanId: CHANNEL_ID,
key: KEY
}
//Derivative pair status
{"event":"subscribed","channel":"status","chanId":335856,"key":"deriv:tBTCF0:USTF0"}
//Liquidation feed
{"event":"subscribed","channel":"status","chanId":91684,"key":"liq:global"}
// Derivatives Status
[
335856, //CHANNEL_ID
[
1596124822000, //TIME_MS
null, //PLACEHOLDER
0.896, //DERIV_PRICE
0.771995, //SPOT_PRICE
null, //PLACEHOLDER
1396531.67460709, //INSURANCE_FUND_BALANCE
null, //PLACEHOLDER
1596153600000, //NEXT_FUNDING_EVT_TIMESTAMP_MS
0.0001056, //NEXT_FUNDING_ACCRUED
6, //NEXT_FUNDING_STEP
null, //PLACEHOLDER
-0.01381344, //CURRENT_FUNDING
null, //PLACEHOLDER
null, //PLACEHOLDER
0.7664, //MARK_PRICE
null, //PLACEHOLDER
null, //PLACEHOLDER
246502.09001551, //OPEN_INTEREST
null, //PLACEHOLDER
null, //PLACEHOLDER
null, //PLACEHOLDER
null, //CLAMP_MIN
0.3 //CLAMP_MAX
] //DERIVATIVE_STATUS_ARRAY
]
// Liquidation feed updates
[
91684, //CHANNEL_ID
[
[
"pos", //MSG_TYPE
142397657, //POS_ID
1574697680828.2002, //TIME_MS
null, //PLACEHOLDER
"tBSVUSD", //SYMBOL
-2.62932, //AMOUNT
91.583875238719, //BASE_PRICE
null, //PLACEHOLDER
1, //IS_MATCH
1, //IS_MARKET_SOLD
null, //PLACEHOLDER
112.27 //LIQUIDATION_PRICE
] //LIQUIDATION_ARRAY
] //LIQUIDATIONS
]
Request fields
Keys | Type | Description |
---|---|---|
"deriv:SYMBOL" (e.g. "deriv:tBTCF0:USTF0") | String | Used to subscribe to derivative pair status updates |
"liq:global" | String | Used to subscribe to liquidation feed updates |
Status update data
Index | Field | Type | Description |
---|---|---|---|
[0] | CHANNEL_ID | Int | Identification number assigned to the channel for the duration of this connection. |
[1] | UPDATE | Array | Derivative status array or Liquidations array |
Derivative status array (Index [1])
Index | Field | Type | Description |
---|---|---|---|
[0] | TIME_MS | Int | Millisecond timestamp |
[ . . . ] | |||
[2] | DERIV_PRICE | Float | Derivative book mid price. |
[3] | SPOT_PRICE | Float | Book mid price of the underlying Bitfinex spot trading pair |
[ . . . ] | |||
[5] | INSURANCE_FUND_BALANCE | Float | The balance available to the liquidation engine to absorb losses. |
[ . . . ] | |||
[7] | NEXT_FUNDING_EVT_TIMESTAMP_MS | Int | Millisecond timestamp of next funding event |
[8] | NEXT_FUNDING_ACCRUED | Float | Current accrued funding for next 8h period |
[9] | NEXT_FUNDING_STEP | Int | Incremental accrual counter |
[ . . . ] | |||
[11] | CURRENT_FUNDING | Float | Funding applied in the current 8h period |
[ . . . ] | |||
[14] | MARK_PRICE | Float | Price based on the BFX Composite Index |
[ . . . ] | |||
[17] | OPEN_INTEREST | Float | Current open interest |
[ . . . ] | |||
[22] | CLAMP_MIN | Float | Range in the average spread that does not require a funding payment |
[23] | CLAMP_MAX | Float | Funding payment cap |
Liquidations (Index [1])
Index | Field | Type | Description |
---|---|---|---|
[0....n] | LIQUIDATION_ARRAY | Array | Liquidation array |
Liquidation array (Index [1][0...n])
Index | Field | Type | Description |
---|---|---|---|
[0] | MSG_TYPE | String | Type of message ('pos') |
[1] | POS_ID | Int | Position id |
[2] | TIME_MS | Int | Millisecond timestamp |
[ . . . ] | |||
[4] | SYMBOL | String | Trading pair |
[5] | AMOUNT | Float | Amount of the liquidated position |
[6] | BASE_PRICE | Float | Base price of the liquidated position |
[ . . . ] | |||
[8] | IS_MATCH | Int | 0 -> initial liquidation trigger, 1 market execution |
[9] | IS_MARKET_SOLD | Int | 0 -> direct sell into the market, 1 position acquired by the system |
[ . . . ] | |||
[11] | LIQUIDATION_PRICE | Float | Price at which the liquidation was triggered |