Back to Ccxt

Apex Watch

wiki/examples/php/apex-watch.md

4.5.562.1 KB
Original Source
php
<?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


function loop($exchange, $symbol) {
   return Async\async(function () use ($exchange, $symbol) {
       while (true) {
           try {
               $ticker = \React\Async\await($exchange->watch_ticker($symbol));
               var_dump(new Date(), $exchange->id, $symbol);
               var_dump($ticker);
               \React\Async\await($exchange->sleep(1000));
           } catch(Exception $e) {
               var_dump($e);
           }
       }

   }) ();
}


function main() {
   return Async\async(function () {
       $exchange = new \ccxt\pro\apex(array(
           'apiKey' => 'your api Key',
           'secret' => 'your api secret',
           'walletAddress' => 'your eth address',
           'options' => array(
               'accountId' => 'your account id',
               'passphrase' => 'your api passphrase',
               'seeds' => 'your zklink omni seed',
               'brokerId' => '',
           ),
       ));
       $exchange->set_sandbox_mode(true);
       if ($exchange->has['watchTicker']) {
           \React\Async\await($exchange->load_markets());
           $target_symbols = ['BTC-USDT', 'ETH-USDT'];
           for ($i = 0; $i < count($target_symbols); $i++) {
               $symbol = $target_symbols[$i];
               \React\Async\await(loop($exchange, $symbol));
           }
       } else {
           var_dump($exchange->id, 'does not support watchTicker yet');
       }
   }) ();
}


main();