Skip to content

Commit

Permalink
Merge pull request #98 from stingbo/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
stingbo authored Apr 23, 2021
2 parents f5b4428 + 319d444 commit 99b0d3b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/Binance/Kernel/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ protected function registerHttpMiddlewares()
break;
}

// log
$this->pushMiddleware($this->logMiddleware(), 'log');

// proxy
$this->pushMiddleware($this->proxyMiddleware(), 'proxy');

// log
$this->pushMiddleware($this->logMiddleware(), 'log');
}

/**
Expand Down
13 changes: 6 additions & 7 deletions src/Coinbase/Kernel/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,16 @@ protected function registerHttpMiddlewares()
{
$this->pushMiddleware($this->addHeaderMiddleware('Content-Type', 'application/json'), 'add_header_content_type');
if ('SIGN' == $this->sign_type) {
// signature
$this->timestamp = $this->getRequestDateTime();
$this->pushMiddleware($this->addHeaderMiddleware('CB-ACCESS-KEY', $this->app->config->get('app_key')), 'add_header_appkey');
$this->pushMiddleware($this->addHeaderMiddleware('CB-ACCESS-TIMESTAMP', $this->timestamp), 'add_header_timestamp');
$this->pushMiddleware($this->addHeaderMiddleware('CB-ACCESS-PASSPHRASE', $this->app->config->get('passphrase')), 'add_header_passphrase');
$this->pushMiddleware($this->signatureMiddleware(), 'signature');
}

// log
$this->pushMiddleware($this->logMiddleware(), 'log');

// proxy
$this->pushMiddleware($this->proxyMiddleware(), 'proxy');

// log
$this->pushMiddleware($this->logMiddleware(), 'log');
}

/**
Expand All @@ -62,6 +59,7 @@ protected function signatureMiddleware()
{
return function (callable $handler) {
return function (RequestInterface $request, array $options) use ($handler) {
$this->timestamp = $this->getRequestDateTime();
$method = $request->getMethod();
$uri_path = $request->getUri()->getPath();
if ('POST' == $method) { // POST
Expand All @@ -73,6 +71,7 @@ protected function signatureMiddleware()
$signature = $this->getSignature($this->timestamp, $method, $uri_path, $query);
}
$request = $request->withHeader('CB-ACCESS-SIGN', $signature);
$request = $request->withHeader('CB-ACCESS-TIMESTAMP', $this->timestamp);

return $handler($request, $options);
};
Expand All @@ -82,7 +81,7 @@ protected function signatureMiddleware()
/**
* A timestamp for your request.
*
* @return float
* @return int
*/
public function getRequestDateTime()
{
Expand Down
6 changes: 3 additions & 3 deletions src/Gate/Kernel/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ protected function registerHttpMiddlewares()
$this->pushMiddleware($this->signatureMiddleware(), 'signature');
}

// log
$this->pushMiddleware($this->logMiddleware(), 'log');

// proxy
$this->pushMiddleware($this->proxyMiddleware(), 'proxy');

// log
$this->pushMiddleware($this->logMiddleware(), 'log');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Huobi/Kernel/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ protected function registerHttpMiddlewares()
$this->pushMiddleware($this->signatureMiddleware(), 'signature');
}

// log
$this->pushMiddleware($this->logMiddleware(), 'log');

// proxy
$this->pushMiddleware($this->proxyMiddleware(), 'proxy');

// log
$this->pushMiddleware($this->logMiddleware(), 'log');
}

/**
Expand Down
13 changes: 6 additions & 7 deletions src/Okex/Kernel/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,16 @@ protected function registerHttpMiddlewares()
$this->pushMiddleware($this->addHeaderMiddleware('Content-Type', 'application/json'), 'add_header_content_type');
$this->pushMiddleware($this->addHeaderMiddleware('x-simulated-trading', $this->app->config->get('x-simulated-trading')), 'add_header_test');
if ('SIGN' == $this->sign_type) {
// signature
$this->timestamp = $this->getRequestDateTime();
$this->pushMiddleware($this->addHeaderMiddleware('OK-ACCESS-KEY', $this->app->config->get('app_key')), 'add_header_appkey');
$this->pushMiddleware($this->addHeaderMiddleware('OK-ACCESS-TIMESTAMP', $this->timestamp), 'add_header_timestamp');
$this->pushMiddleware($this->addHeaderMiddleware('OK-ACCESS-PASSPHRASE', $this->app->config->get('passphrase')), 'add_header_passphrase');
$this->pushMiddleware($this->signatureMiddleware(), 'signature');
}

// log
$this->pushMiddleware($this->logMiddleware(), 'log');

// proxy
$this->pushMiddleware($this->proxyMiddleware(), 'proxy');

// log
$this->pushMiddleware($this->logMiddleware(), 'log');
}

/**
Expand All @@ -63,6 +60,7 @@ protected function signatureMiddleware()
{
return function (callable $handler) {
return function (RequestInterface $request, array $options) use ($handler) {
$this->timestamp = $this->getRequestDateTime();
$method = $request->getMethod();
$uri_path = $request->getUri()->getPath();
if ('POST' == $method) { // POST
Expand All @@ -73,6 +71,7 @@ protected function signatureMiddleware()
parse_str($request->getUri()->getQuery(), $query);
$signature = $this->getSignature($this->timestamp, $method, $uri_path, $query);
}
$request = $request->withHeader('OK-ACCESS-TIMESTAMP', $this->timestamp);
$request = $request->withHeader('OK-ACCESS-SIGN', $signature);

return $handler($request, $options);
Expand All @@ -83,7 +82,7 @@ protected function signatureMiddleware()
/**
* UTC ISO格式时间.
*
* @return float
* @return string
*/
public function getRequestDateTime()
{
Expand Down
15 changes: 15 additions & 0 deletions tests/Okex/Market/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ public function testTicker()
$this->assertSame('mock-result', $client->ticker($instId));
}

public function testIndexTickers()
{
$client = $this->mockApiClient(Client::class);
$quoteCcy = 'BTC';
$instId = 'BTC-USD-SWAP';
$params = [
'quoteCcy' => $quoteCcy,
'instId' => $instId,
];

$client->expects()->httpGet('/api/v5/market/index-tickers', $params)->andReturn('mock-result');

$this->assertSame('mock-result', $client->indexTickers($quoteCcy, $instId));
}

public function testDepth()
{
$client = $this->mockApiClient(Client::class);
Expand Down

0 comments on commit 99b0d3b

Please sign in to comment.