php-binance-api icon indicating copy to clipboard operation
php-binance-api copied to clipboard

how to listen to websocket in background?

Open hamedbaftam opened this issue 4 years ago • 1 comments

how to listen to websocket in background?

hamedbaftam avatar Jul 14 '20 09:07 hamedbaftam

Hello,

This question has multiple solutions, you can find multiple path on the internet.

One solution that come to my mind would by to use the Symfony's Console component and run your scripts the the & operator.

An example of what the solution could be:

namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ListenSocketCommand extends Command
{
    protected static $defaultName = 'app:listen-socket';

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $api = new API('apiKey', 'apiSecret');

        $api->kline(["BTCUSDT", "EOSBTC"], "5m", function($api, $symbol, $chart) {
            // do whatever you want
        });
        return Command::SUCCESS;
    }
}

And call the command by doing (in a terminal) bin/console app:listen-socket & (the last char is where the magic happens)

dFayet avatar Sep 06 '20 17:09 dFayet