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)
The value of the key, contained in the subscription payload, determines what status data will be returned.
Derivatives status updates:
key: "deriv:SYMBOL" // e.g. "deriv:tBTCF0:USTF0"
Liquidation feed updates:
key: "liq:global"
// 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
[
CHANNEL_ID,
[
TIME_MS,
PLACEHOLDER,
DERIV_PRICE,
SPOT_PRICE,
PLACEHOLDER,
INSURANCE_FUND_BALANCE,
PLACEHOLDER,
NEXT_FUNDING_EVT_TIMESTAMP_MS,
NEXT_FUNDING_ACCRUED,
NEXT_FUNDING_STEP,
PLACEHOLDER,
CURRENT_FUNDING
PLACEHOLDER,
PLACEHOLDER,
MARK_PRICE,
PLACEHOLDER,
PLACEHOLDER,
OPEN_INTEREST,
PLACEHOLDER,
PLACEHOLDER,
PLACEHOLDER,
CLAMP_MIN,
CLAMP_MAX
]
]
[335856,[1596124822000,null,0.896,0.771995,null,1396531.67460709,null,1596153600000,0.0001056,6,null,-0.01381344,null,null,0.7664,null,null,246502.09001551,null,null,null,null,0.3]]
// Liquidation feed updates
[
CHANNEL_ID,
[
['pos',
POS_ID,
TIME_MS,
PLACEHOLDER,
SYMBOL,
AMOUNT,
BASE_PRICE,
PLACEHOLDER,
IS_MATCH,
IS_MARKET_SOLD,
PLACEHOLDER
LIQUIDATION_PRICE
]
]
]
[91684,[["pos",142397657,1574697680828.2002,null,"tBSVUSD",-2.62932,91.583875238719,null,1,1,null,112.27]]]
Stream Fields
Fields | Type | Description |
---|---|---|
CHANNEL_ID | int | Identification number assigned to the channel for the duration of this connection. |
SYMBOL | String | Trading pair or funding currency |
TIME_MS | int | Millisecond timestamp |
DERIV_PRICE | float | Derivative book mid price. |
SPOT_PRICE | float | Book mid price of the underlying Bitfinex spot trading pair |
MARK_PRICE | float | Price based on the BFX Composite Index |
INSURANCE_FUND_BALANCE | float | The balance available to the liquidation engine to absorb losses. |
NEXT_FUNDING_EVT_TIMESTAMP_MS | null | Millisecond timestamp of next funding event |
NEXT_FUNDING_ACCRUED | float | Current accrued funding for next 8h period |
NEXT_FUNDING_STEP | int | Incremental accrual counter |
CURRENT_FUNDING | float | Funding applied in the current 8h period |
MARK_PRICE | float | Price based on the BFX Composite Index |
OPEN_INTEREST | float | Current open interest |
CLAMP_MIN | float | Range in the average spread that does not require a funding payment |
CLAMP_MAX | float | Funding payment cap |
POS_ID | int | Position id |
AMOUNT | float | Amount of the liquidated position |
BASE_PRICE | float | Base price of the liquidated position |
IS_MATCH | int | 0 -> initial liquidation trigger, 1 market execution |
IS_MARKET_SOLD | int | 0 -> direct sell into the market, 1 position acquired by the system |
LIQUIDATION_PRICE | float | Price at which the liquidation was triggered |