项目作者: codenix-sv

项目描述 :
WebSocket client in PHP for the Bitfinex API
高级语言: PHP
项目地址: git://github.com/codenix-sv/bitfinex-api-ws.git
创建时间: 2018-03-20T17:28:09Z
项目社区:https://github.com/codenix-sv/bitfinex-api-ws

开源协议:MIT License

下载


bitfinex-api-ws

Build Status
Scrutinizer Code Quality
Test Coverage
Maintainability
License: MIT

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

  1. $ composer require codenix-sv/bitfinex-api-ws

or add

  1. "codenix-sv/bitfinex-api-ws": "^0.1"

Basic usage

Example

  1. use Codenixsv\BitfinexWs\BitfinexClient;
  2. use Codenixsv\BitfinexWs\WsClient;
  3. use Codenixsv\BitfinexWs\Request\SubscribeTicker;
  4. use Ratchet\RFC6455\Messaging\Message;
  5. $client = new BitfinexClient();
  6. $onMessage = function (Message $message) {
  7. echo $message->__toString() . PHP_EOL;
  8. };
  9. $onClose = function ($code = null, $reason = null) {
  10. echo 'WebSocket Connection closed! Code: ' . $code . ' Reason: ' . $reason . PHP_EOL;
  11. };
  12. $onError = function (\Exception $e) {
  13. echo 'Error: ' . $e->getMessage() . PHP_EOL;
  14. };
  15. $events = [
  16. WsClient::EVENT_MESSAGE => $onMessage,
  17. WsClient::EVENT_CLOSE => $onClose,
  18. WsClient::EVENT_ERROR => $onError
  19. ];
  20. $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.

  1. $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.

  1. $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.

  1. $symbol = 'tBTCUSD';
  2. $precision = 'P1';
  3. $frequency = 'F1';
  4. $length = '100';
  5. $client->connect([new SubscribeBooks($symbol, $precision, $frequency, $length)], $events);

SubscribeRawBooks

The Raw Books channel provides the most granular books.

  1. $symbol = 'tBTCUSD';
  2. $length = '100';
  3. $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.

  1. $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.

  1. $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.