diff --git a/user_data/strategies/Strategy002.py b/user_data/strategies/Strategy002.py index 15472916f..e0fa6e034 100644 --- a/user_data/strategies/Strategy002.py +++ b/user_data/strategies/Strategy002.py @@ -15,7 +15,7 @@ from datetime import datetime import subprocess import threading -from user_data.strategies.util import IS_BACKTEST, launcher, back_tester, CURRENT_YEAR, CURRENT_MONTH +from user_data.strategies.util import IS_BACKTEST, launcher, back_tester @@ -168,11 +168,7 @@ class Strategy002(IStrategy): coin = pair.split("/")[0] brain = "Freq_" + self.__class__.__name__ if IS_BACKTEST: - print("Strategy002:current_time = "+str(current_time)) - if current_time.year != CURRENT_YEAR or current_time.month != CURRENT_MONTH: - pass - else: - threading.Thread(target=back_tester, args=(current_time, coin, brain)).start() + threading.Thread(target=back_tester, args=(current_time, coin, brain)).start() else: threading.Thread(target=launcher, args=(mode, coin, brain)).start() return True diff --git a/user_data/strategies/freq_data_cleaner.py b/user_data/strategies/freq_data_cleaner.py new file mode 100644 index 000000000..f10605642 --- /dev/null +++ b/user_data/strategies/freq_data_cleaner.py @@ -0,0 +1,40 @@ +import json +import datetime +import time +import os +import sys +from util import BACKTEST_JSON_PATH, BACKTEST_YEAR, BACKTEST_MONTH + +def clean_json(): + print("clean_json: json_path = " + BACKTEST_JSON_PATH) + file = open(BACKTEST_JSON_PATH) + list = [] + data = json.load(file) + for datas in data: + datas[0] = datas[0]/1000 + datas[0] = int(datas[0]) + date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(datas[0]))) + date = datetime.datetime.strptime(str(date), "%Y-%m-%d %H:%M:%S") + year = date.year + month = date.month + if year == int(BACKTEST_YEAR) and month == int(BACKTEST_MONTH): + list.append(datas) + json_object = json.dumps(list) + file.close() + write_to_json(json_object) + +def write_to_json(json_object): + print("write_to_json: json_path = " + BACKTEST_JSON_PATH) + with open("temp.json", "w") as outfile: + outfile.write(json_object) + os.rename("temp.json", BACKTEST_JSON_PATH) + +if len(sys.argv) < 4: + exit("""Incorrect number of arguments. + python3 freq_data_cleaner.py [json_file] [month] [year] + """) +else: + BACKTEST_JSON_PATH = sys.argv[1] + BACKTEST_MONTH = sys.argv[2] + BACKTEST_YEAR = sys.argv[3] + clean_json() \ No newline at end of file diff --git a/user_data/strategies/util.py b/user_data/strategies/util.py index cf5e50a11..55b246ea3 100644 --- a/user_data/strategies/util.py +++ b/user_data/strategies/util.py @@ -1,7 +1,8 @@ import subprocess -CURRENT_YEAR = 2020 -CURRENT_MONTH = 10 +BACKTEST_JSON_PATH = "" +BACKTEST_YEAR = 2020 +BACKTEST_MONTH = 10 IS_BACKTEST = False WORKSPACE_PATH = "workspace2" if IS_BACKTEST else "workspace" EXECUTION_PATH = "/root/" + WORKSPACE_PATH + "/execution/"