Merge pull request #622 from gcarq/fix/dl-testdata
fix download testdata
This commit is contained in:
@@ -240,7 +240,7 @@ class Arguments(object):
|
||||
|
||||
def scripts_options(self) -> None:
|
||||
"""
|
||||
Parses given arguments for plot scripts.
|
||||
Parses given arguments for scripts.
|
||||
"""
|
||||
self.parser.add_argument(
|
||||
'-p', '--pair',
|
||||
@@ -248,3 +248,20 @@ class Arguments(object):
|
||||
dest='pair',
|
||||
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)
|
||||
|
@@ -47,6 +47,32 @@ def retrier(f):
|
||||
return wrapper
|
||||
|
||||
|
||||
def init_ccxt(exchange_config: dict) -> ccxt.Exchange:
|
||||
"""
|
||||
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:
|
||||
"""
|
||||
Initializes this module with the given config,
|
||||
@@ -63,22 +89,7 @@ def init(config: dict) -> None:
|
||||
logger.info('Instance is running with dry_run enabled')
|
||||
|
||||
exchange_config = config['exchange']
|
||||
|
||||
# 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))
|
||||
_API = init_ccxt(exchange_config)
|
||||
|
||||
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
|
||||
:return:
|
||||
"""
|
||||
print(f'dumping json to "{filename}"')
|
||||
|
||||
if is_zip:
|
||||
if not filename.endswith('.gz'):
|
||||
filename = filename + '.gz'
|
||||
|
@@ -74,10 +74,9 @@ def default_conf():
|
||||
"secret": "secret",
|
||||
"pair_whitelist": [
|
||||
"ETH/BTC",
|
||||
"TKN/BTC",
|
||||
"TRST/BTC",
|
||||
"SWT/BTC",
|
||||
"BCC/BTC"
|
||||
"LTC/BTC",
|
||||
"XRP/BTC",
|
||||
"NEO/BTC"
|
||||
]
|
||||
},
|
||||
"telegram": {
|
||||
|
@@ -45,7 +45,7 @@ def test_init_exception(default_conf):
|
||||
def test_validate_pairs(default_conf, mocker):
|
||||
api_mock = MagicMock()
|
||||
api_mock.load_markets = MagicMock(return_value={
|
||||
'ETH/BTC': '', 'TKN/BTC': '', 'TRST/BTC': '', 'SWT/BTC': '', 'BCC/BTC': ''
|
||||
'ETH/BTC': '', 'LTC/BTC': '', 'XRP/BTC': '', 'NEO/BTC': ''
|
||||
})
|
||||
id_mock = PropertyMock(return_value='test_exchange')
|
||||
type(api_mock).id = id_mock
|
||||
|
@@ -1,35 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""This script generate json data from bittrex"""
|
||||
import json
|
||||
import sys
|
||||
|
||||
from freqtrade import (exchange, arguments, misc)
|
||||
from freqtrade.exchange import ccxt
|
||||
|
||||
BASE_PATH = 'freqtrade/tests/testdata'
|
||||
|
||||
arguments = arguments.Arguments(sys.argv[1:], 'download utility')
|
||||
arguments.scripts_options()
|
||||
args = arguments.parse_args()
|
||||
|
||||
TICKER_INTERVALS = ['1m', '5m']
|
||||
PAIRS = []
|
||||
|
||||
if args.pair:
|
||||
with open(args.pair) as file:
|
||||
PAIRS = json.load(file)
|
||||
PAIRS = list(set(PAIRS))
|
||||
|
||||
print('About to download pairs:', PAIRS)
|
||||
|
||||
# Init Bittrex exchange
|
||||
exchange._API = ccxt.bittrex({'key': '', 'secret': ''})
|
||||
|
||||
for pair in PAIRS:
|
||||
for tick_interval in TICKER_INTERVALS:
|
||||
print('downloading pair %s, interval %s' % (pair, tick_interval))
|
||||
data = exchange.get_ticker_history(pair, tick_interval)
|
||||
pair_print = pair.replace('/', '_')
|
||||
filename = '{}-{}.json'.format(pair_print, tick_interval)
|
||||
misc.file_dump_json(filename, data)
|
Reference in New Issue
Block a user