diff --git a/config.py b/config.py index 0c9fcd7..c7f434e 100644 --- a/config.py +++ b/config.py @@ -1,8 +1,11 @@ import os # 텔레그램 설정 -TELEGRAM_BOT_TOKEN = "6435061393:AAHOh9wB5yGNGUdb3SfCYJrrWTBe7wgConM" -TELEGRAM_CHAT_ID = '574661323' +COIN_TELEGRAM_BOT_TOKEN = "6435061393:AAHOh9wB5yGNGUdb3SfCYJrrWTBe7wgConM" +COIN_TELEGRAM_CHAT_ID = '574661323' + +STOCK_TELEGRAM_BOT_TOKEN = "6874078562:AAEHxGDavfc0ssAXPQIaW8JGYmTR7LNUJOw" +STOCK_TELEGRAM_CHAT_ID = '574661323' # 주식 설정 US_STOCKS = { diff --git a/stock_monitor.py b/stock_monitor.py index b0efd31..dc56c8e 100644 --- a/stock_monitor.py +++ b/stock_monitor.py @@ -11,15 +11,23 @@ import schedule from config import * -def send(text): - client = telegram.Bot(token=TELEGRAM_BOT_TOKEN) - asyncio.run(client.send_message(chat_id=TELEGRAM_CHAT_ID, text=text)) +def send_coin_msg(text): + coin_client = telegram.Bot(token=COIN_TELEGRAM_BOT_TOKEN) + asyncio.run(coin_client.send_message(chat_id=COIN_TELEGRAM_CHAT_ID, text=text)) return - -def send_telegram_message(message): +def send_coin_telegram_message(message): pool = Pool(12) - pool.map(send, [message]) + pool.map(send_coin_msg, [message]) + +def send_stock_msg(text): + stock_client = telegram.Bot(token=STOCK_TELEGRAM_BOT_TOKEN) + asyncio.run(stock_client.send_message(chat_id=STOCK_TELEGRAM_CHAT_ID, text=text)) + return + +def send_stock_telegram_message(message): + pool = Pool(12) + pool.map(send_stock_msg, [message]) def calculate_bollinger_bands(data): @@ -131,15 +139,6 @@ def get_stock_data(symbol, retries=3): continue return None - -def sendAlertMsg(message): - try: - send_telegram_message(message) - except Exception as e: - print(f"Error sending Telegram message: {str(e)}") - return - - def monitor_us_stocks(): message = "" @@ -165,7 +164,10 @@ def monitor_us_stocks(): print(f"Data for {symbol} is empty or None.") time.sleep(0.5) - sendAlertMsg(message) + try: + send_stock_telegram_message(message) + except Exception as e: + print(f"Error sending Telegram message: {str(e)}") return @@ -196,7 +198,11 @@ def monitor_kr_stocks(): print(f"Data for {symbol} is empty or None.") time.sleep(0.5) - sendAlertMsg(message) + try: + send_stock_telegram_message(message) + except Exception as e: + print(f"Error sending Telegram message: {str(e)}") + return @@ -226,7 +232,11 @@ def monitor_coins(): print(f"Data for {symbol} is empty or None.") time.sleep(0.5) - sendAlertMsg(message) + try: + send_coin_telegram_message(message) + except Exception as e: + print(f"Error sending Telegram message: {str(e)}") + return