Skip to content

Commit

Permalink
add okex v5
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Nov 2, 2021
1 parent 53b70cb commit 2ed1aa8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Api/Trader.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function buy(array $data,bool $show=true){
$map=$this->map->requestTrader()->buy($data);
//print_r($map);//die;
$result=$this->exchange->trader()->buy($map);
//print_r($result);//die;
//print_r($result);
$trader=$this->map->responseTrader()->buy(['result'=>$result,'request'=>$data]);
//print_r($trader);

Expand Down
21 changes: 13 additions & 8 deletions src/Map/RequestTraderMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ function buy(array $data){
case 'margin':{
break;
}
case 'future':{
$map['tdMode']=$data['tdMode'] ?? 'cross';
break;
}
case 'future':
case 'swap':{
$map['tdMode']=$data['tdMode'] ?? 'cross';
$map['posSide']='long';
$map['sz']=$data['_number'] ?? 0;

//平多
if(!$data['_entry']) $map['side']='sell';

break;
}
}
Expand Down Expand Up @@ -374,12 +377,14 @@ function sell(array $data){
case 'margin':{
break;
}
case 'future':{
$map['tdMode']=$data['tdMode'] ?? 'cross';
break;
}
case 'future':
case 'swap':{
$map['tdMode']=$data['tdMode'] ?? 'cross';
$map['posSide']='short';
$map['sz']=$data['_number'] ?? 0;
//平空
if(!$data['_entry']) $map['side']='buy';

break;
}
}
Expand Down
52 changes: 52 additions & 0 deletions tests/okex.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,58 @@
}


//v5 future
case 10200:{
$exchanges->setOptions([
//Set the request timeout to 60 seconds by default
'timeout'=>10,
//set Demo Trading
'headers'=>['x-simulated-trading'=>1]
]);
$exchanges->setPlatform('future')->setVersion('v5');
$result=$exchanges->trader()->buy([
'_symbol'=>'BTC-USD-220325',
'_number'=>'1',
'_price'=>'20000',
//'_price'=>'100',
'_client_id'=>'xxxxx'.rand(10000,99999),
'_entry'=>true
]);
print_r($result);

$result=$exchanges->trader()->cancel([
'_symbol'=>'BTC-USD-220325',
//'_order_id'=>'',
'_client_id'=>$result['_client_id'],
]);
break;
}
case 10201:{
$exchanges->setOptions([
//Set the request timeout to 60 seconds by default
'timeout'=>10,
//set Demo Trading
'headers'=>['x-simulated-trading'=>1]
]);
$exchanges->setPlatform('future')->setVersion('v5');
$result=$exchanges->trader()->buy([
'_symbol'=>'BTC-USD-220325',
'_number'=>'1',
'_entry'=>true
]);
print_r($result);

$result=$exchanges->trader()->buy([
'_symbol'=>'BTC-USD-220325',
'_number'=>'1',
'_entry'=>false
]);


print_r($result);
break;
}

default:{
echo 'nothing';
exit;
Expand Down

0 comments on commit 2ed1aa8

Please sign in to comment.