Skip to content

Commit

Permalink
Add Request Options
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Aug 23, 2019
1 parent a1bd754 commit beec594
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 193 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,22 @@ System error unified parameter return [binance](https://github.com/zhouaini528/e
[huobi](https://github.com/zhouaini528/exchanges-php/blob/master/tests/huobi.php#L35)
[bitmex](https://github.com/zhouaini528/exchanges-php/blob/master/tests/bitmex.php#L35)

Local development sets the proxy [More](https://github.com/zhouaini528/exchanges-php/blob/master/tests/okex.php#L53)
Support for more request Settings [More](https://github.com/zhouaini528/exchanges-php/blob/master/tests/okex.php#L53)
```php
//If you are developing locally and need an agent, you can set this
$exchanges->setProxy();

//More flexible Settings
$exchanges->setProxy([
'http' => 'http://127.0.0.1:12333',
'https' => 'http://127.0.0.1:12333',
$exchanges->setOptions([
//Set the request timeout to 60 seconds by default
'timeout'=>10,

//If you are developing locally and need an agent, you can set this
'proxy'=>true,
//More flexible Settings
/* 'proxy'=>[
'http' => 'http://127.0.0.1:12333',
'https' => 'http://127.0.0.1:12333',
'no' => ['.cn']
], */
//Close the certificate
//'verify'=>false,
]);
```

Expand Down
23 changes: 15 additions & 8 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,22 @@ Buy Sell 方法默认有[2秒](https://github.com/zhouaini528/exchanges-php/blob
[huobi](https://github.com/zhouaini528/exchanges-php/blob/master/tests/huobi.php#L35)
[bitmex](https://github.com/zhouaini528/exchanges-php/blob/master/tests/bitmex.php#L35)

支持本地开发代理设置 [More](https://github.com/zhouaini528/exchanges-php/blob/master/tests/okex.php#L53)
支持更多的请求设置 [More](https://github.com/zhouaini528/exchanges-php/blob/master/tests/okex.php#L53)
```php
//如果您正在本地开发需要代理,您可以这样设置
$exchanges->setProxy();

//更灵活的代理设置
$exchanges->setProxy([
'http' => 'http://127.0.0.1:12333',
'https' => 'http://127.0.0.1:12333',
$exchanges->setOptions([
//设置请求超时时间,默认60s
'timeout'=>10,

//如果您正在本地开发需要代理,您可以这样设置
'proxy'=>true,
//更灵活的代理设置
/* 'proxy'=>[
'http' => 'http://127.0.0.1:12333',
'https' => 'http://127.0.0.1:12333',
'no' => ['.cn']
], */
//是否开启证书
//'verify'=>false,
]);
```

Expand Down
29 changes: 4 additions & 25 deletions src/Api/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class Base

protected $map;

protected $proxy=false;

/**
* 初始化交易所
* */
Expand Down Expand Up @@ -75,35 +73,16 @@ protected function error($msg){
}

/**
*
* Returns the underlying instance object
* */
function getPlatform(string $type=''){
return $this->platform->getPlatform($type);
}

/**
* Local development sets the proxy
* @param bool|array
* $proxy=false Default
* $proxy=true Local proxy http://127.0.0.1:12333
*
* Manual proxy
* $proxy=[
'http' => 'http://127.0.0.1:12333',
'https' => 'http://127.0.0.1:12333',
'no' => ['.cn']
* ]
*
* @param mixed
* */
function setProxy($proxy=true){
$this->platform->setProxy($proxy);
}

/**
* Set the request timeout to 60 seconds by default
* Support for more request Settings
* */
function setTimeOut($timeout=60){
$this->platform->setTimeOut($timeout);
function setOptions(array $options=[]){
$this->platform->setOptions($options);
}
}
48 changes: 18 additions & 30 deletions src/Exchanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ class Exchanges

protected $platform;

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

protected $acount;
protected $market;
protected $trader;

protected $options=[];


function __construct(string $exchange,string $key,string $secret,string $extra='',string $host=''){
$this->exchange=$exchange;
Expand All @@ -40,29 +39,35 @@ 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);
$this->acount->setOptions($this->options);
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);
$this->market->setOptions($this->options);
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);
$this->trader->setOptions($this->options);
return $this->trader;
}

/**
* Support native access
* Returns the underlying instance object
* */
public function getPlatform(string $type=''){
if($this->trader!==null) return $this->trader->getPlatform($type);
Expand All @@ -73,26 +78,9 @@ public function getPlatform(string $type=''){
}

/**
* Local development sets the proxy
* @param bool|array
* $proxy=false Default
* $proxy=true Local proxy http://127.0.0.1:12333
*
* Manual proxy
* $proxy=[
'http' => 'http://127.0.0.1:12333',
'https' => 'http://127.0.0.1:12333',
'no' => ['.cn']
* ]
* */
function setProxy($proxy=true){
$this->proxy=$proxy;
}

/**
* Set the request timeout to 60 seconds by default
* Support for more request Settings
* */
function setTimeOut($timeout=60){
$this->timeout=$timeout;
function setOptions(array $options=[]){
$this->options=$options;
}
}
25 changes: 3 additions & 22 deletions src/Exchanges/Binance.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,9 @@ function getPlatform(string $type=''){
}

/**
* Local development sets the proxy
* @param bool|array
* $proxy=false Default
* $proxy=true Local proxy http://127.0.0.1:12333
*
* Manual proxy
* $proxy=[
'http' => 'http://127.0.0.1:12333',
'https' => 'http://127.0.0.1:12333',
'no' => ['.cn']
* ]
*
* @param mixed
* */
function setProxy($proxy=true){
$this->platform->setProxy($proxy);
}

/**
* Set the request timeout to 60 seconds by default
* Support for more request Settings
* */
function setTimeOut($timeout=60){
$this->platform->setTimeOut($timeout);
function setOptions(array $options=[]){
$this->platform->setOptions($options);
}
}
25 changes: 3 additions & 22 deletions src/Exchanges/Bitmex.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,9 @@ function getPlatform(string $type=''){
}

/**
* Local development sets the proxy
* @param bool|array
* $proxy=false Default
* $proxy=true Local proxy http://127.0.0.1:12333
*
* Manual proxy
* $proxy=[
'http' => 'http://127.0.0.1:12333',
'https' => 'http://127.0.0.1:12333',
'no' => ['.cn']
* ]
*
* @param mixed
* */
function setProxy($proxy=true){
$this->platform->setProxy($proxy);
}

/**
* Set the request timeout to 60 seconds by default
* Support for more request Settings
* */
function setTimeOut($timeout=60){
$this->platform->setTimeOut($timeout);
function setOptions(array $options=[]){
$this->platform->setOptions($options);
}
}
27 changes: 4 additions & 23 deletions src/Exchanges/Huobi.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,31 +160,12 @@ function getPlatform(string $type=''){
}
}

/**
* Local development sets the proxy
* @param bool|array
* $proxy=false Default
* $proxy=true Local proxy http://127.0.0.1:12333
*
* Manual proxy
* $proxy=[
'http' => 'http://127.0.0.1:12333',
'https' => 'http://127.0.0.1:12333',
'no' => ['.cn']
* ]
*
* @param mixed
* */
function setProxy($proxy=true){
$this->platform_future->setProxy($proxy);
$this->platform_spot->setProxy($proxy);
}

/**
* Set the request timeout to 60 seconds by default
* Support for more request Settings
* */
function setTimeOut($timeout=60){
$this->platform_future->setTimeOut($timeout);
$this->platform_spot->setTimeOut($timeout);
function setOptions(array $options=[]){
$this->platform_future->setOptions($options);
$this->platform_spot->setOptions($options);
}
}
31 changes: 5 additions & 26 deletions src/Exchanges/Okex.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,32 +197,11 @@ function getPlatform(string $type=''){
}

/**
* Local development sets the proxy
* @param bool|array
* $proxy=false Default
* $proxy=true Local proxy http://127.0.0.1:12333
*
* Manual proxy
* $proxy=[
'http' => 'http://127.0.0.1:12333',
'https' => 'http://127.0.0.1:12333',
'no' => ['.cn']
* ]
*
* @param mixed
* */
function setProxy($proxy=true){
$this->platform_future->setProxy($proxy);
$this->platform_spot->setProxy($proxy);
$this->platform_swap->setProxy($proxy);
}

/**
* Set the request timeout to 60 seconds by default
* Support for more request Settings
* */
function setTimeOut($timeout=60){
$this->platform_future->setTimeOut($timeout);
$this->platform_spot->setTimeOut($timeout);
$this->platform_swap->setTimeOut($timeout);
function setOptions(array $options=[]){
$this->platform_future->setOptions($options);
$this->platform_spot->setOptions($options);
$this->platform_swap->setOptions($options);
}
}
Loading

0 comments on commit beec594

Please sign in to comment.