Skip to content

Commit

Permalink
add add_drawing_spot to sma strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
msaltnet committed Feb 26, 2022
1 parent 5bdb5e1 commit a98cb00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion smtm/strategy_sma_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""새로운 거래 정보를 업데이트
Expand Down Expand Up @@ -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"]
Expand All @@ -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)

Expand All @@ -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]
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions tests/strategy_sma_0_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a98cb00

Please sign in to comment.