Back to Ccxt

Many Exchanges Synchronously

wiki/examples/php/many-exchanges-synchronously.md

4.5.57762 B
Original Source
php
<?php
include './ccxt.php';


$config = array('enableRateLimit' => true);
$binance = new \ccxt\pro\binance($config);
$bittrex = new \ccxt\pro\bittrex($config);
$symbol = "BTC/USDT";

$loop = function($exchange, $symbol) {
   echo 'got inside' . PHP_EOL;
   for ($i = 0; $i < 5; $i++) {
       $ticker = yield $exchange->watch_ticker($symbol);
       print_ticker($ticker, $exchange->id, $symbol);
   }
};

function print_ticker($ticker, $exchange_name, $symbol) {
   $bid = $ticker['bid'];
   $ask = $ticker['ask'];
   echo "$exchange_name $symbol - bid: $bid <> ask: $ask" . PHP_EOL;
}

\React\Async\coroutine($loop, $bittrex, $symbol);
\React\Async\coroutine($loop, $binance, $symbol);