Kucoin / kucoin-php-sdk

PHP SDK for KuCoin API.
https://docs.kucoin.com
MIT License
79 stars 41 forks source link

Using WS message in event loop #128

Open makopov opened 2 years ago

makopov commented 2 years ago

I have 3 questions here...

  1. I'm trying to figure out how to pass the message received by the WS to the event loop, see code below.
  2. Is this the right way to handle ws messages asynchronously? I notice delays with the more topics I subscribe to.
  3. My IDE is showing that React Factory is deprecated, are there plans to stop usages of it in the future?

        $loop = Factory::create();
        $loop->addPeriodicTimer(1, function($message) {
           var_dump('loop: ' . date('Y-m-d H:i:s'));
           var_dump($message);
        });
        $api->setLoop($loop);

        $api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) use(&$exchange, &$interval, &$results) {
            // $loop->run();
            // print $message['data']['symbol'] . PHP_EOL;

            }
        }, function ($code, $reason) {
            echo "OnClose: {$code} {$reason}\n";
        });