exchange: extract ccxt init to its own function (so that we can init ccxt from the scripts)
This commit is contained in:
parent
fded8e5117
commit
de8db9293c
@ -240,7 +240,7 @@ class Arguments(object):
|
|||||||
|
|
||||||
def scripts_options(self) -> None:
|
def scripts_options(self) -> None:
|
||||||
"""
|
"""
|
||||||
Parses given arguments for plot scripts.
|
Parses given arguments for scripts.
|
||||||
"""
|
"""
|
||||||
self.parser.add_argument(
|
self.parser.add_argument(
|
||||||
'-p', '--pair',
|
'-p', '--pair',
|
||||||
@ -248,3 +248,20 @@ class Arguments(object):
|
|||||||
dest='pair',
|
dest='pair',
|
||||||
default=None
|
default=None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def testdata_dl_options(self) -> None:
|
||||||
|
"""
|
||||||
|
Parses given arguments for testdata download
|
||||||
|
"""
|
||||||
|
self.parser.add_argument(
|
||||||
|
'--pairs-file',
|
||||||
|
help='File containing a list of pairs to download',
|
||||||
|
dest='pairs_file',
|
||||||
|
default=None
|
||||||
|
)
|
||||||
|
|
||||||
|
self.parser.add_argument(
|
||||||
|
'--export',
|
||||||
|
help='Export files to given dir',
|
||||||
|
dest='export',
|
||||||
|
default=None)
|
||||||
|
@ -45,6 +45,32 @@ def retrier(f):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def init_ccxt(exchange_config: dict) -> ccxt:
|
||||||
|
"""
|
||||||
|
Initialize ccxt with given config and return valid
|
||||||
|
ccxt instance.
|
||||||
|
:param config: config to use
|
||||||
|
:return: ccxt
|
||||||
|
"""
|
||||||
|
# Find matching class for the given exchange name
|
||||||
|
name = exchange_config['name']
|
||||||
|
|
||||||
|
if name not in ccxt.exchanges:
|
||||||
|
raise OperationalException('Exchange {} is not supported'.format(name))
|
||||||
|
try:
|
||||||
|
api = getattr(ccxt, name.lower())({
|
||||||
|
'apiKey': exchange_config.get('key'),
|
||||||
|
'secret': exchange_config.get('secret'),
|
||||||
|
'password': exchange_config.get('password'),
|
||||||
|
'uid': exchange_config.get('uid' ''),
|
||||||
|
'enableRateLimit': True,
|
||||||
|
})
|
||||||
|
except (KeyError, AttributeError):
|
||||||
|
raise OperationalException('Exchange {} is not supported'.format(name))
|
||||||
|
|
||||||
|
return api
|
||||||
|
|
||||||
|
|
||||||
def init(config: dict) -> None:
|
def init(config: dict) -> None:
|
||||||
"""
|
"""
|
||||||
Initializes this module with the given config,
|
Initializes this module with the given config,
|
||||||
@ -61,22 +87,7 @@ def init(config: dict) -> None:
|
|||||||
logger.info('Instance is running with dry_run enabled')
|
logger.info('Instance is running with dry_run enabled')
|
||||||
|
|
||||||
exchange_config = config['exchange']
|
exchange_config = config['exchange']
|
||||||
|
_API = init_ccxt(exchange_config)
|
||||||
# Find matching class for the given exchange name
|
|
||||||
name = exchange_config['name']
|
|
||||||
|
|
||||||
if name not in ccxt.exchanges:
|
|
||||||
raise OperationalException('Exchange {} is not supported'.format(name))
|
|
||||||
try:
|
|
||||||
_API = getattr(ccxt, name.lower())({
|
|
||||||
'apiKey': exchange_config.get('key'),
|
|
||||||
'secret': exchange_config.get('secret'),
|
|
||||||
'password': exchange_config.get('password'),
|
|
||||||
'uid': exchange_config.get('uid'),
|
|
||||||
'enableRateLimit': True,
|
|
||||||
})
|
|
||||||
except (KeyError, AttributeError):
|
|
||||||
raise OperationalException('Exchange {} is not supported'.format(name))
|
|
||||||
|
|
||||||
logger.info('Using Exchange "%s"', get_name())
|
logger.info('Using Exchange "%s"', get_name())
|
||||||
|
|
||||||
|
@ -71,6 +71,8 @@ def file_dump_json(filename, data, is_zip=False) -> None:
|
|||||||
:param data: JSON Data to save
|
:param data: JSON Data to save
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
print(f'dumping json to "{filename}"')
|
||||||
|
|
||||||
if is_zip:
|
if is_zip:
|
||||||
if not filename.endswith('.gz'):
|
if not filename.endswith('.gz'):
|
||||||
filename = filename + '.gz'
|
filename = filename + '.gz'
|
||||||
|
Loading…
Reference in New Issue
Block a user