PHP code example of mrabdelaziz / binance-api

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

    

mrabdelaziz / binance-api example snippets


use MrAbdelaziz\BinanceApi\Facades\BinanceApi;

// Get account information
$account = BinanceApi::account()->getAccountInfo();

// Get account balances
$balances = BinanceApi::account()->getAccountBalances();

// Get account trading status
$status = BinanceApi::account()->getAccountStatus();

// Place a market buy order
$order = BinanceApi::orders()->marketBuy('BTCUSDT', 0.001);

// Place a limit sell order
$order = BinanceApi::orders()->limitSell('BTCUSDT', 0.001, 50000);

// Cancel an order
$cancelled = BinanceApi::orders()->cancelOrder('BTCUSDT', $orderId);

// Get order status
$orderStatus = BinanceApi::orders()->getOrder('BTCUSDT', $orderId);

// Get all orders for a symbol
$orders = BinanceApi::orders()->getAllOrders('BTCUSDT');

// Get current price
$price = BinanceApi::market()->getPrice('BTCUSDT');

// Get 24hr ticker
$ticker = BinanceApi::market()->get24hrTicker('BTCUSDT');

// Get exchange info
$exchangeInfo = BinanceApi::market()->getExchangeInfo();

// Get open positions
$positions = BinanceApi::positions()->getOpenPositions();

// Get position for specific symbol
$position = BinanceApi::positions()->getPosition('BTCUSDT');

// Get position history
$history = BinanceApi::positions()->getPositionHistory('BTCUSDT');

use MrAbdelaziz\BinanceApi\Exceptions\BinanceApiException;

try {
    $order = BinanceApi::orders()->marketBuy('BTCUSDT', 0.001);
} catch (BinanceApiException $e) {
    // Handle Binance API errors
    Log::error('Binance API Error: ' . $e->getMessage());
    Log::error('Error Code: ' . $e->getCode());
    Log::error('Error Data: ' . json_encode($e->getData()));
}

'rate_limits' => [
    'requests_per_minute' => 1200,
    'orders_per_second' => 10,
    'orders_per_day' => 200000,
],

// Using custom configuration
$customApi = new BinanceApi([
    'api_key' => 'custom_key',
    'api_secret' => 'custom_secret',
    'base_url' => 'https://testnet.binance.vision',
]);

$account = $customApi->account()->getAccountInfo();
bash
php artisan vendor:publish --tag="binance-api-config"