Skip to content

Commit

Permalink
Merge pull request #7 from ccxt-dev/master
Browse files Browse the repository at this point in the history
Updating from master
  • Loading branch information
samholt authored Oct 23, 2017
2 parents 34e5789 + f532d91 commit 5ffe3da
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 41 deletions.
19 changes: 17 additions & 2 deletions build/ccxt.browser.js

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions build/ccxt.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DDoSProtection extends NetworkError {}
class RequestTimeout extends NetworkError {}
class ExchangeNotAvailable extends NetworkError {}

$version = '1.9.229';
$version = '1.9.231';

$curl_errors = array (
0 => 'CURLE_OK',
Expand Down Expand Up @@ -4089,6 +4089,9 @@ public function fetch_markets () {
if ($base == 'DSH')
$base = 'DASH';
$symbol = $base . '/' . $quote;
$precision = array (
'price' => $market['price_precision'],
);
$result[] = array (
'id' => $id,
'symbol' => $symbol,
Expand All @@ -4097,6 +4100,7 @@ public function fetch_markets () {
'baseId' => $baseId,
'quoteId' => $quoteId,
'info' => $market,
'precision' => $precision,
);
}
return $result;
Expand Down Expand Up @@ -4614,6 +4618,17 @@ public function fetch_trades ($symbol, $params = array ()) {
return $this->parse_trades ($response, $market);
}

public function parse_ohlcv ($ohlcv, $market = null, $timeframe = '1m', $since = null, $limit = null) {
return [
$ohlcv[0],
$ohlcv[1],
$ohlcv[3],
$ohlcv[4],
$ohlcv[2],
$ohlcv[5],
];
}

public function fetch_ohlcv ($symbol, $timeframe = '1m', $since = null, $limit = null, $params = array ()) {
$market = $this->market ($symbol);
$request = array (
Expand Down Expand Up @@ -7614,7 +7629,7 @@ public function __construct ($options = array ()) {
),
'markets' => array (
'BTC/EUR' => array ( 'id' => 'BTCEUR', 'symbol' => 'BTC/EUR', 'base' => 'BTC', 'quote' => 'EUR' ),
'LTC/EUR' => array ( 'id' => 'LTCEUR', 'symbol' => 'LTC/EUR', 'base' => 'LTC', 'quote' => 'EUR' ),
// 'LTC/EUR' => array ( 'id' => 'LTCEUR', 'symbol' => 'LTC/EUR', 'base' => 'LTC', 'quote' => 'EUR' ),
),
), $options));
}
Expand Down Expand Up @@ -17092,8 +17107,9 @@ public function fetch_tickers ($symbols = null, $params = array ()) {
for ($s = 0; $s < count ($this->symbols); $s++) {
$symbol = $this->symbols[$s];
$market = $this->markets[$symbol];
if (!$market['darkpool'])
$pairs[] = $market['id'];
if ($market['active'])
if (!$market['darkpool'])
$pairs[] = $market['id'];
}
$filter = implode (',', $pairs);
$response = $this->publicGetTicker (array_merge (array (
Expand Down
26 changes: 21 additions & 5 deletions ccxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const CryptoJS = require ('crypto-js')
//-----------------------------------------------------------------------------
// this is updated by vss.js when building

const version = '1.9.229'
const version = '1.9.231'

//-----------------------------------------------------------------------------
// platform detection
Expand Down Expand Up @@ -3900,6 +3900,9 @@ var bitfinex = {
if (base == 'DSH')
base = 'DASH';
let symbol = base + '/' + quote;
let precision = {
'price': market['price_precision'],
};
result.push ({
'id': id,
'symbol': symbol,
Expand All @@ -3908,6 +3911,7 @@ var bitfinex = {
'baseId': baseId,
'quoteId': quoteId,
'info': market,
'precision': precision,
});
}
return result;
Expand Down Expand Up @@ -4421,6 +4425,17 @@ var bitfinex2 = extend (bitfinex, {
return this.parseTrades (response, market);
},

parseOHLCV (ohlcv, market = undefined, timeframe = '1m', since = undefined, limit = undefined) {
return [
ohlcv[0],
ohlcv[1],
ohlcv[3],
ohlcv[4],
ohlcv[2],
ohlcv[5],
];
},

async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
let market = this.market (symbol);
let request = {
Expand Down Expand Up @@ -7379,7 +7394,7 @@ var bl3p = {
},
'markets': {
'BTC/EUR': { 'id': 'BTCEUR', 'symbol': 'BTC/EUR', 'base': 'BTC', 'quote': 'EUR' },
'LTC/EUR': { 'id': 'LTCEUR', 'symbol': 'LTC/EUR', 'base': 'LTC', 'quote': 'EUR' },
// 'LTC/EUR': { 'id': 'LTCEUR', 'symbol': 'LTC/EUR', 'base': 'LTC', 'quote': 'EUR' },
},

async fetchBalance (params = {}) {
Expand Down Expand Up @@ -16594,7 +16609,7 @@ var kraken = {
return result;
},

async appendInactiveMarkets (result = []) {
appendInactiveMarkets (result = []) {
let precision = { 'amount': 8, 'price': 8 };
let costLimits = { 'min': 0, 'max': undefined };
let priceLimits = { 'min': Math.pow (10, -precision['price']), 'max': undefined };
Expand Down Expand Up @@ -16665,8 +16680,9 @@ var kraken = {
for (let s = 0; s < this.symbols.length; s++) {
let symbol = this.symbols[s];
let market = this.markets[symbol];
if (!market['darkpool'])
pairs.push (market['id']);
if (market['active'])
if (!market['darkpool'])
pairs.push (market['id']);
}
let filter = pairs.join (',');
let response = await this.publicGetTicker (this.extend ({
Expand Down
2 changes: 1 addition & 1 deletion ccxt.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DDoSProtection extends NetworkError {}
class RequestTimeout extends NetworkError {}
class ExchangeNotAvailable extends NetworkError {}

$version = '1.9.229';
$version = '1.9.231';

$curl_errors = array (
0 => 'CURLE_OK',
Expand Down
12 changes: 7 additions & 5 deletions ccxt/async/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@

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

import aiohttp
import asyncio
import concurrent
import socket
import time
import math
import random

import aiohttp

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

from ccxt.errors import ExchangeError
Expand All @@ -53,7 +54,7 @@
# -----------------------------------------------------------------------------


class Exchange (BaseExchange):
class Exchange(BaseExchange):

def __init__(self, config={}):
super(Exchange, self).__init__(config)
Expand Down Expand Up @@ -90,7 +91,7 @@ def add_new_tokens(self):
# print('Adding new tokens: Exchange: {0}'.format(self.id))
now = time.monotonic()
time_since_update = now - self.rateLimitUpdateTime
new_tokens = math.floor( ( 0.8 * 1000.0 * time_since_update ) / self.rateLimit )
new_tokens = math.floor((0.8 * 1000.0 * time_since_update) / self.rateLimit)
if new_tokens > 1:
self.rateLimitTokens = min(self.rateLimitTokens + new_tokens, self.rateLimitMaxTokens)
self.rateLimitUpdateTime = now
Expand All @@ -103,15 +104,16 @@ async def fetch(self, url, method='GET', headers=None, body=None):
headers.update({'User-Agent': self.userAgent})
elif (type(self.userAgent) is dict) and ('User-Agent' in self.userAgent):
headers.update(self.userAgent)
if len(self.proxy):
if self.proxy:
headers.update({'Origin': '*'})
headers.update({'Accept-Encoding': 'gzip, deflate'})
url = self.proxy + url
if self.verbose:
print(url, method, url, "\nRequest:", headers, body)
encoded_body = body.encode() if body else None
session_method = getattr(self.aiohttp_session, method.lower())
await self.wait_for_token()
if self.enableRateLimit:
await self.wait_for_token()
try:
async with session_method(url, data=encoded_body, headers=headers, timeout=(self.timeout / 1000), proxy=self.aiohttp_proxy) as response:
text = await response.text()
Expand Down
23 changes: 19 additions & 4 deletions ccxt/async/exchanges.py

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

21 changes: 18 additions & 3 deletions ccxt/exchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,9 @@ def fetch_markets(self):
if base == 'DSH':
base = 'DASH'
symbol = base + '/' + quote
precision = {
'price': market['price_precision'],
}
result.append({
'id': id,
'symbol': symbol,
Expand All @@ -2775,6 +2778,7 @@ def fetch_markets(self):
'baseId': baseId,
'quoteId': quoteId,
'info': market,
'precision': precision,
})
return result

Expand Down Expand Up @@ -3257,6 +3261,16 @@ def fetch_trades(self, symbol, params={}):
}, params))
return self.parse_trades(response, market)

def parse_ohlcv(self, ohlcv, market=None, timeframe='1m', since=None, limit=None):
return [
ohlcv[0],
ohlcv[1],
ohlcv[3],
ohlcv[4],
ohlcv[2],
ohlcv[5],
]

def fetch_ohlcv(self, symbol, timeframe='1m', since=None, limit=None, params={}):
market = self.market(symbol)
request = {
Expand Down Expand Up @@ -6063,7 +6077,7 @@ def __init__(self, config={}):
},
'markets': {
'BTC/EUR': {'id': 'BTCEUR', 'symbol': 'BTC/EUR', 'base': 'BTC', 'quote': 'EUR'},
'LTC/EUR': {'id': 'LTCEUR', 'symbol': 'LTC/EUR', 'base': 'LTC', 'quote': 'EUR'},
# 'LTC/EUR': {'id': 'LTCEUR', 'symbol': 'LTC/EUR', 'base': 'LTC', 'quote': 'EUR'},
},
}
params.update(config)
Expand Down Expand Up @@ -14953,8 +14967,9 @@ def fetch_tickers(self, symbols=None, params={}):
for s in range(0, len(self.symbols)):
symbol = self.symbols[s]
market = self.markets[symbol]
if not market['darkpool']:
pairs.append(market['id'])
if market['active']:
if not market['darkpool']:
pairs.append(market['id'])
filter = ','.join(pairs)
response = self.publicGetTicker(self.extend({
'pair': filter,
Expand Down
2 changes: 1 addition & 1 deletion ccxt/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
SOFTWARE.
"""

__version__ = '1.9.229'
__version__ = '1.9.231'
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.9.229",
"version": "1.9.231",
"description": "A JavaScript / Python / PHP cryptocurrency trading library with support for 85+ exchanges",
"main": "./ccxt.js",
"unpkg": "build/ccxt.browser.js",
Expand Down
21 changes: 19 additions & 2 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class Argv(object):
argv = Argv()

parser = argparse.ArgumentParser()

parser.add_argument('--verbose', action='store_true', help='enable verbose output')
parser.add_argument('--nonce', type=int, help='integer')
parser.add_argument('exchange', type=str, help='exchange id in lowercase', nargs='?')
parser.add_argument('symbol', type=str, help='symbol in uppercase', nargs='?')

parser.parse_args(namespace=argv)

exchanges = {}
Expand Down Expand Up @@ -142,8 +144,23 @@ def test_tickers(exchange, symbol):
dump(green(exchange.id), 'failed to fetch all tickers, fetching multiple tickers at once...')
tickers = exchange.fetch_tickers([symbol])
dump(green(exchange.id), 'fetched', green(len(list(tickers.keys()))), 'tickers')
else:
dump(yellow(exchange.id), 'fetching all tickers at once not supported')

test_tickers_async(exchange)

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

def get_active_symbols(exchange):
return [symbol for symbol in exchange.symbols if is_active_symbol (exchange, symbol)]

def is_active_symbol(exchange, symbol):
return ('.' not in symbol) and (('active' not in exchange.markets[symbol]) or (exchange.markets[symbol]['active']))

def test_tickers_async(exchange):
dump(green(exchange.id), 'fetching all tickers by simultaneous multiple concurrent requests')
symbols_to_load = get_active_symbols(exchange)
input_coroutines = [exchange.fetchTicker(symbol) for symbol in symbols_to_load]
tickers = asyncio.gather(*input_coroutines)
dump(green(exchange.id), 'fetched', green(len(list(tickers))), 'tickers')

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

Expand Down
Loading

0 comments on commit 5ffe3da

Please sign in to comment.