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 2e420d6 commit de25de5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Binance.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Binance
protected $host;

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

function __construct(string $key='',string $secret='',string $host='https://api.binance.com'){
$this->key=$key;
Expand All @@ -32,6 +33,7 @@ private function init(){
'key'=>$this->key,
'secret'=>$this->secret,
'host'=>$this->host,
'timeout'=>$this->timeout,
];
}

Expand All @@ -52,6 +54,13 @@ function setProxy($proxy=true){
$this->proxy=$proxy;
}

/**
* Set the request timeout to 60 seconds by default
* */
function setTimeOut($timeout=60){
$this->timeout=$timeout;
}

/**
*
* */
Expand Down
3 changes: 3 additions & 0 deletions tests/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

$binance=new Binance();

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

//Order book
try {
$result=$binance->system()->getDepth([
Expand Down
3 changes: 3 additions & 0 deletions tests/trade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

$binance=new Binance($key,$secret);

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

//Send in a new order.
try {
$result=$binance->trade()->postOrder([
Expand Down
5 changes: 4 additions & 1 deletion tests/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

$binance=new Binance($key,$secret);

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

//Get all account orders; active, canceled, or filled.
try {
$result=$binance->user()->getAllOrders([
Expand All @@ -30,7 +33,7 @@
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}

die();
//Get current account information.
try {
$result=$binance->user()->getAccount();
Expand Down

0 comments on commit de25de5

Please sign in to comment.