Skip to content

Commit

Permalink
added examples/php/react-eventloop-with-rate-limiting.php
Browse files Browse the repository at this point in the history
  • Loading branch information
kroitor committed Dec 21, 2017
1 parent 5e7fe8a commit 0d488da
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions examples/php/react-eventloop-with-rate-limiting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

require dirname(__FILE__).'/../vendor/autoload.php';
include dirname(__FILE__) ."/../vendor/ccxt/ccxt/ccxt.php";

date_default_timezone_set ('UTC');

use TomWright\Database\ExtendedPDO\ExtendedPDO as ExtendedPDO;
use TomWright\Database\QueryBuilder\SqlQueryBuilder as SqlQueryBuilder;

$loop = React\EventLoop\Factory::create ();

// instantiate the exchange by id
$exchange = '\\ccxt\\poloniex';
$exchange = new $exchange ();

$tick_function = function () use ($exchange, $loop, &$tick_function) {
global $exchange, $loop;
$order_book = $exchange->fetch_order_book ($symbol);
echo "----------------------------------------------------------------\n";
echo date ('c') . "\n";
echo count ($order_book['bids']) . " bids and " . count ($order_book['asks']) . " asks\n";
echo sprintf ("bid: %.8f ask: %.8f", $order_book['bids'][0][0], $order_book['asks'][0][0]) . "\n";

$loop->futureTick ($tick_function);
};

$loop->futureTick ($tick_function);
$loop->run ();

0 comments on commit 0d488da

Please sign in to comment.