Skip to content

Commit

Permalink
Add Customize the order ID
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Aug 19, 2019
1 parent 2d3d192 commit e5d50a2
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ $exchanges->trader()->show([
//huobi spot
$exchanges->trader()->show([
'_order_id'=>'29897313869',
//'_client_id'=>'1bc3e974577a6ad9ce730006eafb5522',
]);
//huobi future
$exchanges->trader()->show([
Expand Down
1 change: 1 addition & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ $exchanges->trader()->show([
//huobi spot
$exchanges->trader()->show([
'_order_id'=>'29897313869',
//'_client_id'=>'1bc3e974577a6ad9ce730006eafb5522',
]);
//huobi future
$exchanges->trader()->show([
Expand Down
2 changes: 2 additions & 0 deletions src/Exchanges/Huobi.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function cancel(array $data){
$data['symbol']=preg_replace("/\\d+/",'', $data['symbol']);
return $this->platform_future->contract()->postCancel($data);
}else{
if(isset($data['client-order-id'])) return $this->platform_spot->order()->postSubmitCancelClientOrder($data);
return $this->platform_spot->order()->postSubmitCancel($data);
}
}
Expand All @@ -106,6 +107,7 @@ function show(array $data){
$data['symbol']=preg_replace("/\\d+/",'', $data['symbol']);
return $this->platform_future->contract()->postOrderInfo($data);
}else{
if(isset($data['clientOrderId'])) return $this->platform_spot->order()->getClientOrder($data);
return $this->platform_spot->order()->get($data);
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/Map/RequestTraderMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function buy(array $data){
$map['offset']=$data['offset'] ?? ($data['_entry'] ? 'open' : 'close');
$map['client_order_id']=$data['_client_id'] ?? ($data['client_order_id'] ?? '');
$map['lever_rate']=$data['lever_rate'] ?? 20;
//$map['contract_type']

//市价单与限价单的参数映射
if(isset($data['_price'])){
Expand All @@ -47,6 +46,7 @@ function buy(array $data){
}
case 'spot':{
$map['account-id']=$data['account-id'] ?? $this->extra;
$map['client-order-id']=$data['_client_id'] ?? ($data['client-order-id'] ?? '');

//市价单与限价单的参数映射
if(isset($data['_number']) && isset($data['_price'])){
Expand Down Expand Up @@ -183,7 +183,6 @@ function sell(array $data){
$map['offset']=$data['offset'] ?? ($data['_entry'] ? 'open' : 'close');
$map['client_order_id']=$data['_client_id'] ?? ($data['client_order_id'] ?? '');
$map['lever_rate']=$data['lever_rate'] ?? 20;
//$map['contract_type']

//市价单与限价单的参数映射
if(isset($data['_price'])){
Expand All @@ -196,6 +195,7 @@ function sell(array $data){
}
case 'spot':{
$map['account-id']=$data['account-id'] ?? $this->extra;
$map['client-order-id']=$data['_client_id'] ?? ($data['client-order-id'] ?? '');

//市价单与限价单的参数映射
if(isset($data['_number']) && isset($data['_price'])){
Expand Down Expand Up @@ -328,6 +328,10 @@ function cancel(array $data){
}
case 'spot':{
$map['order-id']=$data['_order_id'] ?? ($data['order-id'] ?? '');

$map['client-order-id']=$data['_client_id'] ?? ($data['client-order-id'] ?? '');
if(empty($map['client-order-id'])) unset($map['client-order-id']);

break;
}
}
Expand Down Expand Up @@ -408,6 +412,10 @@ function show(array $data){
}
case 'spot':{
$map['order-id']=$data['_order_id'] ?? ($data['order-id'] ?? '');

$map['clientOrderId']=$data['_client_id'] ?? ($data['clientOrderId'] ?? '');
if(empty($map['clientOrderId'])) unset($map['clientOrderId']);

break;
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/Map/ResponseTraderMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function buy(array $data){
}
case 'spot':{
$map['_order_id']=$data['result']['data'] ?? '';
$map['_client_id']=$data['request']['_client_id'] ?? ($data['request']['clientOrderId'] ?? '');
break;
}
}
Expand Down Expand Up @@ -178,6 +179,7 @@ function sell(array $data){
}
case 'spot':{
$map['_order_id']=$data['result']['data'] ?? '';
$map['_client_id']=$data['request']['_client_id'] ?? ($data['request']['clientOrderId'] ?? '');
break;
}
}
Expand Down Expand Up @@ -228,14 +230,15 @@ function cancel(array $data){
switch ($this->platform){
case 'huobi':{
switch ($this->checkType($data['request']['_symbol'] ?? '')){
case 'spot':{
$map['_order_id']=$data['result']['data'] ?? '';
break;
}
case 'future':{
$map['_order_id']=$data['result']['data']['successes'] ?? '';
break;
}
case 'spot':{
$map['_order_id']=$data['result']['data'] ?? '';
$map['_client_id']=$data['request']['_client_id'] ?? ($data['request']['clientOrderId'] ?? '');
break;
}
}

if(!isset($data['result']['status']) || $data['result']['status']!='ok') $map['_status']='FAILURE';
Expand Down Expand Up @@ -317,6 +320,7 @@ function show(array $data){
$data['result']['data']['field-amount'] == 0 ? $map['_price_avg']=0:$map['_price_avg']=bcdiv(strval($data['result']['data']['field-cash-amount']),strval($data['result']['data']['field-amount']),16);
$map['_status']=$this->huobi_status['spot'][$data['result']['data']['state']];
$map['_filed_amount']=$data['result']['data']['field-cash-amount'];
$map['_client_id']=$data['request']['_client_id'] ?? ($data['request']['clientOrderId'] ?? '');
break;
}
case 'future':{
Expand Down
85 changes: 80 additions & 5 deletions tests/huobi.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@
//get $account_id,It's for buy and sell
//recommended save database $account_id
$exchanges=new Exchanges('huobi',$key,$secret);
$exchanges->setProxy();
$result=$exchanges->getPlatform('spot')->account()->get();
break;
}

case 100:{
$result=$exchanges->trader()->buy([
'_symbol'=>'btcusdt',
'_price'=>'10',
'_price'=>'20',
]);
break;
}
Expand Down Expand Up @@ -160,22 +161,22 @@

case 300:{
$result=$exchanges->trader()->show([
'_order_id'=>'29897313869',
'_order_id'=>'44997280257',
]);
break;
}

case 301:{
//The original parameters
$result=$exchanges->trader()->show([
'order-id'=>'30002957180',
'order-id'=>'44997280257',
]);
break;
}
case 302:{
//The original parameters
$result=$exchanges->trader()->cancel([
'order-id'=>'30003632696',
'order-id'=>'44997280257',
]);
break;
}
Expand All @@ -199,11 +200,85 @@
}

//***Complete spot flow
case 400:{
case 391:{
echo $_client_id='abc'.rand(10000,99999).rand(10000,99999);
$result=$exchanges->trader()->buy([
'_symbol'=>'btcusdt',
'_number'=>'0.001',
'_price'=>'2000',
'_client_id'=>$_client_id,
]);
break;
}

case 392:{
$result=$exchanges->trader()->show([
'_client_id'=>'abc7083059759',
]);
break;
}

case 393:{
$result=$exchanges->trader()->cancel([
'_client_id'=>'abc7083059759',
]);
break;
}


case 397:{
$_client_id=rand(10000,99999).rand(10000,99999);
$result=$exchanges->trader()->buy([
'_symbol'=>'btcusdt',
'_number'=>'0.001',
'_price'=>'2000',
'_client_id'=>$_client_id,
]);
print_r($result);

$result=$exchanges->trader()->cancel([
'_client_id'=>$_client_id,
]);

break;
}
case 398:{
$_client_id=rand(10000,99999).rand(10000,99999);
$result=$exchanges->trader()->sell([
'_symbol'=>'btcusdt',
'_number'=>'0.001',
'_price'=>'30000',
'_client_id'=>$_client_id,
]);
print_r($result);

$result=$exchanges->trader()->cancel([
'_client_id'=>$_client_id,
]);

break;
}

case 399:{
$result=$exchanges->trader()->buy([
'_symbol'=>'btcusdt',
'_number'=>'0.001',
'_price'=>'2000',
]);
print_r($result);

$result=$exchanges->trader()->cancel([
'_order_id'=>$result['data']['id'],
]);

break;
}

case 400:{
$result=$exchanges->trader()->sell([
'_symbol'=>'btcusdt',
'_number'=>'0.001',
'_price'=>'30000',
]);
print_r($result);

Expand Down

0 comments on commit e5d50a2

Please sign in to comment.