This channel sends a trade message whenever a trade occurs at Bitfinex. It includes all the pertinent details of the trade, such as price, size and the time of execution. The channel can send funding trade data as well.
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: 'trades',
symbol: 'tBTCUSD'
})
w.on('open', () => w.send(msg))
wscat -c wss://api-pub.bitfinex.com/ws/2
{ "event": "subscribe", "channel": "trades", "symbol": "tBTCUSD" }
ws = websocket.WebSocketApp('wss://api-pub.bitfinex.com/ws/2')
ws.on_open = lambda self: self.send('{ "event": "subscribe", "channel": "trades", "symbol": "tBTCUSD"}')
ws.on_message = lambda self, evt: print (evt)
// request
{
event: "subscribe",
channel: "trades",
symbol: SYMBOL
}
// response Trading
{
event: "subscribed",
channel: "trades",
chanId: CHANNEL_ID,
symbol: "tBTCUSD"
pair: "BTCUSD"
}
{"event":"subscribed","channel":"trades","chanId":19111,"symbol":"tBTCUSD","pair":"BTCUSD"}
// response Funding
{
event: "subscribed",
channel: "trades",
chanId: CHANNEL_ID,
symbol: "fUSD",
currency: "USD"
}
{"event":"subscribed","channel":"trades","chanId":339521,"symbol":"fUSD","currency":"USD"}
// on trading pairs (ex. tBTCUSD)
[
CHANNEL_ID,
[
[
ID,
MTS,
AMOUNT,
PRICE
],
...
]
]
[17470,[[401597393,1574694475039,0.005,7244.9],[401597392,1574694470503,-0.01,7245.3]]]
// on funding currencies (ex. fUSD)
[
CHANNEL_ID,
[
[
ID,
MTS,
AMOUNT,
RATE,
PERIOD
],
...
]
]
[339521,[[133323072,1574694245478,-258.7458086,0.0002587,2],[133323071,1574694245368,-1932.20263916,0.0002587,2]]]
// on trading pairs (ex. tBTCUSD)
[
CHANNEL_ID,
<"te", "tu">,
[
ID,
MTS,
AMOUNT,
PRICE
]
]
[17470,"te",[401597395,1574694478808,0.005,7245.3]]
[17470,"tu",[401597395,1574694478808,0.005,7245.3]]
// on funding currencies (ex. fUSD)
[
CHANNEL_ID,
<"fte", "ftu">,
[
ID,
MTS,
AMOUNT,
RATE,
PERIOD
]
]
[337371,"fte",[133323543,1574694605000,-59.84,0.00023647,2]]
[337371,"ftu",[133323543,1574694605000,-59.84,0.00023647,2]]
Request Fields
Fields | Type | Description |
---|---|---|
SYMBOL | String | Trading pair or funding currency |
Stream Fields
Fields | Type | Description |
---|---|---|
CHANNEL_ID | int | Identification number assigned to the channel for the duration of this connection. |
ID | int | Trade ID |
MTS | int | millisecond time stamp |
±AMOUNT | float | Amount bought (positive) or sold (negative). |
PRICE | float | Price at which the trade was executed |
RATE | float | Funding rate of the trade |
PERIOD | int | Funding offer period in days |
The order that causes the trade (the taker) determines if it is a buy or a sell.