This commit is contained in:
dsyoon
2025-08-06 15:38:59 +09:00
parent 1027e72c01
commit d7517cf578
2 changed files with 15 additions and 31 deletions

View File

@@ -14,8 +14,6 @@ import FinanceDataReader as fdr
import numpy as np import numpy as np
hts = HTS() hts = HTS()
BUY_AMOUNT = 10000
def send_coin_msg(text): def send_coin_msg(text):
coin_client = telegram.Bot(token=COIN_TELEGRAM_BOT_TOKEN) coin_client = telegram.Bot(token=COIN_TELEGRAM_BOT_TOKEN)
@@ -39,8 +37,13 @@ def send_coin_telegram_message(message_list, header):
return return
def buy_ticker(symbole): def buy_ticker(symbole, data):
try: try:
BUY_AMOUNT = 5000
if data['buy_signal'].iloc[-1] == 'moving average':
BUY_AMOUNT = 10000
_ = hts.buyCoinMarket(symbole, BUY_AMOUNT) _ = hts.buyCoinMarket(symbole, BUY_AMOUNT)
except Exception as e: except Exception as e:
print(f"Error buying {symbole}: {str(e)}") print(f"Error buying {symbole}: {str(e)}")
@@ -150,6 +153,7 @@ def check_buy_point(data, simulation=None):
# 매수 포인트 탐지 및 표시 # 매수 포인트 탐지 및 표시
# 'buy_point' 열 초기화 # 'buy_point' 열 초기화
data['buy_signal'] = ''
data['buy_point'] = 0 data['buy_point'] = 0
# FutureWarning 해결 # 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 \ 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 \ 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['MA720'].iloc[i] < data['MA1440'].iloc[i]:
data.at[data.index[i], 'buy_signal'] = 'moving average'
data.at[data.index[i], 'buy_point'] = 1 data.at[data.index[i], 'buy_point'] = 1
if not simulation: if not simulation:
@@ -167,8 +172,8 @@ def check_buy_point(data, simulation=None):
return data return data
def format_message(market_type, symbol, symbol_name, close): def format_message(market_type, symbol, symbol_name, close, buy_signal):
message = f"매수 [{market_type}] {symbol_name} ({symbol}) " message = f"매수 [{market_type}] {symbol_name} ({symbol}): {buy_signal} "
message += f"현재가: {'$' if market_type == 'US' else ''}{close:.2f}, " message += f"현재가: {'$' if market_type == 'US' else ''}{close:.2f}, "
return message return message
@@ -291,7 +296,7 @@ def monitor_us_stocks():
if recent_data['buy_point'].iloc[-1] != 1: if recent_data['buy_point'].iloc[-1] != 1:
continue continue
print(f" - {US_STOCKS[symbol]} ({symbol}): {recent_data['Close'][-1]:.2f}") 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: except Exception as e:
print(f"Error processing data for {symbol}: {str(e)}") print(f"Error processing data for {symbol}: {str(e)}")
time.sleep(0.5) time.sleep(0.5)
@@ -362,10 +367,10 @@ def monitor_coins():
if recent_data['buy_point'].iloc[-1] != 1: if recent_data['buy_point'].iloc[-1] != 1:
continue continue
print(f" - {KR_ETFS[symbol]} ({symbol}): {recent_data['Close'][-1]:.2f}") 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
buy_ticker(symbol) buy_ticker(symbol, recent_data)
except Exception as e: except Exception as e:
print(f"Error processing data for {symbol}: {str(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.") print(f"Data for {symbol} is empty or None.")
time.sleep(0.5) 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: if len(message_list) > 0:
try: try:
# send message # send message

View File

@@ -227,8 +227,8 @@ def run_simulation(symbol: str, interval_minutes: int, days: int = 30):
if __name__ == "__main__": if __name__ == "__main__":
interval = 60 interval = 60
days = 90 # 분석 기간을 90일로 늘림 (6월~8월 데이터 포함) 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 = ['ADA','APE','ARB','BONK','HBAR','LINK','ONDO','PEPE','SEI','SHIB','STORJ','SUI','TON','TRX','WLD','XLM','XRP']
#target_coins = ['APE'] target_coins = ['APE']
for symbol in target_coins: for symbol in target_coins:
print(f"\n=== {symbol} 저점 기간 분석 시작 ===") print(f"\n=== {symbol} 저점 기간 분석 시작 ===")