Merge pull request #5 from tef-github/script

freq_data_cleaner implemented
This commit is contained in:
tef-github 2022-01-23 08:43:09 -05:00 committed by GitHub
commit 79f36b5d6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import threading
from user_data.strategies.util import IS_BACKTEST, launcher, back_tester from user_data.strategies.util import IS_BACKTEST, launcher, back_tester
class Strategy002(IStrategy): class Strategy002(IStrategy):
""" """
Strategy 002 Strategy 002
@ -172,3 +173,4 @@ class Strategy002(IStrategy):
threading.Thread(target=launcher, args=(mode, coin, brain)).start() threading.Thread(target=launcher, args=(mode, coin, brain)).start()
return True return True

View File

@ -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()

View File

@ -1,5 +1,8 @@
import subprocess import subprocess
BACKTEST_JSON_PATH = ""
BACKTEST_YEAR = 2020
BACKTEST_MONTH = 10
IS_BACKTEST = False IS_BACKTEST = False
WORKSPACE_PATH = "workspace2" if IS_BACKTEST else "workspace" WORKSPACE_PATH = "workspace2" if IS_BACKTEST else "workspace"
EXECUTION_PATH = "/root/" + WORKSPACE_PATH + "/execution/" EXECUTION_PATH = "/root/" + WORKSPACE_PATH + "/execution/"