Skip to content

Commit

Permalink
signature bool compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Jan 4, 2021
1 parent 0ac9842 commit dd9f319
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
17 changes: 15 additions & 2 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ protected function signature(){
$this->data['timestamp']=$this->nonce;

ksort($this->data);
$this->signature = hash_hmac('sha256', urldecode(http_build_query($this->data)), $this->secret);

$temp=$this->data;
foreach ($temp as $k=>$v) if(is_bool($v)) $temp[$k]=$v?'true':'false';

$this->signature = hash_hmac('sha256', urldecode(http_build_query($temp)), $this->secret);
}
}

Expand Down Expand Up @@ -109,7 +113,16 @@ protected function send(){
$url=$this->host.$this->path;

if($this->type=='GET') $url.= '?'.http_build_query($this->data).($this->signature!=''?'&sign='.$this->signature:'');
else $this->options['body']=json_encode(array_merge($this->data,['sign'=>$this->signature]));
else {
$temp=$this->data;

foreach ($temp as $k=>$v){
if($v=='true') $temp[$k]=true;
if($v=='false') $temp[$k]=false;
}

$this->options['body']=json_encode(array_merge($temp,['sign'=>$this->signature]));
}

$response = $client->request($this->type, $url, $this->options);

Expand Down
14 changes: 10 additions & 4 deletions tests/linear/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,28 @@
//'verify'=>false,
]);


try {
$result=$bybit->privates()->postOrderCreate([
//'order_link_id'=>'xxxxxxxxxxxxxx',
'side'=>'Buy',
'side'=>'Sell',
'symbol'=>'BTCUSDT',
'order_type'=>'Limit',
'qty'=>'1',
'price'=>'4000',
'qty'=>'0.25',
'price'=>'40000',
'time_in_force'=>'GoodTillCancel',

'reduce_only'=>'false',
'close_on_trigger'=>'false',
//or set
'reduce_only'=>false,
'close_on_trigger'=>false
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}


try {
$result=$bybit->privates()->getOrderSearch([
'order_id'=>'xxxxxxxxxxxxx',
Expand Down

0 comments on commit dd9f319

Please sign in to comment.