CCXT
PHP Examples

Binance Https Proxy

Binance Https Proxy — CCXT PHP code example.

<?php
namespace ccxt;
include_once (__DIR__.'/../../ccxt.php');
// ----------------------------------------------------------------------------

// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code

// -----------------------------------------------------------------------------

error_reporting(E_ALL);
date_default_timezone_set('UTC');

use ccxt\Precise;
use React\Async;
use React\Promise;


// AUTO-TRANSPILE //
'use strict';


var_dump('CCXT Version:', $ccxt->version); // eslint-disable-line import/no-named-as-default-member


$https_proxy_url = $process->env->https_proxy || 'https://username:password@your-proxy.com';


$wss_proxy_url = 'same or another';


var_dump('Using proxy server', $https_proxy_url);


function main() {
    // eslint-disable-next-line import/no-named-as-default-member
    return Async\async(function () {
        $exchange = new \ccxt\async\binance(array(
            'httpsProxy' => $https_proxy_url,
            'wssProxy' => $wss_proxy_url,
        ));
        /*
        //
        // you can also use custom agent, like:
        //
        const HttpsProxyAgent = await import ('https-proxy-agent');
        const httpsAgent = new HttpsProxyAgent (httpsProxyUrl);
        const exchange = new ccxt.binance ({
        'httpsAgent': httpsAgent, // you can pass your custom agent
        'options': {
        'ws': {
        'options': { 'agent': httpsAgent },
        },
        },
        });
         */
        $symbol = 'BTC/USDT';
        \React\Async\await($exchange->load_markets());
        var_dump('Markets loaded');
        // eslint-disable-next-line no-constant-condition
        while (true) {
            try {
                $orderbook = \React\Async\await($exchange->watch_order_book($symbol));
                var_dump($exchange->iso8601($exchange->milliseconds()), $symbol, $orderbook['asks'][0], $orderbook['bids'][0]);
            } catch(Exception $e) {
                var_dump($e);
            }
        }
    }) ();
}


main();