codenix-sv / bitfinex-api-ws
PHP WebSocket client PHP for the Bitfinex API
Requires
- php: ^7.3
- ext-json: *
- ratchet/pawl: ^0.3.4
- react/socket: ^1.4.0
Requires (Dev)
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-10-29 05:47:19 UTC
README
WebSocket client, written with PHP for bitfinex.com API.
Bitfinex is a full-featured spot trading platform for major digital assets & cryptocurrencies, including Bitcoin, Ethereum, EOS, Litecoin, Ripple, NEO, Monero and many more. Bitfinex offers leveraged margin trading through a peer-to-peer funding market, allowing users to securely trade with up to 3.3x leverage.
For additional information about API visit docs.bitfinex.com/docs/ws-general
Requirements
- PHP >= 7.3
- ext-json
Installation
The preferred way to install this extension is through composer.
Either run
$ composer require codenix-sv/bitfinex-api-ws
or add
"codenix-sv/bitfinex-api-ws": "^0.1"
Basic usage
Example
use Codenixsv\BitfinexWs\BitfinexClient; use Codenixsv\BitfinexWs\WsClient; use Codenixsv\BitfinexWs\Request\SubscribeTicker; use Ratchet\RFC6455\Messaging\Message; $client = new BitfinexClient(); $onMessage = function (Message $message) { echo $message->__toString() . PHP_EOL; }; $onClose = function ($code = null, $reason = null) { echo 'WebSocket Connection closed! Code: ' . $code . ' Reason: ' . $reason . PHP_EOL; }; $onError = function (\Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }; $events = [ WsClient::EVENT_MESSAGE => $onMessage, WsClient::EVENT_CLOSE => $onClose, WsClient::EVENT_ERROR => $onError ]; $client->connect([new SubscribeTicker('tBTCUSD'), new SubscribeTicker('tETHUSD')], $events);
Available channels
Public
SubscribeTicker
The ticker endpoint provides a high level overview of the state of the market for a specified pair. It shows the current best bid and ask, the last traded price, as well as information on the daily volume and price movement over the last day.
$client->connect([new SubscribeTicker('tBTCUSD')], $events);
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 the time of execution. The channel can send funding trade data as well.
$client->connect([new SubscribeTrades('tBTCUSD')], $events);
SubscribeBooks
The Order Books channel allows you to keep track of the state of the Bitfinex order book. It is provided on a price aggregated basis with customizable precision. Upon connecting, you will receive a snapshot of the book followed by updates for any changes to the state of the book.
$symbol = 'tBTCUSD'; $precision = 'P1'; $frequency = 'F1'; $length = '100'; $client->connect([new SubscribeBooks($symbol, $precision, $frequency, $length)], $events);
SubscribeRawBooks
The Raw Books channel provides the most granular books.
$symbol = 'tBTCUSD'; $length = '100'; $client->connect([new SubscribeRawBooks($symbol, $length)], $events);
SubscribeCandles
The Candles endpoint provides OCHL (Open, Close, High, Low) and volume data for the specified trading pair.
$client->connect([new SubscribeCandles('trade:1m:tBTCUSD')], $events);
SubscribeCandles
Subscribe to and receive different types of platform information - currently supports derivatives pair status and liquidation feed.
$client->connect([new SubscribeStatus('deriv:tBTCF0:USTF0')], $events);
License
codenix-sv/bitfinex-api-ws
is released under the MIT License. See the bundled LICENSE for details.