init
This commit is contained in:
67
monitor.py
67
monitor.py
@@ -227,18 +227,26 @@ class Monitor(HTS):
|
|||||||
# ------------- Strategy -------------
|
# ------------- Strategy -------------
|
||||||
def buy_sell_ticker_1h(self, symbol: str, data: pd.DataFrame, balances=None, is_inverse: bool = False) -> bool:
|
def buy_sell_ticker_1h(self, symbol: str, data: pd.DataFrame, balances=None, is_inverse: bool = False) -> bool:
|
||||||
try:
|
try:
|
||||||
|
# BUY_MINUTE_LIMIT 이내라면 매수하지 않음
|
||||||
|
current_time = datetime.now()
|
||||||
|
last_buy_dt = self.buy_cooldown.get(symbol, {}).get('buy', {}).get('datetime')
|
||||||
|
if last_buy_dt:
|
||||||
|
time_diff = current_time - last_buy_dt
|
||||||
|
if time_diff.total_seconds() < BUY_MINUTE_LIMIT:
|
||||||
|
print(f"{symbol}: 매수 금지 중 (남은 시간: {BUY_MINUTE_LIMIT - time_diff.total_seconds():.0f}초)")
|
||||||
|
return False
|
||||||
|
|
||||||
# 신호 생성 및 최신 포인트 확인
|
# 신호 생성 및 최신 포인트 확인
|
||||||
data = self.annotate_signals(symbol, data)
|
data = self.annotate_signals(symbol, data)
|
||||||
if data['point'].iloc[-1] != 1:
|
if data['point'].iloc[-1] != 1:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 인버스 데이터: 매수 신호를 매도로 처리 (fall_6p, deviation40 만 허용)
|
|
||||||
if is_inverse:
|
if is_inverse:
|
||||||
|
# 인버스 데이터: 매수 신호를 매도로 처리 (fall_6p, deviation40 만 허용)
|
||||||
# 허용된 인버스 매도 신호만 처리
|
# 허용된 인버스 매도 신호만 처리
|
||||||
last_signal = str(data['signal'].iloc[-1]) if 'signal' in data.columns else ''
|
last_signal = str(data['signal'].iloc[-1]) if 'signal' in data.columns else ''
|
||||||
if last_signal not in ['fall_6p', 'deviation40']:
|
if last_signal not in ['fall_6p', 'deviation40']:
|
||||||
return False
|
return False
|
||||||
current_time = datetime.now()
|
|
||||||
available_balance = 0
|
available_balance = 0
|
||||||
try:
|
try:
|
||||||
if balances and symbol in balances:
|
if balances and symbol in balances:
|
||||||
@@ -260,10 +268,11 @@ class Monitor(HTS):
|
|||||||
self.sendMsg("[KRW-COIN]\n" + f"• 매도 [COIN] {KR_COINS[symbol]} ({symbol}): {data['signal'].iloc[-1]} ({'₩'}{data['Close'].iloc[-1]:.4f})")
|
self.sendMsg("[KRW-COIN]\n" + f"• 매도 [COIN] {KR_COINS[symbol]} ({symbol}): {data['signal'].iloc[-1]} ({'₩'}{data['Close'].iloc[-1]:.4f})")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
else:
|
||||||
check_5_week_lowest = False
|
check_5_week_lowest = False
|
||||||
|
|
||||||
# 5주봉이 20주봉이나 40주봉보다 아래에 있는지 체크
|
|
||||||
try:
|
try:
|
||||||
|
# 5주봉이 20주봉이나 40주봉보다 아래에 있는지 체크
|
||||||
# Convert hourly data to week-based rolling periods (5, 20, 40 weeks)
|
# Convert hourly data to week-based rolling periods (5, 20, 40 weeks)
|
||||||
hours_in_week = 24 * 7 # 168 hours
|
hours_in_week = 24 * 7 # 168 hours
|
||||||
period_5w = 5 * hours_in_week # 840 hours
|
period_5w = 5 * hours_in_week # 840 hours
|
||||||
@@ -283,63 +292,41 @@ class Monitor(HTS):
|
|||||||
# Ignore errors in MA calculation so as not to block trading logic
|
# Ignore errors in MA calculation so as not to block trading logic
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# 체크: fall_6p
|
||||||
buy_amount = 5100
|
buy_amount = 5100
|
||||||
current_time = datetime.now()
|
current_time = datetime.now()
|
||||||
if data['signal'].iloc[-1] == 'fall_6p':
|
if data['signal'].iloc[-1] == 'fall_6p':
|
||||||
if data['Close'].iloc[-1] > 100:
|
if data['Close'].iloc[-1] > 100:
|
||||||
buy_amount = 600000
|
|
||||||
else:
|
|
||||||
buy_amount = 300000
|
buy_amount = 300000
|
||||||
|
|
||||||
last_buy_dt = self.buy_cooldown.get(symbol, {}).get('buy', {}).get('datetime')
|
|
||||||
if last_buy_dt and self.last_signal.get(symbol) == 'fall_6p':
|
|
||||||
time_diff = current_time - last_buy_dt
|
|
||||||
if time_diff.total_seconds() < 4000:
|
|
||||||
print(f"{symbol}: 매수 금지 중 (남은 시간: {600 - time_diff.total_seconds():.0f}초)")
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
last_buy_dt = self.buy_cooldown.get(symbol, {}).get('buy', {}).get('datetime')
|
|
||||||
if last_buy_dt:
|
|
||||||
time_diff = current_time - last_buy_dt
|
|
||||||
if time_diff.total_seconds() < BUY_MINUTE_LIMIT:
|
|
||||||
print(f"{symbol}: 매수 금지 중 (남은 시간: {BUY_MINUTE_LIMIT - time_diff.total_seconds():.0f}초)")
|
|
||||||
return False
|
|
||||||
|
|
||||||
if data['signal'].iloc[-1] == 'movingaverage':
|
|
||||||
buy_amount = 10000
|
|
||||||
elif data['signal'].iloc[-1] == 'deviation40':
|
|
||||||
buy_amount = 50000
|
|
||||||
elif data['signal'].iloc[-1] == 'deviation240':
|
|
||||||
buy_amount = 60000
|
|
||||||
elif data['signal'].iloc[-1] == 'deviation1440':
|
|
||||||
if symbol in ['BONK', 'PEPE', 'TON']:
|
|
||||||
buy_amount = 100000
|
|
||||||
else:
|
else:
|
||||||
buy_amount = 150000
|
buy_amount = 150000
|
||||||
|
elif data['signal'].iloc[-1] == 'movingaverage':
|
||||||
|
buy_amount = 10000
|
||||||
|
elif data['signal'].iloc[-1] == 'deviation40':
|
||||||
|
buy_amount = 30000
|
||||||
|
elif data['signal'].iloc[-1] == 'deviation240':
|
||||||
|
buy_amount = 7000
|
||||||
|
elif data['signal'].iloc[-1] == 'deviation1440':
|
||||||
|
if symbol in ['BONK', 'PEPE', 'TON']:
|
||||||
|
buy_amount = 50000
|
||||||
|
else:
|
||||||
|
buy_amount = 70000
|
||||||
|
|
||||||
if data['signal'].iloc[-1] in ['movingaverage', 'deviation40', 'deviation240', 'deviation1440']:
|
if data['signal'].iloc[-1] in ['movingaverage', 'deviation40', 'deviation240', 'deviation1440']:
|
||||||
if check_5_week_lowest:
|
if check_5_week_lowest:
|
||||||
buy_amount *= 2
|
buy_amount *= 2
|
||||||
|
|
||||||
"""
|
# 매수를 진행함
|
||||||
# 분봉 시스널이 없을 때는 이전 봉보다 높으면 60분 마다 매수
|
|
||||||
if data['point'].iloc[-1] != 1:
|
|
||||||
last_buy_dt = self.buy_cooldown.get(symbol, {}).get('buy', {}).get('datetime')
|
|
||||||
if last_buy_dt:
|
|
||||||
time_diff = current_time - last_buy_dt
|
|
||||||
if time_diff.total_seconds() < 3600:
|
|
||||||
print(f"{symbol}: 매수 금지 중 (남은 시간: {3600 - time_diff.total_seconds():.0f}초)")
|
|
||||||
return False
|
|
||||||
"""
|
|
||||||
buy_amount = self.hts.buyCoinMarket(symbol, buy_amount)
|
buy_amount = self.hts.buyCoinMarket(symbol, buy_amount)
|
||||||
|
|
||||||
if self.cooldown_file is not None:
|
|
||||||
# 최근 매수 신호를 함께 기록하여 [신규] 포맷으로 저장
|
# 최근 매수 신호를 함께 기록하여 [신규] 포맷으로 저장
|
||||||
|
if self.cooldown_file is not None:
|
||||||
try:
|
try:
|
||||||
self.last_signal[symbol] = str(data['signal'].iloc[-1])
|
self.last_signal[symbol] = str(data['signal'].iloc[-1])
|
||||||
except Exception:
|
except Exception:
|
||||||
self.last_signal[symbol] = ''
|
self.last_signal[symbol] = ''
|
||||||
self.buy_cooldown.setdefault(symbol, {})['buy'] = {'datetime': current_time, 'signal': str(data['signal'].iloc[-1])}
|
self.buy_cooldown.setdefault(symbol, {})['buy'] = {'datetime': current_time, 'signal': str(data['signal'].iloc[-1])}
|
||||||
|
|
||||||
# 매수를 저장함
|
# 매수를 저장함
|
||||||
self._save_buy_cooldown()
|
self._save_buy_cooldown()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user