From 40bc3c6319ed0ca6bdc7b5a21b7488e30940ef12 Mon Sep 17 00:00:00 2001 From: Bemhreth Date: Fri, 14 Jan 2022 23:44:55 +0300 Subject: [PATCH 1/2] implemented paralller execution --- user_data/strategies/Strategy002.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/user_data/strategies/Strategy002.py b/user_data/strategies/Strategy002.py index 2fc5cfce4..168f239b7 100644 --- a/user_data/strategies/Strategy002.py +++ b/user_data/strategies/Strategy002.py @@ -13,6 +13,8 @@ import freqtrade.vendor.qtpylib.indicators as qtpylib import numpy # noqa from datetime import datetime import subprocess +import threading + class Strategy002(IStrategy): @@ -138,6 +140,10 @@ class Strategy002(IStrategy): ), 'sell'] = 1 return dataframe + + def call_launcher(self, mode, coin): + print("strategy002: call_launcher: mode = " + mode + " coin = " +coin) + subprocess.call("python3 /root/workspace2/execution/launcher.py " + mode + " " + coin, shell=True) def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float, time_in_force: str, current_time: datetime, **kwargs) -> bool: @@ -162,6 +168,7 @@ class Strategy002(IStrategy): """ mode = "test" coin = pair.split("/")[0] - subprocess.call("python3 /root/workspace/execution/launcher.py " + mode + " " + coin, shell=True) + thread = threading.Thread(target=self.call_launcher, args=(mode,coin)) + thread.start() return True From 9e44990ae7f0d3bc35eb86eddb5229963a76db75 Mon Sep 17 00:00:00 2001 From: tef Date: Sat, 15 Jan 2022 00:35:18 -0500 Subject: [PATCH 2/2] fix pr comments --- user_data/strategies/Strategy002.py | 11 +++++------ user_data/strategies/Strategy003.py | 10 +++++++++- user_data/strategies/Strategy004.py | 9 ++++++++- user_data/strategies/util.py | 11 +++++++++++ 4 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 user_data/strategies/util.py diff --git a/user_data/strategies/Strategy002.py b/user_data/strategies/Strategy002.py index 168f239b7..813a8ba1f 100644 --- a/user_data/strategies/Strategy002.py +++ b/user_data/strategies/Strategy002.py @@ -15,6 +15,7 @@ from datetime import datetime import subprocess import threading +from user_data.strategies.util import thread_executor, IS_BACKTEST, launcher, back_tester class Strategy002(IStrategy): @@ -140,10 +141,6 @@ class Strategy002(IStrategy): ), 'sell'] = 1 return dataframe - - def call_launcher(self, mode, coin): - print("strategy002: call_launcher: mode = " + mode + " coin = " +coin) - subprocess.call("python3 /root/workspace2/execution/launcher.py " + mode + " " + coin, shell=True) def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float, time_in_force: str, current_time: datetime, **kwargs) -> bool: @@ -168,7 +165,9 @@ class Strategy002(IStrategy): """ mode = "test" coin = pair.split("/")[0] - thread = threading.Thread(target=self.call_launcher, args=(mode,coin)) - thread.start() + if IS_BACKTEST: + threading.Thread(target=back_tester, args=(current_time, coin)).start() + else: + threading.Thread(target=launcher, args=(mode, coin)).start() return True diff --git a/user_data/strategies/Strategy003.py b/user_data/strategies/Strategy003.py index 3856e9a50..2b64cdf15 100644 --- a/user_data/strategies/Strategy003.py +++ b/user_data/strategies/Strategy003.py @@ -1,5 +1,7 @@ # --- Do not remove these libs --- +import threading + from freqtrade.strategy.interface import IStrategy from typing import Dict, List from functools import reduce @@ -12,6 +14,9 @@ import numpy # noqa from datetime import datetime import subprocess +from user_data.strategies.util import IS_BACKTEST, back_tester, launcher + + class Strategy003(IStrategy): """ Strategy 003 @@ -175,5 +180,8 @@ class Strategy003(IStrategy): """ mode = "test" coin = pair.split("/")[0] - subprocess.call("python3 /root/workspace/execution/launcher.py " + mode + " " + coin, shell=True) + if IS_BACKTEST: + threading.Thread(target=back_tester, args=(current_time, coin)).start() + else: + threading.Thread(target=launcher, args=(mode, coin)).start() return True \ No newline at end of file diff --git a/user_data/strategies/Strategy004.py b/user_data/strategies/Strategy004.py index 3645b17dc..ef0b6b87f 100644 --- a/user_data/strategies/Strategy004.py +++ b/user_data/strategies/Strategy004.py @@ -1,4 +1,6 @@ # --- Do not remove these libs --- +import threading + from freqtrade.strategy import IStrategy from typing import Dict, List from functools import reduce @@ -9,6 +11,8 @@ import subprocess import talib.abstract as ta +from user_data.strategies.util import IS_BACKTEST, back_tester, launcher + class Strategy004(IStrategy): """ @@ -176,5 +180,8 @@ class Strategy004(IStrategy): """ mode = "test" coin = pair.split("/")[0] - subprocess.call("python3 /root/workspace/execution/launcher.py " + mode + " " + coin, shell=True) + if IS_BACKTEST: + threading.Thread(target=back_tester, args=(current_time, coin)).start() + else: + threading.Thread(target=launcher, args=(mode, coin)).start() return True diff --git a/user_data/strategies/util.py b/user_data/strategies/util.py new file mode 100644 index 000000000..5e0bb60ee --- /dev/null +++ b/user_data/strategies/util.py @@ -0,0 +1,11 @@ +import subprocess + +IS_BACKTEST = False + +EXECUTION_PATH = "/root/workspace2/execution/" + +def launcher(mode, coin): + subprocess.call("python3 "+EXECUTION_PATH+"launcher.py " + mode + " " + coin, shell=True) + +def back_tester(date_time, coin): + subprocess.call("python3 "+EXECUTION_PATH+"back_tester.py " + date_time + " " + coin, shell=True)