php-binance-api.php
public function ticker($symbol, callable $callback)
    {
        $endpoint = $symbol ? strtolower($symbol) . '@ticker' : '!ticker@arr';
        $this->subscriptions[$endpoint] = true;

        // @codeCoverageIgnoreStart
        // phpunit can't cover async function
        \Ratchet\Client\connect($this->stream . $endpoint)->then(function ($ws) use ($callback, $symbol, $endpoint) {
            $ws->on('message', function ($data) use ($ws, $callback, $symbol, $endpoint) {
                if ($this->subscriptions[$endpoint] === false) {
                    //$this->subscriptions[$endpoint] = null;
                    $ws->close();
                    return; //return $ws->close();
                }
                $json = json_decode($data);
                if ($symbol) {
                    call_user_func($callback, $this, $symbol, $this->tickerStreamHandler($json));
                } else {
                    foreach ($json as $obj) {
                        $return = $this->tickerStreamHandler($obj);
                        $symbol = $return['symbol'];
                        call_user_func($callback, $this, $symbol, $return);
                    }
                }
            });
            $ws->on('close', function ($code = null, $reason = null) {
                // WPCS: XSS OK.
                echo "ticker: WebSocket Connection closed! ({$code} - {$reason})" . PHP_EOL;
            });
        }, function ($e) {
            // WPCS: XSS OK.
            echo "ticker: Could not connect: {$e->getMessage()}" . PHP_EOL;
        });
        // @codeCoverageIgnoreEnd
    }
public function ticker($symbol, callable $callback)
    {
        $endpoint = $symbol ? strtolower($symbol) . '@ticker' : '!ticker@arr';
        $this->subscriptions[$endpoint] = true;

        // @codeCoverageIgnoreStart
        // phpunit can't cover async function
        \Ratchet\Client\connect($this->stream . $endpoint)->then(function ($ws) use ($callback, $symbol, $endpoint) {
            $ws->on('message', function ($data) use ($ws, $callback, $symbol, $endpoint) {
                if ($this->subscriptions[$endpoint] === false) {
                    //$this->subscriptions[$endpoint] = null;
                    $ws->close();
                    return; //return $ws->close();
                }
                $json = json_decode($data);
                if ($symbol) {
                    call_user_func($callback, $this, $symbol, $this->tickerStreamHandler($json));
                } else {
                    foreach ($json as $obj) {
                        $return = $this->tickerStreamHandler($obj);
                        $symbol = $return['symbol'];
                        call_user_func($callback, $this, $symbol, $return);
                    }
                }
            });
            $ws->on('close', function ($code = null, $reason = null) {
                // WPCS: XSS OK.
                echo "ticker: WebSocket Connection closed! ({$code} - {$reason})" . PHP_EOL;
            });
        }, function ($e) {
            // WPCS: XSS OK.
            echo "ticker: Could not connect: {$e->getMessage()}" . PHP_EOL;
        });
        // @codeCoverageIgnoreEnd
    }
public function ticker ( $ symbol , callable $ callback ) { $ endpoint = $ symbol ? strtolower ( $ symbol ) . '@ticker' : '!ticker@arr' ; $ this -> subscriptions [ $ endpoint ] = true ; // @codeCoverageIgnoreStart // phpunit can't cover async function \ Ratchet \ Client \ connect ( $ this -> stream . $ endpoint ) -> then ( function ( $ ws ) use ( $ callback , $ symbol , $ endpoint ) { $ ws -> on ( 'message' , function ( $ data ) use ( $ ws , $ callback , $ symbol , $ endpoint ) { if ( $ this -> subscriptions [ $ endpoint ] === false ) { //$this->subscriptions[$endpoint] = null; $ ws -> close ( ) ; return ; //return $ws->close(); } $ json = json_decode ( $ data ) ; if ( $ symbol ) { call_user_func ( $ callback , $ this , $ symbol , $ this -> tickerStreamHandler ( $ json ) ) ; } else { foreach ( $ json as $ obj ) { $ return = $ this -> tickerStreamHandler ( $ obj ) ; $ symbol = $ return [ 'symbol' ] ; call_user_func ( $ callback , $ this , $ symbol , $ return ) ; } } } ) ; $ ws -> on ( 'close' , function ( $ code = null , $ reason = null ) { // WPCS: XSS OK. echo "ticker: WebSocket Connection closed! ({$code} - {$reason})" . PHP_EOL ; } ) ; } , function ( $ e ) { // WPCS: XSS OK. echo "ticker: Could not connect: {$e->getMessage()}" . PHP_EOL ; } ) ; // @codeCoverageIgnoreEnd }
ticker pulls 24h price change statistics via WebSocket

$api->ticker(false, function($api, $symbol, $ticker) {
print_r($ticker);
});

@param $symbol string optional symbol or false
@param $callback callable closure
@return null
ticker pulls 24h price change statistics via WebSocket