diff --git a/stock_monitor.py b/stock_monitor.py index 6c54fb2..1920c68 100644 --- a/stock_monitor.py +++ b/stock_monitor.py @@ -14,8 +14,6 @@ import FinanceDataReader as fdr import numpy as np hts = HTS() -BUY_AMOUNT = 10000 - def send_coin_msg(text): coin_client = telegram.Bot(token=COIN_TELEGRAM_BOT_TOKEN) @@ -39,8 +37,13 @@ def send_coin_telegram_message(message_list, header): return -def buy_ticker(symbole): +def buy_ticker(symbole, data): try: + BUY_AMOUNT = 5000 + + if data['buy_signal'].iloc[-1] == 'moving average': + BUY_AMOUNT = 10000 + _ = hts.buyCoinMarket(symbole, BUY_AMOUNT) except Exception as e: print(f"Error buying {symbole}: {str(e)}") @@ -150,6 +153,7 @@ def check_buy_point(data, simulation=None): # 매수 포인트 탐지 및 표시 # 'buy_point' 열 초기화 + data['buy_signal'] = '' data['buy_point'] = 0 # FutureWarning 해결 @@ -159,6 +163,7 @@ def check_buy_point(data, simulation=None): if all(data[f'MA{n}'].iloc[i] < data['MA720'].iloc[i] for n in [5, 20, 40, 120, 200, 240]) and \ all(data[f'MA{n}'].iloc[i] > data[f'MA{n}'].iloc[i - 1] for n in [5, 20, 40, 120, 200, 240]) and \ data['MA720'].iloc[i] < data['MA1440'].iloc[i]: + data.at[data.index[i], 'buy_signal'] = 'moving average' data.at[data.index[i], 'buy_point'] = 1 if not simulation: @@ -167,8 +172,8 @@ def check_buy_point(data, simulation=None): return data -def format_message(market_type, symbol, symbol_name, close): - message = f"매수 [{market_type}] {symbol_name} ({symbol}) " +def format_message(market_type, symbol, symbol_name, close, buy_signal): + message = f"매수 [{market_type}] {symbol_name} ({symbol}): {buy_signal} " message += f"현재가: {'$' if market_type == 'US' else '₩'}{close:.2f}, " return message @@ -291,7 +296,7 @@ def monitor_us_stocks(): 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])) + message_list.append(format_message('US', symbol, US_STOCKS[symbol], recent_data['Close'][-1], recent_data['buy_signal'][-1])) except Exception as e: print(f"Error processing data for {symbol}: {str(e)}") time.sleep(0.5) @@ -362,10 +367,10 @@ def monitor_coins(): 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])) + message_list.append(format_message('COIN', symbol, US_STOCKS[symbol], recent_data['Close'][-1], recent_data['buy_signal'][-1])) # buy - buy_ticker(symbol) + buy_ticker(symbol, recent_data) except Exception as e: print(f"Error processing data for {symbol}: {str(e)}") @@ -373,27 +378,6 @@ def monitor_coins(): print(f"Data for {symbol} is empty or None.") time.sleep(0.5) - # 4시간 - interval = 240 - data = get_coin_more_data(symbol, interval, bong_count=1500) - - if data is not None and not data.empty: - try: - data = calculate_technical_indicators(data) - info = check_buy_point(data, simulation=True) # Changed to check_buy_point - if info is None: - continue - info['name'] = KR_COINS[symbol] - print(f" - {info['name']} ({symbol}): {info['price']:.2f} -> {info['buy']}") - - if info['buy']: - message_list.append(format_message(info, 'KR')) - except Exception as e: - print(f"Error processing data for {symbol}: {str(e)}") - else: - print(f"Data for {symbol} is empty or None.") - time.sleep(0.5) - if len(message_list) > 0: try: # send message diff --git a/stock_simulation.py b/stock_simulation.py index f88aaf0..c2cd46e 100644 --- a/stock_simulation.py +++ b/stock_simulation.py @@ -227,8 +227,8 @@ def run_simulation(symbol: str, interval_minutes: int, days: int = 30): if __name__ == "__main__": interval = 60 days = 90 # 분석 기간을 90일로 늘림 (6월~8월 데이터 포함) - target_coins = ['ADA','APE','ARB','BONK','HBAR','LINK','ONDO','PEPE','SEI','SHIB','STORJ','SUI','TON','TRX','WLD','XLM','XRP'] - #target_coins = ['APE'] + #target_coins = ['ADA','APE','ARB','BONK','HBAR','LINK','ONDO','PEPE','SEI','SHIB','STORJ','SUI','TON','TRX','WLD','XLM','XRP'] + target_coins = ['APE'] for symbol in target_coins: print(f"\n=== {symbol} 저점 기간 분석 시작 ===")