file_dump_json

This commit is contained in:
kryofly 2018-01-11 15:49:04 +01:00
parent 69f68c428e
commit feb5da0c35
4 changed files with 19 additions and 6 deletions

View File

@ -14,6 +14,11 @@ from freqtrade import __version__
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def file_dump_json(filename, data):
with open(filename, 'w') as fp:
json.dump(data, fp)
class State(enum.Enum): class State(enum.Enum):
RUNNING = 0 RUNNING = 0
STOPPED = 1 STOPPED = 1

View File

@ -8,6 +8,7 @@ from pandas import DataFrame
from freqtrade.exchange import get_ticker_history from freqtrade.exchange import get_ticker_history
from freqtrade.optimize.hyperopt_conf import hyperopt_optimize_conf from freqtrade.optimize.hyperopt_conf import hyperopt_optimize_conf
from freqtrade.analyze import populate_indicators, parse_ticker_dataframe from freqtrade.analyze import populate_indicators, parse_ticker_dataframe
from freqtrade import misc
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -127,7 +128,6 @@ def download_backtesting_testdata(datadir: str, pair: str, interval: int = 5) ->
logger.debug("New End: {}".format(data[-1:][0]['T'])) logger.debug("New End: {}".format(data[-1:][0]['T']))
data = sorted(data, key=lambda data: data['T']) data = sorted(data, key=lambda data: data['T'])
with open(filename, "wt") as fp: misc.file_dump_json(filename, data)
json.dump(data, fp)
return True return True

View File

@ -5,10 +5,11 @@ import argparse
from copy import deepcopy from copy import deepcopy
import pytest import pytest
from unittest.mock import MagicMock
from jsonschema import ValidationError from jsonschema import ValidationError
from freqtrade.misc import throttle, parse_args, load_config,\ from freqtrade.misc import throttle, parse_args, load_config,\
parse_args_common parse_args_common, file_dump_json
def test_throttle(): def test_throttle():
@ -135,6 +136,14 @@ def test_parse_args_hyperopt_custom(mocker):
assert call_args.func is not None assert call_args.func is not None
def test_file_dump_json(default_conf, mocker):
file_open = mocker.patch('freqtrade.misc.open', MagicMock())
json_dump = mocker.patch('json.dump', MagicMock())
file_dump_json('somefile', [1, 2, 3])
assert file_open.call_count == 1
assert json_dump.call_count == 1
def test_load_config(default_conf, mocker): def test_load_config(default_conf, mocker):
file_mock = mocker.patch('freqtrade.misc.open', mocker.mock_open( file_mock = mocker.patch('freqtrade.misc.open', mocker.mock_open(
read_data=json.dumps(default_conf) read_data=json.dumps(default_conf)

View File

@ -1,11 +1,11 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""This script generate json data from bittrex""" """This script generate json data from bittrex"""
import json
from os import path from os import path
from freqtrade import exchange from freqtrade import exchange
from freqtrade.exchange import Bittrex from freqtrade.exchange import Bittrex
from freqtrade import misc
PAIRS = [ PAIRS = [
'BTC_BCC', 'BTC_ETH', 'BTC_MER', 'BTC_POWR', 'BTC_ETC', 'BTC_BCC', 'BTC_ETH', 'BTC_MER', 'BTC_POWR', 'BTC_ETC',
@ -25,5 +25,4 @@ for pair in PAIRS:
pair, pair,
TICKER_INTERVAL, TICKER_INTERVAL,
)) ))
with open(filename, 'w') as fp: misc.file_dump_json(filename, data)
json.dump(data, fp)