PHP code example of samrap / gemini

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

    

samrap / gemini example snippets


use Samrap\Gemini\Gemini;

$key = 'mykey';
$secret = '1234abcd'
$gemini = new Gemini($key, $secret);

$gemini = new Gemini();
$symbols = $gemini->symbols();

print_r($symbols); // ["btc-usd", "ethbtc", "ethusd"]

$gemini = new Gemini();
$symbol = 'ethusd';
$orderBook = $gemini->currentOrderBook($symbol, [
    'limit_bids' => 10,
    'limit_asks' => 10,
]);

$gemini = new Gemini();
$symbol = 'ethusd';
$orderBook = $gemini->currentOrderBook($symbol);

$gemini = new Gemini('mykey', '1234abcd');
$order = $gemini->newOrder([
    'client_order_id' => '20150102-4738721',
    'symbol' => 'btcusd',      
    'amount' => '34.12',       
    'price' => '622.13',
    'side' => 'buy',           
    'type' => 'exchange limit',
    'options' => ['maker-or-cancel'],
]);


use Samrap\Gemini\Exceptions\GeminiException;
use Samrap\Gemini\Exceptions\MaintenanceException;
use Samrap\Gemini\Exceptions\OrderNotFoundException;

// ...

public function getOrderStatus($order_id)
{
    try {
        $status = $this->gemini->orderStatus([
            'order_id' => $order_id,
        ])
    } catch (OrderNotFoundException $e) {
        return 'The order you searched for does not exist.';
    } catch (MaintenanceException $e) {
        $this->logger->critical($e->getMessage());

        return 'The API is currently unavailable';
    } catch (GeminiException $e) {
        $this->logger->warn($e->getMessage())
    }

    return $status['original_amount'];
}

composer