-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm getting output 'Alarm Clock' and code refusing to do small loop #20
Comments
Thank you for your feedback. I'll check it. The problem is to quote it workerman //The third way is to guard the process
$binance->getSubscribes(function($data){
print_r(json_encode($data));
},true); |
Yeah I found out it comes from pcntl_alarm I keep getting it for either: $binance->getSubscribe([
Will try and use the 'guard' version. |
You try this 'symbol=btcusdt@depth' and comment out the code 'sleep(3)'.The main problem is sleep. $binance->keysecret([
'key' => $binanceConfig['key'],
'secret' => $binanceConfig['secret'],
]);
$binance->subscribe([
'btcusdt@depth'
]);
$x = 15;
while($x > 0){
echo "<br />run $x";
$data = $binance->getSubscribes();
echo "<pre>";
print_r(json_encode($data));
echo "</pre>\n\n";
//sleep(3);
$x = $x - 1;
}
$binance->unsubscribe([
'btcusdt@depth'
]); You need to execute it twice, because the first time you need to subscribe, the second time you can get the data //The third way is to guard the process
$binance->getSubscribes(function($data){
print_r(json_encode($data));
},true); |
I read that pcntl_alarm gets triggered instantly when using sleep(..) indeed so removed that. I then tried to use the 'guard' way to retrieve the data but then I get this problem: When I use
I also get the 'Usage: php yourfile [mode]' error. When I use it without ', true' it runs.. but even then it sometimes works and sometimes doesn't. Example when doesn't work: Then I tried again (this time with 50 run): BTW if I change btcusdt@markPrice to symbol=btcusdt@markPrice then it doesn't work at all anymore. |
ok so I have it working ... sometimes. When I run the script sometimes it works and sometimes I still get 'Alarm clock' my code
I feel I'm doing something wrong conceptually - it can't be using sockets and Binance API are so unreliable that sometimes it works and sometimes it doesn't: Thanks for the help! |
I'm sorry I just told you wrong. I subscribed to'btcusdt@markPrice' but the exchange did not push data, so the data cannot be obtained by'getSubscribe'. The code I gave is to let you subscribe to it'btcusdt@depth', so that you can better analyze the SDK problem or the exchange problem.You copy the code and run directly demo For the stability and maintainability of websocket, I suggest that you should use a cache method for storage, such as redis. Then read the data from redis. Here is a use case to get the market quotation websocket-market (you need to translate it) You can see the source code. |
@zhouaini528 and @StevenFlecha did you guys fixed the issue? Facing the same problem, loop is not working when getting the data from websockets or subscribing the stream, i also tried the third way to guard the processor but no luck.
|
@numairawan The first and second methods I have given can only be executed once in the current process life cycle. If the loop mode is used, the "Alarm Clock" will appear, so the best method is to use the third method. //The first way
$data=$binance->getSubscribe();
print_r(json_encode($data));
//The second way callback
$binance->getSubscribe(function($data){
print_r(json_encode($data));
});
//****Recommended way
//The third way is to guard the process
$binance->getSubscribe(function($data){
print_r(json_encode($data));
},true); The third method uses the closure method. You cannot use variables in this way. The correct way is as follows. $getTickerPrice = '';
$binanceWSSpot->getSubscribe([$symbol],function($data) use($getTickerPrice,$binanceWSSpot){
$getTickerPrice = $data;
//$getTickerPrice = $binanceWSSpot->getSubscribe(["$symbol"]);
if (empty($getTickerPrice)) {
$binanceWSSpot->subscribe(["$symbol"]);
} else {
$tickerPrice = json_encode($getTickerPrice["$symbol"]['data']['c']);
$tickerPrice = str_replace('"', "", $tickerPrice);
},true); |
@zhouaini528 did you update something? It was working fine before like a months ago. I am using the loop to get and update the PnL of open trades. Tried your thirdway, yeah its working but its not working inside any loop. Also i need to start the processor with workerman.
When i start the process, loop dont work. But if i remove "true" processor stopped and print alarm clock.
here is the simple code that was working fine few months back. (sleep is not the issue, even if i dont use delay the loop will stop after 20 to 30 loops)
Check this out.
Result; |
@numairawan The first and second methods of obtaining data are suitable for one-time access. If you want the current process to obtain data multiple times, you must use the "Timer" timer to obtain. You can see my source code (Here). The third method is "Timer". Although the demo you gave is successful, its efficiency is not high, so this method is not recommended. |
@numairawan @StevenFlecha while(1){
pcntl_alarm(0);
sleep(1);
$data=$binance->getSubscribes();
print_r(json_encode($data));
} |
@zhouaini528 Thank you very much now its working fine, but sometimes getSubscribe returning the same value for 10 to 30 minutes, to fix it in loop, subscribe to the same stream in each loop will fix it. |
Hey,
Not an issue but more of a question.
I'm just testing a bit and currently have this code:
And this is the result: https://dl.dropbox.com/s/zxu4sfcjy7931h7/shot_210523_175315.png
I would expect it to run 15 times.. but it runs only once and it outputs this text 'Alarm Clock' it does not come from my code.. I searched your code based and the string 'Alarm Clock' is also nowhere to be found - so I have no idea where that is coming from.
Any ideas what is happening here?
Thanks!
Steven
The text was updated successfully, but these errors were encountered: