init
This commit is contained in:
@@ -10,15 +10,18 @@ from multiprocessing import Pool
|
|||||||
import schedule
|
import schedule
|
||||||
from config import *
|
from config import *
|
||||||
|
|
||||||
|
|
||||||
def send(text):
|
def send(text):
|
||||||
client = telegram.Bot(token=TELEGRAM_BOT_TOKEN)
|
client = telegram.Bot(token=TELEGRAM_BOT_TOKEN)
|
||||||
asyncio.run(client.send_message(chat_id=TELEGRAM_CHAT_ID, text=text))
|
asyncio.run(client.send_message(chat_id=TELEGRAM_CHAT_ID, text=text))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def send_telegram_message(message):
|
def send_telegram_message(message):
|
||||||
pool = Pool(12)
|
pool = Pool(12)
|
||||||
pool.map(send, [message])
|
pool.map(send, [message])
|
||||||
|
|
||||||
|
|
||||||
def calculate_bollinger_bands(data):
|
def calculate_bollinger_bands(data):
|
||||||
data['MA'] = data['Close'].rolling(window=BOLLINGER_PERIOD).mean()
|
data['MA'] = data['Close'].rolling(window=BOLLINGER_PERIOD).mean()
|
||||||
data['STD'] = data['Close'].rolling(window=BOLLINGER_PERIOD).std()
|
data['STD'] = data['Close'].rolling(window=BOLLINGER_PERIOD).std()
|
||||||
@@ -26,6 +29,7 @@ def calculate_bollinger_bands(data):
|
|||||||
data['Lower'] = data['MA'] - (BOLLINGER_STD * data['STD'])
|
data['Lower'] = data['MA'] - (BOLLINGER_STD * data['STD'])
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def check_bollinger_bands(symbol, data):
|
def check_bollinger_bands(symbol, data):
|
||||||
if len(data) < BOLLINGER_PERIOD:
|
if len(data) < BOLLINGER_PERIOD:
|
||||||
return None
|
return None
|
||||||
@@ -46,6 +50,7 @@ def check_bollinger_bands(symbol, data):
|
|||||||
'distance': distance
|
'distance': distance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_coin_data(symbol, retries=3):
|
def get_coin_data(symbol, retries=3):
|
||||||
for attempt in range(retries):
|
for attempt in range(retries):
|
||||||
try:
|
try:
|
||||||
@@ -82,6 +87,7 @@ def get_coin_data(symbol, retries=3):
|
|||||||
continue
|
continue
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_stock_data(symbol, retries=3):
|
def get_stock_data(symbol, retries=3):
|
||||||
for attempt in range(retries):
|
for attempt in range(retries):
|
||||||
try:
|
try:
|
||||||
@@ -106,11 +112,14 @@ def get_stock_data(symbol, retries=3):
|
|||||||
continue
|
continue
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def sendAlertMsg(info, market="US"):
|
def sendAlertMsg(info, market="US"):
|
||||||
if market == "US":
|
if market == "US":
|
||||||
message = "🔔 [US] {} ({}) 현재가: ${:.2f}, 근접도: {:.2f}%".format(info['name'], info['symbol'], info['price'], info['distance'])
|
message = "🔔 [US] {} ({}) 현재가: ${:.2f}, 근접도: {:.2f}%".format(info['name'], info['symbol'], info['price'],
|
||||||
|
info['distance'])
|
||||||
else:
|
else:
|
||||||
message = "🔔 [KR] {} ({}) 현재가: ₩{:.0f}, 근접도: {:.2f}%".format(info['name'], info['symbol'].replace('.KS', ''), info['price'], info['distance'])
|
message = "🔔 [KR] {} ({}) 현재가: ₩{:.0f}, 근접도: {:.2f}%".format(info['name'], info['symbol'].replace('.KS', ''),
|
||||||
|
info['price'], info['distance'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
send_telegram_message(message)
|
send_telegram_message(message)
|
||||||
@@ -118,6 +127,7 @@ def sendAlertMsg(info, market="US"):
|
|||||||
print(f"Error sending Telegram message: {str(e)}")
|
print(f"Error sending Telegram message: {str(e)}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def monitor_us_stocks():
|
def monitor_us_stocks():
|
||||||
# 미국 주식 모니터링
|
# 미국 주식 모니터링
|
||||||
print("Monitoring US stocks...")
|
print("Monitoring US stocks...")
|
||||||
@@ -141,6 +151,7 @@ def monitor_us_stocks():
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def monitor_kr_stocks():
|
def monitor_kr_stocks():
|
||||||
# 한국 ETF 모니터링
|
# 한국 ETF 모니터링
|
||||||
print("\nMonitoring Korean ETFs...")
|
print("\nMonitoring Korean ETFs...")
|
||||||
@@ -164,8 +175,9 @@ def monitor_kr_stocks():
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def monitor_coins():
|
def monitor_coins():
|
||||||
# 미국 주식 모니터링
|
# 코인 모니터링
|
||||||
print("Monitoring KR Coins...")
|
print("Monitoring KR Coins...")
|
||||||
for symbol in KR_COINS:
|
for symbol in KR_COINS:
|
||||||
data = get_coin_data(symbol)
|
data = get_coin_data(symbol)
|
||||||
@@ -187,25 +199,23 @@ def monitor_coins():
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def run_schedule():
|
def run_schedule():
|
||||||
|
# 코인 모니터링 스케줄 (매시간 1분, 11분, 21분, 31분, 41분, 51분)
|
||||||
|
for minute in [1, 11, 21, 31, 41, 51]:
|
||||||
|
schedule.every().hour.at(f":{minute:02d}").do(monitor_coins)
|
||||||
|
|
||||||
|
# 미국 주식 모니터링 스케줄 (매일 저녁 5시 20분)
|
||||||
|
schedule.every().day.at("17:20").do(monitor_us_stocks)
|
||||||
|
|
||||||
|
# 한국 ETF 모니터링 스케줄 (매일 오전 8시)
|
||||||
|
schedule.every().day.at("18:20").do(monitor_kr_stocks)
|
||||||
|
|
||||||
|
print("Scheduler started. Monitoring will run at specified times.")
|
||||||
while True:
|
while True:
|
||||||
schedule.run_pending()
|
schedule.run_pending()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Starting monitoring system...")
|
|
||||||
|
|
||||||
# 스케줄 설정
|
|
||||||
schedule.every().hour.at(":01").do(monitor_coins) # 매시 1분에 실행
|
|
||||||
schedule.every().day.at("17:20").do(monitor_us_stocks) # 매일 저녁 5시 20분에 실행
|
|
||||||
schedule.every().day.at("08:00").do(monitor_kr_stocks) # 매일 오전 8시에 실행
|
|
||||||
|
|
||||||
# 초기 실행
|
|
||||||
print("Running initial checks...")
|
|
||||||
monitor_coins()
|
|
||||||
monitor_us_stocks()
|
|
||||||
monitor_kr_stocks()
|
|
||||||
|
|
||||||
# 스케줄러 실행
|
|
||||||
print("Starting scheduler...")
|
|
||||||
run_schedule()
|
run_schedule()
|
||||||
|
|||||||
Reference in New Issue
Block a user