Bitfinex WebSocket API

From sgcWebSockets 4.1.5 Bitfinex WebSocket API is supported.

Bitfinex is one of the world's largest and most advanced cryptocurrency trading platform. Users can exchange Bitcoin, Ethereum, Ripple, EOS, Bitcoin Cash, Iota, NEO, Litecoin, Ethereum Classic...

Bitfinex Websocket API version is 2.0

Each message sent and received via the Bitfinex's websocket channel is encoded in JSON format

 A symbol can be a trading pair or a margin currency:

 

  • Trading pairs symbols are formed prepending a "t" before the pair (i.e tBTCUSD, tETHUSD).

  • Margin currencies symbols are formed prepending a "f" before the currency (i.e fUSD, fBTC, ...)

  

After a successful connection, OnBitfinexConnect event is raised and you get Bitfinex API Version number as parameter.

You can call Ping method to test connection to server. 

If server sends any information, this can be handle using OnBitfinexInfoMessage event, where a Code and a Message are parameters with information about message sent by server. Example codes:

 

20051 : Stop/Restart Websocket Server (please reconnect)

20060 : Entering in Maintenance mode. Please pause any activity and resume after receiving the info message 20061 (it should take 120 seconds at most).

20061 : Maintenance ended. You can resume normal activity. It is advised to unsubscribe/subscribe again all channels.

 

In case of error, OnBitfinexError will be raised, and information about error provided. Example error codes:

 

10000 : Unknown event

10001 : Unknown pair

 

In order to change the configuration, call Configuration method and pass as a parameter one of the following flags:

 

CS_DEC_S = 8; // Enable all decimal as strings.

CS_TIME_S = 32; // Enable all times as date strings.

CS_SEQ_ALL = 65536; // Enable sequencing BETA FEATURE

CHECKSUM = 131072; // Enable checksum for every book iteration. Checks the top 25 entries for each side of book. Checksum is a signed int.

 

Subscribe Public Channels

There are channels which are public and there is no need to authenticate against server. All messages are raised OnBitfinexUpdate event.

 

SubscribeTicker

The ticker is a high level overview of the state of the market. It shows you the current best bid and ask, as well as the last trade price. It also includes information such as daily volume and how much the price has moved over the last day.

 

// Trading pairs

[

  CHANNEL_ID,

  [

    BID,

    BID_SIZE,

    ASK,

    ASK_SIZE,

    DAILY_CHANGE,

    DAILY_CHANGE_PERC,

    LAST_PRICE,

    VOLUME,

    HIGH,

    LOW

  ]

]

// Funding pairs

[

  CHANNEL_ID,

  [

    FRR,

    BID,

    BID_PERIOD,

    BID_SIZE,

    ASK,

    ASK_PERIOD,

    ASK_SIZE,

    DAILY_CHANGE,

    DAILY_CHANGE_PERC,

    LAST_PRICE,

    VOLUME,

    HIGH,

    LOW

  ]

]

 

 

SubscribeTrades

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 time.

 

// on trading pairs (ex. tBTCUSD)

[

  CHANNEL_ID,

  [

    [

      ID,

      MTS,

      AMOUNT,

      PRICE

    ],

    ...

  ]

]

// on funding currencies (ex. fUSD)

[

  CHANNEL_ID,

  [

    [

      ID,

      MTS,

      AMOUNT,

      RATE,

      PERIOD

    ],

    ...

  ]

]

 

SubscribeOrderBook

The Order Books channel allow you to keep track of the state of the Bitfinex order book. It is provided on a price aggregated basis, with customizable precision. After receiving the response, you will receive a snapshot of the book, followed by updates upon any changes to the book.

 

// on trading pairs (ex. tBTCUSD)

[

  CHANNEL_ID,

  [

    [

      PRICE,

      COUNT,

      AMOUNT

    ],

    ...

  ]

]

  

// on funding currencies (ex. fUSD)

[

  CHANNEL_ID,

  [

    [

      RATE,

      PERIOD,

      COUNT,

      AMOUNT

    ],

    ...

  ]

]

 

SubscribeRawOrderBook

These are the most granular books.

 

// on trading pairs (ex. tBTCUSD)

[

  CHANNEL_ID,

  [

    [

      ORDER_ID,

      PRICE,

      AMOUNT

    ],

    ...

  ]

]

  

// on funding currencies (ex. fUSD)

[

  CHANNEL_ID,

  [

    [

      OFFER_ID,

      PERIOD,

      RATE,

      AMOUNT

    ],

    ...

  ]

]

 

SubscribeCandles

Provides a way to access charting candle info. 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

7D : one week

14D : two weeks

1M : one month

 

[

  CHANNEL_ID,

  [

    [

      MTS,

      OPEN,

      CLOSE,

      HIGH,

      LOW,

      VOLUME

    ],

    ...

  ]

]

 

 

 

Subscribe Authenticated Channels

This channel allows you to keep up to date with the status of your account. You can receive updates on your positions, your balances, your orders and your trades.

 

Use Authenticate method in order to Authenticate against server and set required parameters.

Once authenticated, you will receive updates of: Orders, positions, trades, funding offers, funding credits, funding loans, wallets, balance info, margin info, funding info, funding trades...

 

 

You can request UnAuthenticate method if you want log off from server.