Skip to content

Commit

Permalink
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 ca51eee commit 64ce167
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 2 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,45 @@ try {
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}

//***********************Customize the order ID
//Place an Order
try {
$client_order_id=rand(10000,99999).rand(10000,99999);
$result=$huobi->order()->postPlace([
'account-id'=>$account_id,
'symbol'=>'btcusdt',
'type'=>'buy-limit',
'amount'=>'0.001',
'price'=>'1000',
'client-order-id'=>$client_order_id,
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
sleep(1);

//Get order details by order ID.
try {
$result=$huobi->order()->getClientOrder([
'clientOrderId'=>$client_order_id,
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
sleep(1);

//Cancelling an unfilled order.
try {
$result=$huobi->order()->postSubmitCancelClientOrder([
'client-order-id'=>$client_order_id,
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
```

Accounts related API [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/spot/account.php)
Expand Down
39 changes: 39 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,45 @@ try {
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}

//***********************Customize the order ID
//Place an Order
try {
$client_order_id=rand(10000,99999).rand(10000,99999);
$result=$huobi->order()->postPlace([
'account-id'=>$account_id,
'symbol'=>'btcusdt',
'type'=>'buy-limit',
'amount'=>'0.001',
'price'=>'1000',
'client-order-id'=>$client_order_id,
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
sleep(1);

//Get order details by order ID.
try {
$result=$huobi->order()->getClientOrder([
'clientOrderId'=>$client_order_id,
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
sleep(1);

//Cancelling an unfilled order.
try {
$result=$huobi->order()->postSubmitCancelClientOrder([
'client-order-id'=>$client_order_id,
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
```

Accounts related API [More](https://github.com/zhouaini528/huobi-php/blob/master/tests/spot/account.php)
Expand Down
26 changes: 26 additions & 0 deletions src/Api/Spot/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ public function postSubmitCancel(array $data){
return $this->exec();
}

/**
* 撤销订单(基于client order ID) POST /v1/order/orders/submitCancelClientOrder
*
* 参数名称 是否必须 类型 描述 默认值 取值范围
client-order-id true string 用户自编订单号
* */
public function postSubmitCancelClientOrder(array $data){
$this->type='POST';
$this->path='/v1/order/orders/submitCancelClientOrder';
$this->data=$data;
return $this->exec();
}

/**
*
* */
Expand Down Expand Up @@ -61,6 +74,19 @@ public function get(array $data){
return $this->exec();
}

/**
* 查询订单详情(基于client order ID) GET /v1/order/orders/getClientOrder
*
* 参数名称 是否必须 类型 描述 默认值 取值范围
clientOrderId true string 用户自编订单号
* */
public function getClientOrder(array $data){
$this->type='GET';
$this->path='/v1/order/orders/getClientOrder';
$this->data=$data;
return $this->exec();
}

/**
* 用户订单信息 GET /v1/order/orders GET 查询用户当前委托、或历史委托订单 (up to 100) Y Y
* */
Expand Down
45 changes: 43 additions & 2 deletions tests/spot/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

$huobi=new HuobiSpot($key,$secret);

//If you are developing locally and need an agent, you can set this
$huobi->setProxy();

$huobi->setTimeOut(10);
//Set the request timeout to 60 seconds by default
$huobi->setTimeOut(5);

//Place an Order
try {
Expand Down Expand Up @@ -57,5 +58,45 @@
print_r(json_decode($e->getMessage(),true));
}

//***********************Customize the order ID
//Place an Order
try {
$client_order_id=rand(10000,99999).rand(10000,99999);
$result=$huobi->order()->postPlace([
'account-id'=>$account_id,
'symbol'=>'btcusdt',
'type'=>'buy-limit',
'amount'=>'0.001',
'price'=>'1000',
'client-order-id'=>$client_order_id,
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
sleep(1);

//Get order details by order ID.
try {
$result=$huobi->order()->getClientOrder([
'clientOrderId'=>$client_order_id,
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
sleep(1);

//Cancelling an unfilled order.
try {
$result=$huobi->order()->postSubmitCancelClientOrder([
'client-order-id'=>$client_order_id,
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}




0 comments on commit 64ce167

Please sign in to comment.