1. Go to this page and download the library: Download tigusigalpa/phemex-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/ */
use Tigusigalpa\Phemex\Exceptions\AuthenticationException;
use Tigusigalpa\Phemex\Exceptions\NotFoundException;
use Tigusigalpa\Phemex\Exceptions\RateLimitException;
try {
$positions = $client->usdm()->accountPositions();
} catch (AuthenticationException $e) {
// Invalid or missing credentials
} catch (NotFoundException $e) {
// Resource not found
} catch (RateLimitException $e) {
// $e->retryAfter() and $e->remaining() are available
}
use Tigusigalpa\Phemex\WebSocket\Client;
$ws = new Client('wss://vstream.phemex.com/ws');
$ws->connect(
onMessage: function ($message, $conn) {
echo $message->getPayload() . PHP_EOL;
},
onClose: function ($e) {
echo 'closed' . PHP_EOL;
},
);
$ws->subscribe(['orderbook.subscribe', 'trade.subscribe']);