1Forge / php-forex-quotes

PHP Library for fetching realtime forex quotes.
https://1forge.com/forex-data-api
MIT License
71 stars 14 forks source link

Undefined offset: 2 #2

Closed smallpen closed 5 years ago

smallpen commented 6 years ago

Sometime use websocket to receive prices will happen exception "Receive server happen exception => Undefined offset: 2" ! Here is my code

try {
            $this->webSocket_client->onUpdate(function ($symbol, $data) {
                echo "[" . Carbon::now('Asia/Taipei')->toDateTimeString() . "] Receive {$symbol} ..." . PHP_EOL;
                echo "[" . Carbon::now('Asia/Taipei')->toDateTimeString() . "] Price => " . var_dump($data) . PHP_EOL;
                try {
                    $price = round($data['price'], 6);
                    $id = $this->product_list[$symbol];
                    $this->product_redisServer->hset($id, 'price', $price);
                } catch (\Exception $exception) {
                    echo "[" . Carbon::now('Asia/Taipei')->toDateTimeString() . "] Receive price happen exception => {$exception->getMessage()}" . PHP_EOL;
                }
            });

            $this->webSocket_client->onMessage(function ($message) {
                echo $message;
            });

            $this->webSocket_client->connect(function ($client) {
                //Subscribe to an array of currency pairs
                $client->subscribeTo([
                    'EURUSD',
                    'USDJPY',
                    'AUDUSD',
                    'GBPUSD',
                    'EURGBP',
                    'EURJPY',
                    'GBPJPY',
                    'BTCUSD',
                    'ETHUSD',
                    'XAUUSD',
                    'XAGUSD'
                ]);
            });
        } catch (\Exception $exception) {
            echo "[" . Carbon::now('Asia/Taipei')->toDateTimeString() . "] Receive server happen exception => {$exception->getMessage()}" . PHP_EOL;
        }
brutus-gr commented 6 years ago

Hello,

Can you please tell me what version of the library you are currently using (in your composer.json file).

smallpen commented 6 years ago

name : oneforge/forexquotes descrip. : Library to fetch and parse realtime Forex quotes and convert currencies keywords : api, forex, quotes, realtime versions : * 2.0.10 type : library

smallpen commented 6 years ago

Here is trace log !

`BinaryGameServer: Receive 1forge price happen exception!Task has been stop! Error=> Undefined offset: 2, Trace => #0 /home/chris/GameServer/vendor/wisembly/elephant.io/src/Engine/AbstractSocketIO.php(125): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined offse...', '/home/chris/Gam...', 125, Array)

1 /home/chris/GameServer/vendor/wisembly/elephant.io/src/Client.php(86): ElephantIO\Engine\AbstractSocketIO->read()

2 /home/chris/GameServer/vendor/oneforge/forexquotes/lib/ForexDataClient.php(162): ElephantIO\Client->read()

3 /home/chris/GameServer/app/Console/Commands/receivePrice.php(118): OneForge\ForexQuotes\ForexDataClient->connect(Object(Closure))

4 [internal function]: App\Console\Commands\receivePrice->handle()

5 /home/chris/GameServer/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)

6 /home/chris/GameServer/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container{closure}()

7 /home/chris/GameServer/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))

8 /home/chris/GameServer/vendor/laravel/framework/src/Illuminate/Container/Container.php(549): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)

9 /home/chris/GameServer/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Container\Container->call(Array)

10 /home/chris/GameServer/vendor/symfony/console/Command/Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))

11 /home/chris/GameServer/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))

12 /home/chris/GameServer/vendor/symfony/console/Application.php(946): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

13 /home/chris/GameServer/vendor/symfony/console/Application.php(248): Symfony\Component\Console\Application->doRunCommand(Object(App\Console\Commands\receivePrice), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

14 /home/chris/GameServer/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

15 /home/chris/GameServer/vendor/laravel/framework/src/Illuminate/Console/Application.php(88): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

16 /home/chris/GameServer/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

17 /home/chris/GameServer/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

18 {main}`

brutus-gr commented 6 years ago

Hi @smallpen,

I am having trouble replicating the issue.

Can you tell me: 1) How often does this happen. Every time you run it, or seemingly randomly? 2) Do you notice anything else when it happens (eg: dropped connection, market closing, etc...)

smallpen commented 6 years ago

It seem this issue ! https://github.com/Wisembly/elephant.io/issues/149

brutus-gr commented 6 years ago

@smallpen It looks like the library isn't maintained anymore unfortunately. You might be better of switching to javascript and using https://www.npmjs.com/package/forex-quotes - it's far more stable.

We'll eventually try to move off of elephant.io or switch to a fork that's more stable.