Skip to content

Commit

Permalink
apply black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
msaltnet committed May 6, 2024
1 parent 601b275 commit 5c15e2a
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 23 deletions.
4 changes: 1 addition & 3 deletions smtm/controller/telegram_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,4 @@ def _terminate(self, signum=None, frame=None):

def alert_callback(self, msg):
"""예외 상황 처리"""
self._send_text_message(
f"Alert: {msg}", self.main_keyboard
)
self._send_text_message(f"Alert: {msg}", self.main_keyboard)
7 changes: 6 additions & 1 deletion smtm/strategy/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ class Strategy(metaclass=ABCMeta):

@abstractmethod
def initialize(
self, budget, min_price=100, add_spot_callback=None, add_line_callback=None, alert_callback=None
self,
budget,
min_price=100,
add_spot_callback=None,
add_line_callback=None,
alert_callback=None,
):
"""예산을 설정하고 초기화한다
Expand Down
7 changes: 6 additions & 1 deletion smtm/strategy/strategy_bnh.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ def get_request(self):
return None

def initialize(
self, budget, min_price=5000, add_spot_callback=None, add_line_callback=None, alert_callback=None
self,
budget,
min_price=5000,
add_spot_callback=None,
add_line_callback=None,
alert_callback=None,
):
"""예산과 최소 거래 가능 금액을 설정한다"""
if self.is_intialized:
Expand Down
1 change: 1 addition & 0 deletions smtm/strategy/strategy_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .strategy_sas import StrategySas
from .strategy_hey import StrategyHey


class StrategyFactory:
"""Strategy 정보 조회 및 생성을 담당하는 Factory 클래스"""

Expand Down
46 changes: 32 additions & 14 deletions smtm/strategy/strategy_hey.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,25 @@ def _checking_sma(self, info):
self.current_process = "buy"
self.buy_price = current_price
self.loss_cut_alerted = False
self.logger.debug(f"[HEY] BUY #{current_idx} {sma_short} : {sma_mid} : {sma_long}")
self.logger.debug(
f"[HEY] BUY #{current_idx} {sma_short} : {sma_mid} : {sma_long}"
)
elif (sma_short < sma_mid < sma_long) and self.current_process != "sell":
self.current_process = "sell"
self.buy_price = 0
self.loss_cut_alerted = False
self.logger.debug(f"[HEY] SELL #{current_idx} {sma_short} : {sma_mid} : {sma_long}")
elif self._is_loss_cut_entered(current_price) and self.current_process != "sell" and not self.loss_cut_alerted:
self.logger.debug(
f"[HEY] SELL #{current_idx} {sma_short} : {sma_mid} : {sma_long}"
)
elif (
self._is_loss_cut_entered(current_price)
and self.current_process != "sell"
and not self.loss_cut_alerted
):
self.loss_cut_alerted = True
self.logger.debug(f"[HEY] LOSS CUT #{current_idx} {sma_short} : {sma_mid} : {sma_long}")
self.logger.debug(
f"[HEY] LOSS CUT #{current_idx} {sma_short} : {sma_mid} : {sma_long}"
)
else:
return

Expand All @@ -153,8 +163,12 @@ def _checking_volitility_breakout(self, info):
self.update_atr_info(info)
breakout_buy_signal, breakout_sell_signal = self.detect_breakout_signals()
if breakout_buy_signal or breakout_sell_signal:
self.logger.debug(f"[HEY] BREAKOUT {info['date_time']} {breakout_buy_signal} {breakout_sell_signal}")
self.logger.debug(f"-- {self.atr} {info['closing_price']} {self.prev_close}")
self.logger.debug(
f"[HEY] BREAKOUT {info['date_time']} {breakout_buy_signal} {breakout_sell_signal}"
)
self.logger.debug(
f"-- {self.atr} {info['closing_price']} {self.prev_close}"
)
self._make_alert(
info["date_time"],
info["closing_price"],
Expand All @@ -168,12 +182,12 @@ def update_atr_info(self, new_price_info):

if len(self.data) > 1:
# 이전 거래일 종가
self.prev_close = self.data[-2]['closing_price']
self.prev_close = self.data[-2]["closing_price"]

# 새로운 True Range 계산
current_high = new_price_info['high_price']
current_low = new_price_info['low_price']
prev_close = self.data[-2]['closing_price']
current_high = new_price_info["high_price"]
current_low = new_price_info["low_price"]
prev_close = self.data[-2]["closing_price"]

high_low = current_high - current_low
high_close = abs(current_high - prev_close)
Expand All @@ -196,11 +210,15 @@ def detect_breakout_signals(self):
return False, False

current_price = self.data[-1]
current_high = current_price['high_price']
current_low = current_price['low_price']
current_high = current_price["high_price"]
current_low = current_price["low_price"]

breakout_buy_signal = current_high > self.prev_close + self.VOLATILITY_BREAKOUT * self.atr
breakout_sell_signal = current_low < self.prev_close - self.VOLATILITY_BREAKOUT * self.atr
breakout_buy_signal = (
current_high > self.prev_close + self.VOLATILITY_BREAKOUT * self.atr
)
breakout_sell_signal = (
current_low < self.prev_close - self.VOLATILITY_BREAKOUT * self.atr
)

return breakout_buy_signal, breakout_sell_signal

Expand Down
7 changes: 6 additions & 1 deletion smtm/strategy/strategy_rsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ def __init__(self):
self.position = None

def initialize(
self, budget, min_price=100, add_spot_callback=None, add_line_callback=None, alert_callback=None
self,
budget,
min_price=100,
add_spot_callback=None,
add_line_callback=None,
alert_callback=None,
):
"""예산을 설정하고 초기화한다
Expand Down
7 changes: 6 additions & 1 deletion smtm/strategy/strategy_sma_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,12 @@ def __create_sell(self):
}

def initialize(
self, budget, min_price=5000, add_spot_callback=None, add_line_callback=None, alert_callback=None
self,
budget,
min_price=5000,
add_spot_callback=None,
add_line_callback=None,
alert_callback=None,
):
"""
예산과 최소 거래 가능 금액을 설정한다
Expand Down
7 changes: 6 additions & 1 deletion smtm/strategy/strategy_sma_dual_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ def __init__(self):
self.last_upper = None

def initialize(
self, budget, min_price=5000, add_spot_callback=None, add_line_callback=None, alert_callback=None
self,
budget,
min_price=5000,
add_spot_callback=None,
add_line_callback=None,
alert_callback=None,
):
"""
예산과 최소 거래 가능 금액을 설정한다
Expand Down
7 changes: 6 additions & 1 deletion smtm/strategy/strategy_sma_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ def __init__(self):
self.last_upper = None

def initialize(
self, budget, min_price=5000, add_spot_callback=None, add_line_callback=None, alert_callback=None
self,
budget,
min_price=5000,
add_spot_callback=None,
add_line_callback=None,
alert_callback=None,
):
"""
예산과 최소 거래 가능 금액을 설정한다
Expand Down

0 comments on commit 5c15e2a

Please sign in to comment.