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"}
[
  CHANNEL_ID,
  [
    [
      MTS,
      OPEN,
      CLOSE,
      HIGH,
      LOW,
      VOLUME
    ],
    ...
  ]
]

[343351,[[1574698260000,7379.785503,7383.8,7388.3,7379.785503,1.68829482]]]
[
  CHANNEL_ID,
  [
    MTS,
    OPEN,
    CLOSE,
    HIGH,
    LOW,
    VOLUME
  ]
]

[343351,[1574698200000,7399.9,7379.7,7399.9,7371.8,41.63633658]]

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

Stream Fields

FieldsTypeDescription
CHANNEL_IDintIdentification number assigned to the channel for the duration of this connection.
MTSintmillisecond time stamp
OPENfloatFirst execution during the time frame
CLOSEfloatLast execution during the time frame
HIGHfloatHighest execution during the time frame
LOWfloatLowest execution during the timeframe
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