Skip to content

Commit

Permalink
Merge branch 'master' into aofex
Browse files Browse the repository at this point in the history
  • Loading branch information
kroitor committed Mar 27, 2020
2 parents 9e479b4 + 93a9269 commit 7937c2b
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 66 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ console.log (ccxt.exchanges) // print all available exchanges

All-in-one browser bundle (dependencies included), served from a CDN of your choice:

* jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.25.27/dist/ccxt.browser.js
* unpkg: https://unpkg.com/ccxt@1.25.27/dist/ccxt.browser.js
* jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.25.30/dist/ccxt.browser.js
* unpkg: https://unpkg.com/ccxt@1.25.30/dist/ccxt.browser.js

CDNs are not updated in real-time and may have delays. Defaulting to the most recent version without specifying the version number is not recommended. Please, keep in mind that we are not responsible for the correct operation of those CDN servers.

```HTML
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@1.25.27/dist/ccxt.browser.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@1.25.30/dist/ccxt.browser.js"></script>
```

Creates a global `ccxt` object:
Expand Down
2 changes: 1 addition & 1 deletion ccxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Exchange = require ('./js/base/Exchange')
//-----------------------------------------------------------------------------
// this is updated by vss.js when building

const version = '1.25.27'
const version = '1.25.30'

Exchange.ccxtVersion = version

Expand Down
34 changes: 21 additions & 13 deletions dist/ccxt.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Exchange = require ('./js/base/Exchange')
//-----------------------------------------------------------------------------
// this is updated by vss.js when building

const version = '1.25.27'
const version = '1.25.30'

Exchange.ccxtVersion = version

Expand Down Expand Up @@ -3902,42 +3902,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 @@ -4052,8 +4060,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 Expand Up @@ -76854,7 +76863,6 @@ module.exports = class okex extends Exchange {
marketType = 'swap';
spot = false;
swap = true;
baseId = this.safeString (market, 'coin');
const futuresAlias = this.safeString (market, 'alias');
if (futuresAlias !== undefined) {
swap = false;
Expand Down
6 changes: 3 additions & 3 deletions doc/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,14 @@ JavaScript (for use with the ``<script>`` tag):

All-in-one browser bundle (dependencies included), served from a CDN of your choice:

- jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.25.27/dist/ccxt.browser.js
- unpkg: https://unpkg.com/ccxt@1.25.27/dist/ccxt.browser.js
- jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.25.30/dist/ccxt.browser.js
- unpkg: https://unpkg.com/ccxt@1.25.30/dist/ccxt.browser.js

CDNs are not updated in real-time and may have delays. Defaulting to the most recent version without specifying the version number is not recommended. Please, keep in mind that we are not responsible for the correct operation of those CDN servers.

.. code:: html

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@1.25.27/dist/ccxt.browser.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@1.25.30/dist/ccxt.browser.js"></script>

Creates a global ``ccxt`` object:

Expand Down
6 changes: 3 additions & 3 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ JavaScript (for use with the ``<script>`` tag):

All-in-one browser bundle (dependencies included), served from a CDN of your choice:

- jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.25.27/dist/ccxt.browser.js
- unpkg: https://unpkg.com/ccxt@1.25.27/dist/ccxt.browser.js
- jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.25.30/dist/ccxt.browser.js
- unpkg: https://unpkg.com/ccxt@1.25.30/dist/ccxt.browser.js

You can obtain a live-updated version of the bundle by removing the version number from the URL (the ``@a.b.c`` thing) — however, we do not recommend to do that, as it may break your app eventually. Also, please keep in mind that we are not responsible for the correct operation of those CDN servers.

.. code:: html

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@1.25.27/dist/ccxt.browser.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@1.25.30/dist/ccxt.browser.js"></script>

Creates a global ``ccxt`` object:

Expand Down
23 changes: 19 additions & 4 deletions examples/py/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

class Argv(object):

table = False
verbose = False
nonce = None
exchange_id = None
Expand All @@ -32,6 +33,7 @@ class Argv(object):

parser = argparse.ArgumentParser()

parser.add_argument('--table', action='store_true', help='output as table')
parser.add_argument('--verbose', action='store_true', help='enable verbose output')
parser.add_argument('exchange_id', type=str, help='exchange id in lowercase', nargs='?')
parser.add_argument('method', type=str, help='method or property', nargs='?')
Expand All @@ -42,6 +44,17 @@ class Argv(object):
# ------------------------------------------------------------------------------


def table(values):
first = values[0]
keys = list(first.keys()) if isinstance(first, dict) else range(0, len(first))
widths = [max([len(str(v[k])) for v in values]) for k in keys]
string = ' | '.join(['{:<' + str(w) + '}' for w in widths])
return "\n".join([string.format(*[str(v[k]) for k in keys]) for v in values])


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


def print_supported_exchanges():
print('Supported exchanges: ' + ', '.join(ccxt.exchanges) + '\n')

Expand Down Expand Up @@ -121,10 +134,12 @@ def print_usage():

# if it is a method, call it
if callable(method):

result = method(*args)
pprint(result)

else: # otherwise it's a property, print it
result = method

pprint(method)
if argv.table:
result = list(result.values()) if isinstance(result, dict) else result
print(table([exchange.omit(v, 'info') for v in result]))
else:
pprint(result)
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
1 change: 0 additions & 1 deletion js/okex.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,6 @@ module.exports = class okex extends Exchange {
marketType = 'swap';
spot = false;
swap = true;
baseId = this.safeString (market, 'coin');
const futuresAlias = this.safeString (market, 'alias');
if (futuresAlias !== undefined) {
swap = false;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ccxt",
"version": "1.25.27",
"version": "1.25.30",
"description": "A JavaScript / Python / PHP cryptocurrency trading library with support for 130+ exchanges",
"main": "./ccxt.js",
"unpkg": "dist/ccxt.browser.js",
Expand Down
21 changes: 14 additions & 7 deletions php/base/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
use Elliptic\EC;
use BN\BN;

$version = '1.25.27';
$version = '1.25.30';

// rounding mode
const TRUNCATE = 0;
Expand All @@ -54,7 +54,7 @@

class Exchange {

const VERSION = '1.25.27';
const VERSION = '1.25.30';

public static $exchanges = array(
'_1btcxe',
Expand Down 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 Expand Up @@ -1839,7 +1846,7 @@ public function filter_by_value_since_limit($array, $field, $value = null, $sinc
$array = array_values($array);
$valueIsSet = isset($value);
$sinceIsSet = isset($since);
$array = array_filter($array, function ($element) use ($valueIsSet, $value, $sinceIsSet, $since, $field) {
$array = array_filter($array, function ($element) use ($valueIsSet, $value, $sinceIsSet, $since, $field, $key) {
return ($valueIsSet ? ($element[$field] === $value) : true) &&
($sinceIsSet ? ($element[$key] >= $since) : true);
});
Expand Down
1 change: 0 additions & 1 deletion php/okex.php
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,6 @@ public function parse_market($market) {
$marketType = 'swap';
$spot = false;
$swap = true;
$baseId = $this->safe_string($market, 'coin');
$futuresAlias = $this->safe_string($market, 'alias');
if ($futuresAlias !== null) {
$swap = false;
Expand Down
6 changes: 3 additions & 3 deletions python/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,14 @@ JavaScript (for use with the ``<script>`` tag):

All-in-one browser bundle (dependencies included), served from a CDN of your choice:

- jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.25.27/dist/ccxt.browser.js
- unpkg: https://unpkg.com/ccxt@1.25.27/dist/ccxt.browser.js
- jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.25.30/dist/ccxt.browser.js
- unpkg: https://unpkg.com/ccxt@1.25.30/dist/ccxt.browser.js

CDNs are not updated in real-time and may have delays. Defaulting to the most recent version without specifying the version number is not recommended. Please, keep in mind that we are not responsible for the correct operation of those CDN servers.

.. code:: html

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@1.25.27/dist/ccxt.browser.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@1.25.30/dist/ccxt.browser.js"></script>

Creates a global ``ccxt`` object:

Expand Down
2 changes: 1 addition & 1 deletion python/ccxt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

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

__version__ = '1.25.27'
__version__ = '1.25.30'

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

Expand Down
Loading

0 comments on commit 7937c2b

Please sign in to comment.