PHP code example of cryptohopper / sdk

1. Go to this page and download the library: Download cryptohopper/sdk 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/ */

    

cryptohopper / sdk example snippets




use Cryptohopper\Sdk\Client;
use Cryptohopper\Sdk\Exceptions\CryptohopperException;

$client = new Client(apiKey: getenv('CRYPTOHOPPER_TOKEN'));

try {
    $me      = $client->user->get();
    $hoppers = $client->hoppers->list();
    $ticker  = $client->exchange->ticker(exchange: 'binance', market: 'BTC/USDT');
} catch (CryptohopperException $e) {
    fwrite(STDERR, "{$e->getCode()} / {$e->getStatus()}: {$e->getMessage()}\n");
    if ($e->getCode() === 'RATE_LIMITED' && $e->getRetryAfterMs() !== null) {
        fwrite(STDERR, "Retry after {$e->getRetryAfterMs()}ms\n");
    }
}

$client = new Client(
    apiKey: 'your-40-char-oauth-token',
    appKey: 'your-oauth-client-id', // optional, sent as x-api-app-key
);

$client = new Client(
    apiKey:     getenv('CRYPTOHOPPER_TOKEN'),
    appKey:     getenv('CRYPTOHOPPER_APP_KEY'),
    baseUrl:    'https://api.cryptohopper.com/v1', // override for staging
    timeout:    30,                                 // per-request, seconds
    maxRetries: 3,                                  // HTTP 429 backoff
    userAgent:  'my-app/1.0',                       // appended after 'cryptohopper-sdk-php/<v>'
);

try {
    $client->hoppers->get('not-a-real-id');
} catch (CryptohopperException $e) {
    $e->getCode();          // string: 'NOT_FOUND', 'UNAUTHORIZED', 'RATE_LIMITED', ...
    $e->getStatus();        // int: HTTP status (0 on network error)
    $e->getServerCode();    // int|null: Cryptohopper numeric code when present
    $e->getIpAddress();     // string|null: server-reported caller IP, if any
    $e->getRetryAfterMs();  // int|null: parsed Retry-After (only on 429)
}