From a98cb0075fa1a08554d94e1dc797846645f912d3 Mon Sep 17 00:00:00 2001 From: msaltnet Date: Sat, 26 Feb 2022 21:33:15 +0900 Subject: [PATCH] add add_drawing_spot to sma strategy --- smtm/strategy_sma_0.py | 12 +++++++++++- tests/strategy_sma_0_test.py | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/smtm/strategy_sma_0.py b/smtm/strategy_sma_0.py index 8bde47f..c3d914c 100644 --- a/smtm/strategy_sma_0.py +++ b/smtm/strategy_sma_0.py @@ -52,6 +52,7 @@ def __init__(self): self.logger = LogManager.get_logger(__class__.__name__) self.waiting_requests = {} self.cross_info = [{"price": 0, "index": 0}, {"price": 0, "index": 0}] + self.add_spot_callback = None def update_trading_info(self, info): """새로운 거래 정보를 업데이트 @@ -80,6 +81,10 @@ def _get_deviation_ratio(std, last): ratio = std / last * 1000000 return math.floor(ratio) / 1000000 + def __add_drawing_spot(self, date_time, value): + if self.add_spot_callback is not None: + self.add_spot_callback(date_time, value) + def __update_process(self, info): try: current_price = info["closing_price"] @@ -100,6 +105,7 @@ def __update_process(self, info): return if sma_short > sma_mid > sma_long and self.current_process != "buy": + is_skip = False self.current_process = "buy" self.process_unit = (round(self.balance / self.STEP), 0) @@ -118,13 +124,16 @@ def __update_process(self, info): if std_ratio > self.STD_RATIO: self.cross_info[1] = {"price": 0, "index": current_idx} self.logger.debug(f"[SMA] SKIP BUY !!! === Stand deviation:{std_ratio:.6f}") - + is_skip = True + if is_skip is not True: + self.__add_drawing_spot(info["date_time"], self.process_unit[0]) elif sma_short < sma_mid < sma_long and self.current_process != "sell": self.current_process = "sell" self.process_unit = (0, self.asset_amount / self.STEP) self.logger.debug( f"[SMA] Try to sell {sma_short} {sma_mid} {sma_long}, amout: {self.process_unit[1]}" ) + self.__add_drawing_spot(info["date_time"], info["closing_price"]) else: return self.cross_info[0] = self.cross_info[1] @@ -337,3 +346,4 @@ def initialize(self, budget, min_price=5000, add_spot_callback=None): self.budget = budget self.balance = budget self.min_price = min_price + self.add_spot_callback = add_spot_callback diff --git a/tests/strategy_sma_0_test.py b/tests/strategy_sma_0_test.py index 73ec975..b6697df 100644 --- a/tests/strategy_sma_0_test.py +++ b/tests/strategy_sma_0_test.py @@ -74,6 +74,7 @@ class DummyMean: mock_series.return_value = series_return dummy_info = { + "date_time": "mango", "closing_price": 500, } mock_np.return_value = False @@ -129,6 +130,7 @@ class DummyMean: mock_series.return_value = series_return dummy_info = { + "date_time": "mango", "closing_price": 500, } mock_np.return_value = False