Skip to content

Commit

Permalink
multiple edits
Browse files Browse the repository at this point in the history
  • Loading branch information
kroitor committed Sep 24, 2017
1 parent 389424a commit fc87834
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 71 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ package-lock.json
exchanges.json
ccxt.sublime-workspace
.idea
yarn.lock
yarn.lock
keys.local.json
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ ccxt.wiki/
package-lock.json
exchanges.json
ccxt.sublime-workspace
keys.local.json
2 changes: 1 addition & 1 deletion build/ccxt.php
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,7 @@ public function __construct ($options = array ()) {
'hasFetchOHLCV' => true,
'hasFetchMyTrades' => true,
'hasFetchOrder' => true,
'hasFetchOrders' => true,
'hasFetchOrders' => false,
'hasFetchOpenOrders' => true,
'timeframes' => array (
'1m' => '1m',
Expand Down
2 changes: 1 addition & 1 deletion ccxt/async/exchanges.py

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

2 changes: 1 addition & 1 deletion ccxt/exchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ def __init__(self, config={}):
'hasFetchOHLCV': True,
'hasFetchMyTrades': True,
'hasFetchOrder': True,
'hasFetchOrders': True,
'hasFetchOrders': False,
'hasFetchOpenOrders': True,
'timeframes': {
'1m': '1m',
Expand Down
13 changes: 7 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ let proxies = [
'',
'https://cors-anywhere.herokuapp.com/',
'https://crossorigin.me/',
// 'http://cors-proxy.htmldriven.com/?url=', // we don't want this for now
]

/* ------------------------------------------------------------------------ */
Expand All @@ -44,9 +43,12 @@ const exchange = new (ccxt)[exchangeId] ({ verbose: verbose, enabledRateLimit: t

//-----------------------------------------------------------------------------

let apiKeys = JSON.parse (fs.readFileSync ('./keys.json', 'utf8'))[exchangeId]
const keysGlobal = './keys.json'
const keysLocal = './keys.local.json'
let keysFile = fs.existsSync (keysLocal) ? keysLocal : keysGlobal
let settings = JSON.parse (fs.readFileSync (keysFile, 'utf8'))[exchangeId]

Object.assign (exchange, apiKeys)
Object.assign (exchange, settings)

const verboseList = [ ];
if (verboseList.indexOf (exchange.id) >= 0) {
Expand Down Expand Up @@ -404,9 +406,8 @@ let tryAllProxies = async function (exchange, proxies) {
let currentProxy = 0
let maxRetries = proxies.length

// a special case for ccex
if (exchange.id == 'ccex')
currentProxy = 1
if (settings && ('proxy' in settings))
currentProxy = proxies.indexOf (settings.proxy)

for (let numRetries = 0; numRetries < maxRetries; numRetries++) {

Expand Down
6 changes: 5 additions & 1 deletion test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ function dump ($s) { echo implode (' ', func_get_args ()) . "\n"; }
$exchanges[$id] = new $exchange (array ('verbose' => false));
}

$config = json_decode (file_get_contents ('./keys.json'), true);
$keys_global = './keys.json';
$keys_local = './keys.local.json';
$keys_file = file_exists ($keys_local) ? $keys_local : $keys_global;

$config = json_decode (file_get_contents ($keys_file), true);

foreach ($config as $id => $params)
foreach ($params as $key => $value)
Expand Down
128 changes: 68 additions & 60 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,91 +55,94 @@ def dump_error(*args):

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

def test_exchange_symbol_orderbook(exchange, symbol):
delay = int(exchange.rateLimit / 1000)
time.sleep(delay)
dump(green(exchange.id), green(symbol), 'fetching order book...')
orderbook = exchange.fetch_order_book(symbol)
dump(
green(exchange.id),
green(symbol),
'order book',
orderbook['datetime'],
'bid: ' + str(orderbook['bids'][0][0] if len(orderbook['bids']) else 'N/A'),
'bidVolume: ' + str(orderbook['bids'][0][1] if len(orderbook['bids']) else 'N/A'),
'ask: ' + str(orderbook['asks'][0][0] if len(orderbook['asks']) else 'N/A'),
'askVolume: ' + str(orderbook['asks'][0][1] if len(orderbook['asks']) else 'N/A'))
def test_order_book(exchange, symbol):
if exchange.hasFetchOrderBook:
delay = int(exchange.rateLimit / 1000)
time.sleep(delay)
dump(green(exchange.id), green(symbol), 'fetching order book...')
orderbook = exchange.fetch_order_book(symbol)
dump(
green(exchange.id),
green(symbol),
'order book',
orderbook['datetime'],
'bid: ' + str(orderbook['bids'][0][0] if len(orderbook['bids']) else 'N/A'),
'bidVolume: ' + str(orderbook['bids'][0][1] if len(orderbook['bids']) else 'N/A'),
'ask: ' + str(orderbook['asks'][0][0] if len(orderbook['asks']) else 'N/A'),
'askVolume: ' + str(orderbook['asks'][0][1] if len(orderbook['asks']) else 'N/A'))
else:
dump(yellow(exchange.id), 'fetch_order_book() supported')

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

def test_exchange_symbol_ohlcv(exchange, symbol):
delay = int(exchange.rateLimit / 1000)
time.sleep(delay)
def test_ohlcv(exchange, symbol):
if exchange.hasFetchOHLCV:
delay = int(exchange.rateLimit / 1000)
time.sleep(delay)
ohlcvs = exchange.fetch_ohlcv(symbol)
dump(green(exchange.id), 'fetched', green(len(ohlcvs)), 'OHLCVs')
else:
dump(yellow(exchange.id), 'fetching OHLCV not supported')
dump(yellow(exchange.id), 'fetch_ohlcv() not supported')

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

def test_exchange_all_tickers(exchange):
delay = int(exchange.rateLimit / 1000)
time.sleep(delay)
dump(green(exchange.id), 'fetching all tickers at once...')
def test_tickers(exchange):
if exchange.hasFetchTickers:
delay = int(exchange.rateLimit / 1000)
time.sleep(delay)
dump(green(exchange.id), 'fetching all tickers at once...')
tickers = exchange.fetch_tickers()
dump(green(exchange.id), 'fetched', green(len(list(tickers.keys()))), 'tickers')
else:
dump(yellow(exchange.id), 'fetching all tickers at once not supported')
dump(yellow(exchange.id), 'fetch_tickers() not supported')

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

def test_exchange_symbol_ticker(exchange, symbol):
delay = int(exchange.rateLimit / 1000)
time.sleep(delay)
dump(green(exchange.id), green(symbol), 'fetching ticker...')
ticker = exchange.fetch_ticker(symbol)
dump(
green(exchange.id),
green(symbol),
'ticker',
ticker['datetime'],
'high: ' + str(ticker['high']),
'low: ' + str(ticker['low']),
'bid: ' + str(ticker['bid']),
'ask: ' + str(ticker['ask']),
'volume: ' + str(ticker['quoteVolume']))
def test_ticker(exchange, symbol):
if exchange.hasFetchTicker:
delay = int(exchange.rateLimit / 1000)
time.sleep(delay)
dump(green(exchange.id), green(symbol), 'fetching ticker...')
ticker = exchange.fetch_ticker(symbol)
dump(
green(exchange.id),
green(symbol),
'ticker',
ticker['datetime'],
'high: ' + str(ticker['high']),
'low: ' + str(ticker['low']),
'bid: ' + str(ticker['bid']),
'ask: ' + str(ticker['ask']),
'volume: ' + str(ticker['quoteVolume']))
else:
dump(green(exchange.id), green(symbol), 'fetch_ticker() not supported')

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

def test_exchange_symbol_trades(exchange, symbol):

delay = int(exchange.rateLimit / 1000)
time.sleep(delay)
dump(green(exchange.id), green(symbol), 'fetching trades...')
try:
def test_trades(exchange, symbol):
if exchange.hasFetchTrades:
delay = int(exchange.rateLimit / 1000)
time.sleep(delay)
dump(green(exchange.id), green(symbol), 'fetching trades...')
trades = exchange.fetch_trades(symbol)
dump(green(exchange.id), green(symbol), 'fetched', green(len(list(trades))), 'trades')
except ccxt.ExchangeError as e:
dump_error(yellow('[' + type(e).__name__ + ']'), e.args)
except ccxt.NotSupported as e:
dump_error(yellow('[' + type(e).__name__ + ']'), e.args)
else:
dump(green(exchange.id), green(symbol), 'fetch_trades() not supported')

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

def test_exchange_symbol(exchange, symbol):
def test_symbol(exchange, symbol):
dump(green('SYMBOL: ' + symbol))
test_exchange_symbol_ticker(exchange, symbol)
test_ticker(exchange, symbol)

if exchange.id == 'coinmarketcap':
dump(green(exchange.fetchGlobal()))
else:
test_exchange_symbol_orderbook(exchange, symbol)
test_exchange_symbol_trades(exchange, symbol)
test_order_book(exchange, symbol)
test_trades(exchange, symbol)

test_exchange_all_tickers(exchange)
test_exchange_symbol_ohlcv(exchange, symbol)
test_tickers(exchange)
test_ohlcv(exchange, symbol)

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

Expand Down Expand Up @@ -173,7 +176,7 @@ def test_exchange(exchange):
break

if symbol.find('.d') < 0:
test_exchange_symbol(exchange, symbol)
test_symbol(exchange, symbol)

# ..........................................................................
# private API
Expand Down Expand Up @@ -221,12 +224,12 @@ def test_exchange(exchange):
def try_all_proxies(exchange, proxies):
current_proxy = 0
max_retries = len(proxies)
# a special case for ccex
if exchange.id == 'ccex':
current_proxy = 1
if exchange.proxy:
current_proxy = proxies.index(exchange.proxy)
for num_retries in range(0, max_retries):
try:
exchange.proxy = proxies[current_proxy]
dump(green(exchange.id), 'using proxy', '`' + exchange.proxy + '`')
current_proxy = (current_proxy + 1) % len(proxies)
load_exchange(exchange)
test_exchange(exchange)
Expand All @@ -253,8 +256,13 @@ def try_all_proxies(exchange, proxies):
# 'http://cors-proxy.htmldriven.com/?url=', # we don't want this for now
]

# prefer local testing keys to global keys
keys_global = './keys.json'
keys_local = './keys.local.json'
keys_file = keys_local if os.path.exists(keys_local) else keys_global

# load the api keys from config
with open('./keys.json') as file:
with open(keys_file) as file:
config = json.load(file)

# instantiate all exchanges
Expand Down Expand Up @@ -282,7 +290,7 @@ def try_all_proxies(exchange, proxies):

if symbol:
load_exchange(exchange)
test_exchange_symbol(exchange, symbol)
test_symbol(exchange, symbol)
else:
try_all_proxies(exchange, proxies)

Expand Down

0 comments on commit fc87834

Please sign in to comment.