PHP code example of infinex-exchange / infinex-php

1. Go to this page and download the library: Download infinex-exchange/infinex-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

infinex-exchange / infinex-php example snippets



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();
}    


$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";
	}
);



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();


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();


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";
	}
);

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

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

$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";
    }
);

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

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