Candles

The Candles endpoint provides OCHL (Open, Close, High, Low) and volume data for the specified trading pair.

//Trading Candles

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: 'candles', 
  key: 'trade:1m:tBTCUSD' //'trade:TIMEFRAME:SYMBOL'
})

w.on('open', () => w.send(msg))

//Funding Candles

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: 'candles', 
  key: 'trade:1m:fUSD:a30:p2:p30' //'trade:TIMEFRAME:SYMBOL:aAGGR:pPER_START:pEND'
})

w.on('open', () => w.send(msg))
wscat -c wss://api-pub.bitfinex.com/ws/2
{ "event": "subscribe",  "channel": "candles",  "key": "trade:1m:tBTCUSD" }
ws = websocket.WebSocketApp('wss://api-pub.bitfinex.com/ws/2')

ws.on_open = lambda self: self.send('{ "event": "subscribe",  "channel": "candles",  "key": "trade:1m:tBTCUSD" }')

ws.on_message = lambda self, evt:  print (evt)
// request
{
   event: "subscribe",
   channel: "candles",
   key: "trade:1m:tBTCUSD"
}

// response
{
  event: "subscribed",
  channel: "candles",
  chanId": CHANNEL_ID,
  key: "trade:1m:tBTCUSD"
}

{"event":"subscribed","channel":"candles","chanId":343351,"key":"trade:1m:tBTCUSD"}
[
  343351, //CHANNEL_ID
  [
    [
      1574698260000, //MTS
      7379.785503, //OPEN
      7383.8, //CLOSE
      7388.3, //HIGH
      7379.785503, //LOW
      1.68829482 //VOLUME
    ], //CANDLE
    ...
  ] //SNAPSHOT
]
[
  343351, //CHANNEL_ID
  [
    1574698200000, //MTS
    7399.9, //OPEN
    7379.7, //CLOSE
    7399.9, //HIGH
    7371.8, //LOW
    41.63633658 //VOLUME
  ] //CANDLE
]

Request fields

FieldsTypeDescription
KEYstringSpecify the time frame and symbol ('trade:TIMEFRAME:SYMBOL').
KEY (funding)stringSpecify the time frame and symbol along with the pPeriod or an aAGGR aggregated period using a Pper_start and Pper_end parameter.

🚧

Funding Candles

Be sure to specify a period or aggregated period when retrieving funding candles. If you wish to mimic the candles found in the UI, use the following setup to aggregate all funding candles: a30:p2:30

Candle snapshot data

IndexFieldTypeDescription
[0]CHANNEL_IDIntIdentification number assigned to the channel for the duration of this connection.
[1]SNAPSHOTArrayArray with an array of recent candles (Indices [0...n] will be candles)
[1][0...n]CANDLEArrayCandle array

Candle update data

IndexFieldTypeDescription
[0]CHANNEL_IDIntIdentification number assigned to the channel for the duration of this connection.
[1]CANDLEArrayCandle array

Candle arrays

IndexFieldsTypeDescription
[0]MTSintmillisecond time stamp
[1]OPENfloatFirst execution during the time frame
[2]CLOSEfloatLast execution during the time frame
[3]HIGHfloatHighest execution during the time frame
[4]LOWfloatLowest execution during the timeframe
[5]VOLUMEfloatQuantity of symbol traded within the timeframe

Time frames

  • 1m: one minute
  • 5m : five minutes
  • 15m : 15 minutes
  • 30m : 30 minutes
  • 1h : one hour
  • 3h : 3 hours
  • 6h : 6 hours
  • 12h : 12 hours
  • 1D : one day
  • 1W : one week
  • 14D : two weeks
  • 1M : one month