Skip to content

Commit

Permalink
Default Huobi order-id priority query
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed May 13, 2021
1 parent 83082c8 commit 73124f2
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions src/Exchanges/Huobi.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class BaseHuobi
protected $platform_future;
protected $platform_spot;
protected $platform_swap;

function __construct(HuobiFuture $platform_future,HuobiSpot $platform_spot,HuobiSwap $platform_swap){
$this->platform_future=$platform_future;
$this->platform_spot=$platform_spot;
$this->platform_swap=$platform_swap;
}

protected function checkType($symbol){
if(is_numeric(substr($symbol,-1,1))) return 'future';
if(stristr($symbol,'-USD')) return 'swap';
Expand All @@ -40,7 +40,7 @@ function get(array $data){
$temp='';
if(isset($data['symbol'])) $temp=$data['symbol'];
if(isset($data['contract_code'])) $temp=$data['contract_code'];

switch ($this->checkType($temp)){
case 'future':{
$data['symbol']=preg_replace("/\\d+/",'', $data['symbol']);
Expand Down Expand Up @@ -75,7 +75,7 @@ function sell(array $data){
$temp='';
if(isset($data['symbol'])) $temp=$data['symbol'];
if(isset($data['contract_code'])) $temp=$data['contract_code'];

switch ($this->checkType($temp)){
case 'future':{
return $this->platform_future->contract()->postOrder($data);
Expand All @@ -88,15 +88,15 @@ function sell(array $data){
}
}
}

/**
*
* */
function buy(array $data){
$temp='';
if(isset($data['symbol'])) $temp=$data['symbol'];
if(isset($data['contract_code'])) $temp=$data['contract_code'];

switch ($this->checkType($temp)){
case 'future':{
return $this->platform_future->contract()->postOrder($data);
Expand All @@ -109,15 +109,15 @@ function buy(array $data){
}
}
}

/**
*
* */
function cancel(array $data){
$temp='';
if(isset($data['symbol'])) $temp=$data['symbol'];
if(isset($data['contract_code'])) $temp=$data['contract_code'];

switch ($this->checkType($temp)){
case 'future':{
$data['symbol']=preg_replace("/\\d+/",'', $data['symbol']);
Expand All @@ -132,37 +132,38 @@ function cancel(array $data){
}
}
}

/**
*
* */
function update(array $data){
return [];
}

/**
*
* */
function show(array $data){
$temp='';
if(isset($data['symbol'])) $temp=$data['symbol'];
if(isset($data['contract_code'])) $temp=$data['contract_code'];

switch ($this->checkType($temp)){
case 'future':{
$data['symbol']=preg_replace("/\\d+/",'', $data['symbol']);
return $this->platform_future->contract()->postOrderInfo($data);
}
case 'spot':{
if(isset($data['clientOrderId'])) return $this->platform_spot->order()->getClientOrder($data);
return $this->platform_spot->order()->get($data);
//order-id
if(isset($data['order-id'])) return $this->platform_spot->order()->get($data);
return $this->platform_spot->order()->getClientOrder($data);
}
case 'swap':{
return $this->platform_swap->account()->postOrderInfo($data);
}
}
}

/**
*
* */
Expand All @@ -176,27 +177,27 @@ class Huobi
protected $platform_future;
protected $platform_spot;
protected $platform_swap;

function __construct($key,$secret,$host=''){
$this->platform_future=new HuobiFuture($key,$secret,empty($host) ? 'https://api.hbdm.com' : $host);

$this->platform_spot=new HuobiSpot($key,$secret,empty($host) ? 'https://api.huobi.pro' : $host);

$this->platform_swap=new HuobiSwap($key,$secret,empty($host) ? 'https://api.hbdm.com' : $host);
}

function account(){
return new AccountHuobi($this->platform_future,$this->platform_spot,$this->platform_swap);
}

function market(){
return new MarketHuobi($this->platform_future,$this->platform_spot,$this->platform_swap);
}

function trader(){
return new TraderHuobi($this->platform_future,$this->platform_spot,$this->platform_swap);
}

function getPlatform(string $type=''){
switch (strtolower($type)){
case 'spot':{
Expand All @@ -213,8 +214,8 @@ function getPlatform(string $type=''){
}
}
}


/**
* Support for more request Settings
* */
Expand All @@ -223,4 +224,4 @@ function setOptions(array $options=[]){
$this->platform_spot->setOptions($options);
$this->platform_swap->setOptions($options);
}
}
}

0 comments on commit 73124f2

Please sign in to comment.