zhouaini528 / binance-php

Binance API Like the official document interface, Support for arbitrary extension.
MIT License
107 stars 43 forks source link

User Data Streams expiring after 24H #23

Open mohammad-rj opened 3 years ago

mohammad-rj commented 3 years ago

after 24 hours our private subscription expires and does not receive the account and order update

zhouaini528 commented 3 years ago

For User Data Streams, I have not set up a reconnection mechanism, only public data is reconnected. Because I am worried that it is not triggered by the initiative, there will be a risk of losing private data. Your business end can set up a monitoring application to determine whether the User Data Streams is disconnected. Simply disconnect and re-subscribe. Let me think about whether we need to improve this one.

mohammad-rj commented 3 years ago

what is the best way? i must delete or unsubscribe the last private subscribe and subscribe again? Or is there a better way? can we add this mechanism on main code ?

zhouaini528 commented 3 years ago

What version of binance-php do you currently have? Is it 2.1.1?

mohammad-rj commented 3 years ago

I'm up to the latest commit

zhouaini528 commented 3 years ago

You look at your log if there is this information "private connection close,ready to reconnect"

Are you subscribing to spot, future, or delivery?

mohammad-rj commented 3 years ago

usdt-future where i must looking for this log ? "private connection close,ready to reconnect"

private function reconnection($global,$type='public',array $keysecret=[]){ $all_sub=$global->get('all_sub'); if(empty($all_sub)) return;

    if($type=='public'){
        $temp=[];
        foreach ($all_sub as $v){
            if(!is_array($v)) $temp[]=$v;
        }

        $global->save('add_sub',$temp);
    }else{

    }
}

and what is this function ?

can we have a function for reconnection private channel ?

zhouaini528 commented 3 years ago

You gave too little information. You need to check the log. I can't locate the problem. But in this case, your business end only needs to re-subscribe once.

This log is in the location set by your config, and the location in the code is at 'private connection close,ready to reconnect'

    private function reconnection($global,$type='public',array $keysecret=[]){
        $all_sub=$global->get('all_sub');
        if(empty($all_sub)) return;

        if($type=='public'){
            $temp=[];
            foreach ($all_sub as $v){
                if(!is_array($v)) $temp[]=$v;
            }

            $global->save('add_sub',$temp);
        }else{

        }
    }

This code indicates that when the user disconnects, they need to re-subscribe to the data. I haven't perfected it here, I only completed the public data. Next I have to complete the right place

I will finish reconnecting to the private channel as soon as possible

mohammad-rj commented 3 years ago

this must was in usdt-future-server2021-06-16-2021-06-17.txt log of server_usdt_future.php , right ? but there is no "private connection close,ready to reconnect"

also when i check test function, that u define for test and debug with switch number 99 on client_usdt_future.php it say : [secret] => xxx my secret [connection] => 1 [listen_key] => xxx my listen_key [listen_key_time] => 1623918598 [connection_close] => 0

connection is true and connection_close is false also it just past 42 minutes of this [listen_key_time] => 1623918598 (its fresh)

i think the reconnecting work truly, but after 24 h binance does not recognize as valid !

I think the previous key should be deleted and a new key created, every 24 hours based on what is described in the Bainance document "A single connection to fstream.binance.com is only valid for 24 hours; expect to be disconnected at the 24 hour mark" https://binance-docs.github.io/apidocs/futures/en/#user-data-streams

what do you think ? did I get it right?

zhouaini528 commented 3 years ago

Your findings are very useful, I need time to test, after the test is successful, I will @you

zhouaini528 commented 3 years ago

Hello, I didn't find 24-hour disconnection after the test. Look at my screenshot, running time is 2021-06-17, I changed the account order, executed and got the data. 微信截图_20210621134116

微信截图_20210621134203

I'm using spot. I'll try futures.

mohammad-rj commented 3 years ago

I have seen this problem several times on futures

zhouaini528 commented 3 years ago

I am testing futures, please wait for my test results

zhouaini528 commented 3 years ago

After 26 hours of testing, I found no disconnection. I changed my account balance and successfully received the data. I will now extend the test time on this basis.

微信截图_20210622164416

微信截图_20210622163823

mohammad-rj commented 3 years ago

oh, so why this issue happened for me ? is it possible it happened because of queue

zhouaini528 commented 3 years ago

The queue data saves 100 pieces of data by default, you can set it by configuring queue_count=100. Because I only do a small amount of data test, I will try to add a lot of data later. please wait for my test results

$binance->config([
    //Number of messages WS queue shuold hold, default 100
    'queue_count'=>100,
]);
zhouaini528 commented 3 years ago

After 6 days 20 hours of testing, I found no disconnection.

微信截图_20210628110242

微信截图_20210628110441