From c304eaeac8b1b0067383940c8a5caf86daa2cecb Mon Sep 17 00:00:00 2001 From: dsyoon Date: Mon, 4 Aug 2025 09:09:27 +0900 Subject: [PATCH] init --- stock_monitor.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/stock_monitor.py b/stock_monitor.py index d98ed92..3418d92 100644 --- a/stock_monitor.py +++ b/stock_monitor.py @@ -304,10 +304,10 @@ def format_ma_message(info, market_type): message += f"현재가: {'$' if market_type == 'US' else '₩'}{info['price']:.2f} \n" return message -def get_coin_data(symbol, retries=3): +def get_coin_data(symbol, interval=240, retries=3): for attempt in range(retries): try: - url = "https://api.bithumb.com/v1/candles/minutes/{}?market=KRW-{}&count=3000".format(240, symbol) + url = "https://api.bithumb.com/v1/candles/minutes/{}?market=KRW-{}&count=3000".format(interval, symbol) headers = {"accept": "application/json"} response = requests.get(url, headers=headers) json_data = json.loads(response.text) @@ -449,7 +449,25 @@ def monitor_coins(): print("KRW COINs {}".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) for symbol in KR_COINS: - data = get_coin_data(symbol) + data = get_coin_data(symbol, interval=60) + if data is not None and not data.empty: + try: + data = calculate_technical_indicators(data) + info = check_ma_alert(symbol, data) + if info is None: + continue + info['name'] = KR_COINS[symbol] + print(f" - {info['name']} ({symbol}): {info['price']:.2f} -> {info['alert']}") + + if info['alert']: + message_list.append(format_ma_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) + + data = get_coin_data(symbol, interval=240) if data is not None and not data.empty: try: data = calculate_technical_indicators(data) @@ -478,7 +496,7 @@ def monitor_coins(): def run_schedule(): # 코인 모니터링 스케줄 (매시간 1분, 11분, 21분, 31분, 41분, 51분) - for minute in [4, 34]: + for minute in [4, 14, 24, 34, 44, 54]: schedule.every().hour.at(f":{minute:02d}").do(monitor_coins) # 미국 주식 모니터링 스케줄 (매일 저녁 5시 20분)