From 24487f0a820031d20631598aa78bf354847fc3d6 Mon Sep 17 00:00:00 2001 From: Jon Eyrick Date: Sun, 22 Oct 2017 23:22:13 -0700 Subject: [PATCH] Realtime chart data, user balances, trade history --- php-binance-api.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 0e964937..e8a90982 100644 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -449,6 +449,16 @@ public function chart($symbols, $interval = "30m", $callback) { } } + // Keep-alive function for userDataStream + public function keepAlive() { + $loop = \React\EventLoop\Factory::create(); + $loop->addPeriodicTimer(30, function() { + $listenKey = $this->options['listenKey']; + $this->apiRequest("v1/userDataStream?listenKey={$listenKey}", "PUT"); + }); + $loop->run(); + } + // Issues userDataStream token and keepalive, subscribes to userData WebSocket public function userData(&$balance_callback, &$execution_callback = false) { $response = $this->apiRequest("v1/userDataStream", "POST"); @@ -475,10 +485,5 @@ public function userData(&$balance_callback, &$execution_callback = false) { }, function($e) { echo "userData: Could not connect: {$e->getMessage()}".PHP_EOL; }); - /*$loop = \React\EventLoop\Factory::create(); - $loop->addPeriodicTimer(30, function() use ($listenKey) { - $this->apiRequest("v1/userDataStream?listenKey={$listenKey}", "PUT"); - }); - $loop->run();*/ } }