承接 infinex-exchange/infinex-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

infinex-exchange/infinex-php

最新稳定版本:1.1.0

Composer 安装命令:

composer require infinex-exchange/infinex-php

包简介

Official PHP wrapper for the Infinex APIs

README 文档

README

Official PHP wrapper for the Infinex APIs.

Installation

composer require infinex-exchange/infinex-php

Usage

Check examples/ folder for more usage examples.

API

Blocking API over HTTP:

<?php
require __DIR__ . '/vendor/autoload.php';
    
try {
    $infinex = new Infinex\API(
	    new Infinex\Transport\HTTP('https://api.infinex.cc')
	);
	
    var_dump(
        $infinex -> wallet -> getAssets()
    );

	$infinex -> login('api_key_here');
    
    var_dump(
        $infinex -> wallet -> getBalance('USDT')
    );
    
    var_dump(
        $infinex -> spot -> getOrderBook('BPX/USDT')
    );
}
    
catch(Infinex\Exceptions\ConnException $e) {
    echo "Connection error: " . $e->getMessage();
}
    
catch(Infinex\Exceptions\InfinexException $e) {
    echo "Error from exchange: " . $e->getMessage();
}    
?>

Non-blocking async API over HTTP:

<?php
require __DIR__ . '/vendor/autoload.php';
    
$infinex = new Infinex\API(
	new Infinex\Transport\HTTP('https://api.infinex.cc'),
	true
);

$infinex -> login('api_key_here');
	
$infinex -> wallet -> getBalance('BTC') -> then(
	function($response) {
		var_dump($response);
	},
	function($e) {
		echo get_class($e).': '.$e->getMessage()."\n";
	}
);

?>

Blocking API over WebSockets:

<?php
require __DIR__ . '/vendor/autoload.php';

use React\EventLoop\Loop;

$loop = Loop::get();
   
try {
    $infinex = new Infinex\API(
	    new Infinex\Transport\WebSocket($loop, 'wss://mux.infinex.cc')
	);
	
    var_dump(
        $infinex -> wallet -> getAssets()
    );

	$infinex -> login('api_key_here');
    
    var_dump(
        $infinex -> wallet -> getBalance('USDT')
    );
    
    var_dump(
        $infinex -> spot -> getOrderBook('BPX/USDT')
    );
}
    
catch(Infinex\Exceptions\ConnException $e) {
    echo "Connection error: " . $e->getMessage();
}
    
catch(Infinex\Exceptions\InfinexException $e) {
    echo "Error from exchange: " . $e->getMessage();
}

$loop -> run();
?>

Non-blocking async API over WebSockets:

<?php
require __DIR__ . '/vendor/autoload.php';

use React\EventLoop\Loop;

$loop = Loop::get();
   
$infinex = new Infinex\API(
	new Infinex\Transport\WebSocket($loop, 'wss://mux.infinex.cc'),
	true
);

$infinex -> login('api_key_here');
	
$infinex -> wallet -> getBalance('BTC') -> then(
	function($response) {
		var_dump($response);
	},
	function($e) {
		echo get_class($e).': '.$e->getMessage()."\n";
	}
);

$loop -> run();

?>

Streams

To use Infinex streams, you need to create a ReactPHP EventLoop, initialize the StreamsClient object and connect to the exchange server:

use React\EventLoop\Loop;

$loop = Loop::get();

$infinex = new Infinex\StreamsClient($loop, 'wss://stream.infinex.cc');

$infinex -> open() -> then(
	function() {
		echo "Connection successfull\n";
	},
	function($e) {
		echo 'Connection failed: '.$e -> getMessage()."\n";
	}
);

If the connection is broken, the StreamsClient object will automatically reconnect, re-login and restore all subscriptions. However, certain events, e.g. orderbook update, may take place when we were not connected. Therefore, we can catch and react to connection lost and restore events.

$infinex -> on('open', function() {
    echo "Connected to Infinex streams server\n";
});

$infinex -> on('close', function() {
    echo "Disconnected from Infinex streams server\n";
});

To subscribe to a stream or multiple streams we can use the sub function. As the first argument, we pass the name of the stream or an array of stream names, as the second argument we pass the callback function that will be called each time the stream receives an event.

$infinex -> sub(
	'BPX/USDT@ticker',
    function($event) {
        echo 'Alert! Market price changed to '.$event -> price."\n";
    }
) -> then(
	function() {
		echo "Subscribed!\n";
    },
    function($e) {
        echo "Failed to subscribe! '.$e->getMessage()."\n";
    }
);

To unsubscribe from a stream or multiple streams, use the unsub function

$infinex -> unsub('BPX/USDT@ticker') -> then(
	function() {
		echo "Unsubscribed!\n";
    },
    function($e) {
        echo "Failed to unsubscribe! '.$e->getMessage()."\n";
    }
);

To use private streams, login to the exchange with your API key first

$infinex -> login('api_key_here') -> then(
	function() {
		echo "Logged in\n";
	},
	function($e) {
		echo "Login error! ".$e -> getMessage()."\n";
	}
);

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2023-03-04