This commit is contained in:
dsyoon
2025-05-01 09:44:43 +09:00
parent 294ba4f3d9
commit 56d2521a55
2 changed files with 33 additions and 20 deletions

View File

@@ -1,8 +1,11 @@
import os import os
# 텔레그램 설정 # 텔레그램 설정
TELEGRAM_BOT_TOKEN = "6435061393:AAHOh9wB5yGNGUdb3SfCYJrrWTBe7wgConM" COIN_TELEGRAM_BOT_TOKEN = "6435061393:AAHOh9wB5yGNGUdb3SfCYJrrWTBe7wgConM"
TELEGRAM_CHAT_ID = '574661323' COIN_TELEGRAM_CHAT_ID = '574661323'
STOCK_TELEGRAM_BOT_TOKEN = "6874078562:AAEHxGDavfc0ssAXPQIaW8JGYmTR7LNUJOw"
STOCK_TELEGRAM_CHAT_ID = '574661323'
# 주식 설정 # 주식 설정
US_STOCKS = { US_STOCKS = {

View File

@@ -11,15 +11,23 @@ import schedule
from config import * from config import *
def send(text): def send_coin_msg(text):
client = telegram.Bot(token=TELEGRAM_BOT_TOKEN) coin_client = telegram.Bot(token=COIN_TELEGRAM_BOT_TOKEN)
asyncio.run(client.send_message(chat_id=TELEGRAM_CHAT_ID, text=text)) asyncio.run(coin_client.send_message(chat_id=COIN_TELEGRAM_CHAT_ID, text=text))
return return
def send_coin_telegram_message(message):
def send_telegram_message(message):
pool = Pool(12) 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): def calculate_bollinger_bands(data):
@@ -131,15 +139,6 @@ def get_stock_data(symbol, retries=3):
continue continue
return None 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(): def monitor_us_stocks():
message = "" message = ""
@@ -165,7 +164,10 @@ def monitor_us_stocks():
print(f"Data for {symbol} is empty or None.") print(f"Data for {symbol} is empty or None.")
time.sleep(0.5) 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 return
@@ -196,7 +198,11 @@ def monitor_kr_stocks():
print(f"Data for {symbol} is empty or None.") print(f"Data for {symbol} is empty or None.")
time.sleep(0.5) 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 return
@@ -226,7 +232,11 @@ def monitor_coins():
print(f"Data for {symbol} is empty or None.") print(f"Data for {symbol} is empty or None.")
time.sleep(0.5) 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 return