Skip to content

Commit

Permalink
Private and Public channel reconnect
Browse files Browse the repository at this point in the history
zhouaini528 committed Jul 15, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 8b6fde5 commit 8d09794
Showing 4 changed files with 38 additions and 16 deletions.
27 changes: 15 additions & 12 deletions src/Api/WebSocket/SocketClient.php
Original file line number Diff line number Diff line change
@@ -168,6 +168,21 @@ protected function getData($global,$callback=null,$sub=[]){
return $temp;
}

/*
*
* */
function reconPrivate(string $key){
$this->client->debug=[
'private'=>[$key=>'close'],
];
}

function reconPublic(){
$this->client->debug=[
'public'=>['public'=>'close','kline'=>'close'],
];
}

function test(){
print_r($this->client->all_sub);
print_r($this->client->add_sub);
@@ -185,19 +200,7 @@ function test2(){
}
}

function test_reconnection(){
$this->client->debug=[
'public'=>['public'=>'close','kline'=>'close'],
];
}

function test_reconnection2(){
$this->client->debug2=1;
}

function test_reconnection3($key){
$this->client->debug=[
'private'=>[$key=>'close'],
];
}
}
8 changes: 7 additions & 1 deletion src/Api/WebSocket/SocketServer.php
Original file line number Diff line number Diff line change
@@ -253,6 +253,12 @@ private function debug($con,$global){
$debug['private'][$con->tag_keysecret['key']]='recon';
$global->save('debug',$debug);

//更改登录状态
$this->keysecretInit($con->tag_keysecret,[
'connection'=>2,
'auth'=>0,
]);

$con->close();
}
}
@@ -303,7 +309,7 @@ private function subscribe($con,$global){
if($con->tag!='public' && !empty($temp['private'])){
//判断是否鉴权登录
$keysecret=$global->get('keysecret');
if($keysecret[$con->tag_keysecret['key']]['auth']==0) {
if($keysecret[$con->tag_keysecret['key']]['auth']!=1 || $keysecret[$con->tag_keysecret['key']]['key']!=$con->tag_keysecret['key']) {
$this->log($con->tag_keysecret['key'].' subscribe need login ');
return;
}
14 changes: 14 additions & 0 deletions src/BitmexWebSocket.php
Original file line number Diff line number Diff line change
@@ -84,4 +84,18 @@ public function getSubscribes($callback=null,$daemon=false){
return $this->client()->getSubscribes($callback,$daemon);
}

/**
* Private channel reconnect
* @param string $key
*/
public function reconPrivate(string $key){
$this->client()->reconPrivate($key);
}

/**
* Public channel reconnect
*/
public function reconPublic(){
$this->client()->reconPublic();
}
}
5 changes: 2 additions & 3 deletions tests/websocket/client.php
Original file line number Diff line number Diff line change
@@ -272,8 +272,7 @@
}

case 10005:{
$bitmex->client()->test_reconnection();

$bitmex->reconPublic();
break;
}

@@ -283,7 +282,7 @@
}

case 10008:{
$bitmex->client()->test_reconnection3($key_secret[0]['key']);
$bitmex->reconPrivate($key_secret[0]['key']);
break;
}
}

0 comments on commit 8d09794

Please sign in to comment.