Skip to content

Commit

Permalink
Merge pull request #6688 from dennydanek/master
Browse files Browse the repository at this point in the history
relocation verbose
  • Loading branch information
kroitor committed Mar 27, 2020
2 parents 4472cdc + bb5831a commit 437abd5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
31 changes: 20 additions & 11 deletions js/base/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,42 +462,50 @@ module.exports = class Exchange {
}
}

print (... args) {
console.log (... args)
}

fetch (url, method = 'GET', headers = undefined, body = undefined) {

if (isNode && this.userAgent) {
if (typeof this.userAgent === 'string')
if (typeof this.userAgent === 'string') {
headers = extend ({ 'User-Agent': this.userAgent }, headers)
else if ((typeof this.userAgent === 'object') && ('User-Agent' in this.userAgent))
} else if ((typeof this.userAgent === 'object') && ('User-Agent' in this.userAgent)) {
headers = extend (this.userAgent, headers)
}
}

if (typeof this.proxy === 'function') {

url = this.proxy (url)
if (isNode)
if (isNode) {
headers = extend ({ 'Origin': this.origin }, headers)
}

} else if (typeof this.proxy === 'string') {

if (this.proxy.length)
if (isNode)
headers = extend ({ 'Origin': this.origin }, headers)
if (this.proxy.length && isNode) {
headers = extend ({ 'Origin': this.origin }, headers)
}

url = this.proxy + url
}

headers = extend (this.headers, headers)

if (this.verbose)
console.log ("fetch:\n", this.id, method, url, "\nRequest:\n", headers, "\n", body, "\n")
if (this.verbose) {
this.print ("fetch:\n", this.id, method, url, "\nRequest:\n", headers, "\n", body, "\n")
}

return this.executeRestRequest (url, method, headers, body)
}

async fetch2 (path, type = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {

if (this.enableRateLimit)
if (this.enableRateLimit) {
await this.throttle (this.rateLimit)
}

const request = this.sign (path, type, method, params, headers, body)
return this.fetch (request.url, request.method, request.headers, request.body)
Expand Down Expand Up @@ -612,8 +620,9 @@ module.exports = class Exchange {
this.last_json_response = json // FIXME: for those classes that haven't switched to handleErrors yet
}

if (this.verbose)
console.log ("handleRestResponse:\n", this.id, method, url, response.status, response.statusText, "\nResponse:\n", responseHeaders, "\n", responseBody, "\n")
if (this.verbose) {
this.print ("handleRestResponse:\n", this.id, method, url, response.status, response.statusText, "\nResponse:\n", responseHeaders, "\n", responseBody, "\n")
}

this.handleErrors (response.status, response.statusText, url, method, responseHeaders, responseBody, json, requestHeaders, requestBody)
this.defaultErrorHandler (response.status, response.statusText, url, method, responseHeaders, responseBody, json)
Expand Down
15 changes: 11 additions & 4 deletions php/base/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,15 @@ public function parse_json($json_string, $as_associative_array = true) {
return json_decode($json_string, $as_associative_array);
}

public function print() {
$args = func_get_args();
if (is_array($args)) {
foreach ($args as $arg) {
print_r($arg);
}
}
}

public function fetch($url, $method = 'GET', $headers = null, $body = null) {
if ($this->enableRateLimit) {
$this->throttle();
Expand Down Expand Up @@ -1292,8 +1301,7 @@ public function fetch($url, $method = 'GET', $headers = null, $body = null) {
}

if ($this->verbose) {
print_r("\nRequest:\n");
print_r(array($method, $url, $verbose_headers, $body));
$this->print("\nRequest:\n", array($method, $url, $verbose_headers, $body));
}

// we probably only need to set it once on startup
Expand Down Expand Up @@ -1375,8 +1383,7 @@ function ($curl, $header) use (&$response_headers, &$http_status_text) {
$http_status_code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);

if ($this->verbose) {
print_r("\nResponse:\n");
print_r(array($method, $url, $http_status_code, $curl_error, $response_headers, $result));
$this->print("\nResponse:\n", array($method, $url, $http_status_code, $curl_error, $response_headers, $result));
}

$this->handle_errors($http_status_code, $http_status_text, $url, $method, $response_headers, $result ? $result : null, $json_response, $headers, $body);
Expand Down
4 changes: 2 additions & 2 deletions python/ccxt/async_support/base/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def fetch(self, url, method='GET', headers=None, body=None):
url = self.proxy + url

if self.verbose:
print("\nRequest:", method, url, headers, body)
self.print("\nRequest:", method, url, headers, body)
self.logger.debug("%s %s, Request: %s %s", method, url, headers, body)

request_body = body
Expand Down Expand Up @@ -130,7 +130,7 @@ async def fetch(self, url, method='GET', headers=None, body=None):
if self.enableLastJsonResponse:
self.last_json_response = json_response
if self.verbose:
print("\nResponse:", method, url, http_status_code, headers, http_response)
self.print("\nResponse:", method, url, http_status_code, headers, http_response)
self.logger.debug("%s %s, Response: %s %s %s", method, url, http_status_code, headers, http_response)

except socket.gaierror as e:
Expand Down
11 changes: 9 additions & 2 deletions python/ccxt/base/exchange.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-

from __future__ import print_function

# -----------------------------------------------------------------------------

"""Base exchange class"""

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -512,13 +516,16 @@ def prepare_request_headers(self, headers=None):
headers.update({'Accept-Encoding': 'gzip, deflate'})
return headers

def print(self, *args):
print_function(*args)

def fetch(self, url, method='GET', headers=None, body=None):
"""Perform a HTTP request and return decoded JSON data"""
request_headers = self.prepare_request_headers(headers)
url = self.proxy + url

if self.verbose:
print("\nRequest:", method, url, request_headers, body)
self.print("\nRequest:", method, url, request_headers, body)
self.logger.debug("%s %s, Request: %s %s", method, url, request_headers, body)

request_body = body
Expand Down Expand Up @@ -554,7 +561,7 @@ def fetch(self, url, method='GET', headers=None, body=None):
if self.enableLastResponseHeaders:
self.last_response_headers = headers
if self.verbose:
print("\nResponse:", method, url, http_status_code, headers, http_response)
self.print("\nResponse:", method, url, http_status_code, headers, http_response)
self.logger.debug("%s %s, Response: %s %s %s", method, url, http_status_code, headers, http_response)
response.raise_for_status()

Expand Down

0 comments on commit 437abd5

Please sign in to comment.