Skip to content

Commit

Permalink
Set the request timeout to 60 seconds by default
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Jul 22, 2019
1 parent 38bd988 commit 4ed3614
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/Api/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@ function getPlatform(string $type=''){
function setProxy($proxy=true){
$this->platform->setProxy($proxy);
}

/**
* Set the request timeout to 60 seconds by default
* */
function setTimeOut($timeout=60){
$this->platform->setTimeOut($timeout);
}
}
11 changes: 11 additions & 0 deletions src/Exchanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Exchanges
protected $platform;

protected $proxy=false;
protected $timeout=60;

protected $acount;
protected $market;
Expand All @@ -42,18 +43,21 @@ function __construct(string $exchange,string $key,string $secret,string $extra='
function account(){
$this->acount=new Account($this->exchange,$this->key,$this->secret,$this->extra,$this->host);
$this->acount->setProxy($this->proxy);
$this->acount->setTimeOut($this->timeout);
return $this->acount;
}

function market(){
$this->market=new Market($this->exchange,$this->key,$this->secret,$this->extra,$this->host);
$this->market->setProxy($this->proxy);
$this->market->setTimeOut($this->timeout);
return $this->market;
}

function trader(){
$this->trader=new Trader($this->exchange,$this->key,$this->secret,$this->extra,$this->host);
$this->trader->setProxy($this->proxy);
$this->trader->setTimeOut($this->timeout);
return $this->trader;
}

Expand Down Expand Up @@ -84,4 +88,11 @@ public function getPlatform(string $type=''){
function setProxy($proxy=true){
$this->proxy=$proxy;
}

/**
* Set the request timeout to 60 seconds by default
* */
function setTimeOut($timeout=60){
$this->timeout=$timeout;
}
}
7 changes: 7 additions & 0 deletions src/Exchanges/Binance.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,11 @@ function getPlatform(string $type=''){
function setProxy($proxy=true){
$this->platform->setProxy($proxy);
}

/**
* Set the request timeout to 60 seconds by default
* */
function setTimeOut($timeout=60){
$this->platform->setTimeOut($timeout);
}
}
7 changes: 7 additions & 0 deletions src/Exchanges/Bitmex.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,11 @@ function getPlatform(string $type=''){
function setProxy($proxy=true){
$this->platform->setProxy($proxy);
}

/**
* Set the request timeout to 60 seconds by default
* */
function setTimeOut($timeout=60){
$this->platform->setTimeOut($timeout);
}
}
8 changes: 8 additions & 0 deletions src/Exchanges/Huobi.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,12 @@ function setProxy($proxy=true){
$this->platform_future->setProxy($proxy);
$this->platform_spot->setProxy($proxy);
}

/**
* Set the request timeout to 60 seconds by default
* */
function setTimeOut($timeout=60){
$this->platform_future->setTimeOut($timeout);
$this->platform_spot->setTimeOut($timeout);
}
}
9 changes: 9 additions & 0 deletions src/Exchanges/Okex.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,13 @@ function setProxy($proxy=true){
$this->platform_spot->setProxy($proxy);
$this->platform_swap->setProxy($proxy);
}

/**
* Set the request timeout to 60 seconds by default
* */
function setTimeOut($timeout=60){
$this->platform_future->setTimeOut($timeout);
$this->platform_spot->setTimeOut($timeout);
$this->platform_swap->setTimeOut($timeout);
}
}
2 changes: 1 addition & 1 deletion src/Map/RequestTraderMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ function show(array $data){

switch ($this->platform){
case 'huobi':{
switch ($this->checkType($data['_symbol'] ?? $data['symbol'])){
switch ($this->checkType($data['_symbol'] ?? ($data['symbol'] ?? ''))){
case 'future':{
$map['order_id']=$data['_order_id'] ?? ($data['order_id'] ?? '');
$map['client_order_id']=$data['_client_id'] ?? ($data['client_order_id'] ?? '');
Expand Down
12 changes: 9 additions & 3 deletions tests/binance.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
//If you are developing locally and need an agent, you can set this
$exchanges->setProxy();

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

$action=intval($_GET['action'] ?? 0);//http pattern
if(empty($action)) $action=intval($argv[1]);//cli pattern

Expand Down Expand Up @@ -194,19 +197,22 @@
]);
print_r($result);

$result=$exchanges->trader()->cancel([
$result=$exchanges->trader()->cancel([
'_symbol'=>'BTCUSDT',
//'_order_id'=>$result['orderId'],
'_client_id'=>$_client_id,
]);
]);

break;
}

//******************************Complete future flow
case 450:{


$result=$exchanges->trader()->cancel([
'_symbol'=>'BTCUSDT',
'_client_id'=>'4b9dd6a3916561da4c7931ec63870bbf',
]);
break;
}

Expand Down
3 changes: 3 additions & 0 deletions tests/bitmex.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
//If you are developing locally and need an agent, you can set this
$exchanges->setProxy();

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

$action=intval($_GET['action'] ?? 0);//http pattern
if(empty($action)) $action=intval($argv[1]);//cli pattern

Expand Down
3 changes: 3 additions & 0 deletions tests/huobi.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
//If you are developing locally and need an agent, you can set this
$exchanges->setProxy();

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

$action=intval($_GET['action'] ?? 0);//http pattern
if(empty($action)) $action=intval($argv[1]);//cli pattern

Expand Down
3 changes: 3 additions & 0 deletions tests/okex.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
//If you are developing locally and need an agent, you can set this
$exchanges->setProxy();

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

$action=intval($_GET['action'] ?? 0);//http pattern
if(empty($action)) $action=intval($argv[1]);//cli pattern

Expand Down

0 comments on commit 4ed3614

Please sign in to comment.