Пример #1
0
$volatility = $argv[5];
$maxDelta = $argv[6];
echo $channel . "\n";
echo $sPrice . "\n";
## ---------------------------------------------------------------------------
## Publish Example
## ---------------------------------------------------------------------------
echo "Running publish\r\n";
$currPrice = $sPrice;
while (1) {
    $t = time() . "";
    $now = new DateTime();
    $change = (rand(0, $volatility) - $volatility / 2) / 100;
    $vol = rand(100, 1000) * 10;
    $currPrice = $currPrice + $change;
    $delta = $currPrice - $sPrice;
    $perc = round((1 - $sPrice / $currPrice) * 100, 2);
    $stream = array("time" => $now->format("g:i:sa"), "price" => number_format($currPrice, 2, '.', ''), "delta" => number_format($delta, 2, '.', ''), "perc" => number_format($perc, 2, '.', ''), "vol" => $vol);
    $publish_success = $pubnub->publish($channel, $stream);
    echo $t . " " . $publish_success[0] . " " . $publish_success[1];
    echo "\r\n";
    $slptime = rand($minTrade, $maxTrade);
    // Rest Price if Detla is greater than 25%.
    // This is because it is fake data anyway and
    // we want the stock price to run forever
    // randomly in a working demo state.
    if (abs($perc) > $maxDelta / 100) {
        $currPrice = $sPrice;
    }
    usleep($slptime);
}