mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-08 20:46:47 +08:00
BUG: worked around CCXT issue with fetch_tickers, see: https://github.com/ccxt/ccxt/issues/870
This commit is contained in:
@@ -701,18 +701,19 @@ class CCXT(Exchange):
|
||||
"""
|
||||
tickers = dict()
|
||||
try:
|
||||
symbols = [self.get_symbol(asset) for asset in assets]
|
||||
ccxt_tickers = self.api.fetch_tickers(symbols)
|
||||
|
||||
for asset in assets:
|
||||
symbol = self.get_symbol(asset)
|
||||
if symbol not in ccxt_tickers:
|
||||
# TODO: use fetch_tickers() for efficiency
|
||||
# I tried using fetch_tickers() but noticed some
|
||||
# inconsistencies, see issue:
|
||||
# https://github.com/ccxt/ccxt/issues/870
|
||||
ticker = self.api.fetch_ticker(symbol=symbol)
|
||||
if not ticker:
|
||||
log.warn('ticker not found for {} {}'.format(
|
||||
self.name, symbol
|
||||
))
|
||||
continue
|
||||
|
||||
ticker = ccxt_tickers[symbol]
|
||||
ticker['last_traded'] = from_ms_timestamp(ticker['timestamp'])
|
||||
|
||||
if 'last_price' not in ticker:
|
||||
|
||||
@@ -236,10 +236,10 @@ class Exchange:
|
||||
|
||||
elif data_frequency is not None:
|
||||
applies = (
|
||||
(
|
||||
data_frequency == 'minute' and a.end_minute is not None)
|
||||
or (
|
||||
data_frequency == 'daily' and a.end_daily is not None)
|
||||
(
|
||||
data_frequency == 'minute' and a.end_minute is not None)
|
||||
or (
|
||||
data_frequency == 'daily' and a.end_daily is not None)
|
||||
)
|
||||
|
||||
else:
|
||||
@@ -281,6 +281,16 @@ class Exchange:
|
||||
self._symbol_maps[index] = symbol_map
|
||||
return symbol_map
|
||||
|
||||
@abstractmethod
|
||||
def init(self):
|
||||
"""
|
||||
Load the asset list from the network.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def load_assets(self, is_local=False):
|
||||
"""
|
||||
|
||||
@@ -678,7 +678,7 @@ def get_catalyst_symbol(market_or_symbol):
|
||||
)
|
||||
|
||||
|
||||
def save_asset_data(folder, df):
|
||||
def save_asset_data(folder, df, decimals=8):
|
||||
symbols = df.index.get_level_values('symbol')
|
||||
for symbol in symbols:
|
||||
symbol_df = df.loc[(symbols == symbol)] # Type: pd.DataFrame
|
||||
@@ -691,4 +691,8 @@ def save_asset_data(folder, df):
|
||||
print_headers = True
|
||||
|
||||
with open(filename, 'a') as f:
|
||||
symbol_df.to_csv(f, header=print_headers)
|
||||
symbol_df.to_csv(
|
||||
path_or_buf=f,
|
||||
header=print_headers,
|
||||
float_format='%.{}f'.format(decimals),
|
||||
)
|
||||
|
||||
@@ -12,15 +12,15 @@ log = Logger('test_ccxt')
|
||||
class TestCCXT(BaseExchangeTestCase):
|
||||
@classmethod
|
||||
def setup(self):
|
||||
exchange_name = 'gdax'
|
||||
exchange_name = 'binance'
|
||||
auth = get_exchange_auth(exchange_name)
|
||||
self.exchange = CCXT(
|
||||
exchange_name=exchange_name,
|
||||
key=auth['key'],
|
||||
secret=auth['secret'],
|
||||
base_currency='eth',
|
||||
portfolio=None
|
||||
)
|
||||
self.exchange.init()
|
||||
|
||||
def test_order(self):
|
||||
log.info('creating order')
|
||||
@@ -68,9 +68,10 @@ class TestCCXT(BaseExchangeTestCase):
|
||||
|
||||
def test_tickers(self):
|
||||
log.info('retrieving tickers')
|
||||
tickers = self.exchange.tickers([
|
||||
self.exchange.get_asset('eth_btc'),
|
||||
])
|
||||
assets = [
|
||||
self.exchange.get_asset('eng_eth'),
|
||||
]
|
||||
tickers = self.exchange.tickers(assets)
|
||||
assert len(tickers) == 1
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user