diff --git a/stock_monitor.py b/stock_monitor.py index 29441ac..a0af20a 100644 --- a/stock_monitor.py +++ b/stock_monitor.py @@ -127,16 +127,21 @@ def check_buy_point(data, simulation=None): else: recent_data = data.tail(10) - recent_data['buy_point'] = 0 - for i in range(1, len(recent_data)): - if all(recent_data[f'MA{n}'].iloc[i] < recent_data['MA720'].iloc[i] for n in [5, 20, 40, 120, 200, 240]) and \ - all(recent_data[f'MA{n}'].iloc[i] > recent_data[f'MA{n}'].iloc[i-1] for n in [5, 20, 40, 120, 200, 240]) and \ - recent_data['MA720'].iloc[i] < recent_data['MA1440'].iloc[i]: - recent_data.at[recent_data.index[i], 'buy_point'] = 1 + # SettingWithCopyWarning 해결 + recent_data.loc[:, 'buy_point'] = 0 + + # FutureWarning 해결 + if recent_data['buy_point'].iloc[-1] != 1: + # 코드 계속 + for i in range(1, len(recent_data)): + if all(recent_data[f'MA{n}'].iloc[i] < recent_data['MA720'].iloc[i] for n in [5, 20, 40, 120, 200, 240]) and \ + all(recent_data[f'MA{n}'].iloc[i] > recent_data[f'MA{n}'].iloc[i-1] for n in [5, 20, 40, 120, 200, 240]) and \ + recent_data['MA720'].iloc[i] < recent_data['MA1440'].iloc[i]: + recent_data.at[recent_data.index[i], 'buy_point'] = 1 if not simulation: if recent_data['buy_point'][-10:-1].sum() > 0: - recent_data['buy_point'][-1] = 1 + recent_data.at[recent_data.index[-1], 'buy_point'] = 1 return recent_data @@ -261,7 +266,7 @@ def monitor_us_stocks(): try: data = calculate_technical_indicators(data) recent_data = check_buy_point(data) # Changed to check_buy_point - if recent_data['buy_point'][-1] != 1: + if recent_data['buy_point'].iloc[-1] != 1: continue print(f" - {US_STOCKS[symbol]} ({symbol}): {recent_data['Close'][-1]:.2f}") message_list.append(format_message('US', symbol, US_STOCKS[symbol], recent_data['Close'][-1])) @@ -292,7 +297,7 @@ def monitor_kr_stocks(): try: data = calculate_technical_indicators(data) recent_data = check_buy_point(data) # Changed to check_buy_point - if recent_data['buy_point'][-1] != 1: + if recent_data['buy_point'].iloc[-1] != 1: continue print(f" - {KR_ETFS[symbol]} ({symbol}): {recent_data['Close'][-1]:.2f}") message_list.append(format_message('KR', symbol, US_STOCKS[symbol], recent_data['Close'][-1])) @@ -332,7 +337,7 @@ def monitor_coins(): try: data = calculate_technical_indicators(data) recent_data = check_buy_point(data) # Changed to check_buy_point - if recent_data['buy_point'][-1] != 1: + if recent_data['buy_point'].iloc[-1] != 1: continue print(f" - {KR_ETFS[symbol]} ({symbol}): {recent_data['Close'][-1]:.2f}") message_list.append(format_message('COIN', symbol, US_STOCKS[symbol], recent_data['Close'][-1])) @@ -412,4 +417,5 @@ def run_schedule(): if __name__ == "__main__": - run_schedule() + #run_schedule() + monitor_coins()