Skip to content

Commit

Permalink
Unable to get private channel data
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Oct 22, 2020
1 parent d615b05 commit ec6a6c6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/Api/WebSocket/SocketClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,14 @@ function test(){
print_r($this->client->keysecret);
print_r($this->client->global_key);
}

function test2(){
//print_r($this->client->global_key);
$global_key=$this->client->global_key;
foreach ($global_key as $k=>$v){
echo $k.PHP_EOL;
print_r($this->client->$v);

}
}
}
3 changes: 2 additions & 1 deletion src/Api/WebSocket/SocketGlobal.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ protected function get($key){
}

protected function save($key,$value){
$this->client->$key=$value;
if(!isset($this->client->$key)) $this->add($key,$value);
else $this->client->$key=$value;
}

protected function addSubUpdate($type='public',$data=[]){
Expand Down
19 changes: 13 additions & 6 deletions src/Api/WebSocket/SocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function onConnect(array $keysecret){
return function($con) use($keysecret){
if(empty($keysecret)) return;

$timestamp=round(microtime(true)*1000)/1000+10;
$timestamp=round(microtime(true)*1000)/1000;

$message = $timestamp.'GET/users/self/verify';
$sign=base64_encode(hash_hmac('sha256', $message, $keysecret['secret'], true));
Expand All @@ -94,21 +94,28 @@ private function onMessage($global){
if(isset($data['table'])) {
$table=$data['table'].':'.$this->getInstrumentId($data);
$table=strtolower($table);
if($con->tag=='private') $table=$con->tag_keysecret['key'].$table;

if($con->tag != 'public') $table=$con->tag_keysecret['key'].$table;

$global->save($table,$data);
return;
}

if(isset($data['event'])) {
if($data['event']=='error') {

$this->log($data);
$this->log($data);
$this->log('event '.$data['event']);

if($data['event']=='error') {
$this->errorMessage($global,$con->tag,$data,isset($con->tag_keysecret)?$con->tag_keysecret:'');

return ;
}

if($data['event']=='subscribe'){
return;
}
if($data['event']=='event unsubscribe'){
return;
}
}

if(isset($data['success'])) {
Expand Down
19 changes: 19 additions & 0 deletions tests/websocket/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,24 @@
]);
break;
}

case 10004:{
//$a='futures/position:bch-usd-210326';
//print_r($okex->client()->$a);
/*$data=$okex->getSubscribe();
print_r(json_encode($data));*/
$okex->client()->test2();

break;
}

case 10005:{
$okex->keysecret($key_secret[0]);
$okex->subscribe([
'futures/position:BCH-USD-210326',
]);
break;
}
}


0 comments on commit ec6a6c6

Please sign in to comment.