PHP code example of tigusigalpa / zoomex-php

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

    

tigusigalpa / zoomex-php example snippets


use Tigusigalpa\Zoomex\Client;

$client = new Client([
    'api_key' => 'your_api_key',
    'secret_key' => 'your_secret_key',
    'testnet' => false,
]);

// or fluent style
$client = Client::make()
    ->withApiKey('your_api_key')
    ->withSecretKey('your_secret_key')
    ->withTestnet(false);

use Tigusigalpa\Zoomex\Facades\Zoomex;
use Tigusigalpa\Zoomex\DTO\Market\GetTickersRequest;
use Tigusigalpa\Zoomex\Enums\Category;

$tickers = Zoomex::market()->getTickers(
    new GetTickersRequest(category: Category::LINEAR, symbol: 'BTCUSDT')
);

use Tigusigalpa\Zoomex\DTO\Trade\PlaceOrderRequest;
use Tigusigalpa\Zoomex\Enums\{Category, OrderSide, OrderType, TimeInForce};

$order = Zoomex::trade()->placeOrder(new PlaceOrderRequest(
    category: Category::LINEAR,
    symbol: 'BTCUSDT',
    side: OrderSide::BUY,
    orderType: OrderType::LIMIT,
    qty: '0.01',
    price: '50000',
    timeInForce: TimeInForce::GTC
));

use Tigusigalpa\Zoomex\DTO\Position\GetPositionInfoRequest;

$positions = Zoomex::position()->getPositionInfo(
    new GetPositionInfoRequest(category: Category::LINEAR, symbol: 'BTCUSDT')
);

use Tigusigalpa\Zoomex\DTO\Account\GetWalletBalanceRequest;
use Tigusigalpa\Zoomex\Enums\AccountType;

$balance = Zoomex::account()->getWalletBalance(
    new GetWalletBalanceRequest(accountType: AccountType::CONTRACT)
);

use Tigusigalpa\Zoomex\WebSocket;

$ws = new WebSocket(['api_key' => '...', 'secret_key' => '...']);

$ws->subscribeOrderbook('BTCUSDT', 50, function ($data) {
    print_r($data);
});

$ws->run();

$ws->subscribePrivateOrders(function ($data) {
    print_r($data);
});

use Tigusigalpa\Zoomex\Exceptions\{ZoomexApiException, ZoomexRequestException};

try {
    $order = Zoomex::trade()->placeOrder($request);
} catch (ZoomexApiException $e) {
    // $e->retCode, $e->retMsg
} catch (ZoomexRequestException $e) {
    // network issue
}
bash
composer 
bash
php artisan vendor:publish --tag=zoomex-config