This commit is contained in:
dsyoon
2025-08-24 15:46:44 +09:00
parent 840675da5a
commit 70b29aeaac
8 changed files with 82 additions and 82 deletions

View File

@@ -24,60 +24,60 @@ RESISTANCE_LOOKBACK = 120 # 저항선 판단을 위한 과거 캔들 수 (예:
RESISTANCE_BREAK_THRESHOLD = 0.01 # 저항선 대비 1% 이상 돌파 시 신호 RESISTANCE_BREAK_THRESHOLD = 0.01 # 저항선 대비 1% 이상 돌파 시 신호
KR_COINS = { KR_COINS = {
"ADA": "ADA", "ADA": "에이다",
"APE": "ApeCoin", "APE": "에이프코인",
"ARB": "Arbitrum", "APT": "앱토스",
"BONK": "BONK", "ARB": "아비트럼",
"ENA": "ETHENA", "BONK": "봉크",
"HBAR": "HBAR", "ENA": "에테나",
"KAIA": "KAIA", "HBAR": "헤데라",
"LINK": "Chainlink", "KAIA": "카이아",
"ONDO": "ONDO", "LINK": "체인링크",
"PENGU": "Pudgy Penguins", "ONDO": "온도파이낸스",
"PEPE": "PEPE", "PENGU": "펏지 펭귄",
"POL": "POL", "PEPE": "페페",
"SAND": "Sandbox", "POL": "폴리곤 에코시스템 토큰",
"SEI": "SEI", "SEI": "세이",
"SHIB": "Shiba Inu", "SHIB": "시바이누",
"STORJ": "Storj", "STORJ": "스토리지",
"SUI": "Sui Network", "SUI": "수이",
"TON": "Toncoin", "TON": "톤코인",
"TRX": "TRON", "TRX": "트론",
"UXLINK": "UXLINK", "UXLINK": "유엑스링크",
"VIRTUAL": "Virtuals Protocol", "VIRTUAL": "버추얼 프로토콜",
"WLD": "Worldcoin", "WLD": "월드코인",
"XLM": "XLM", "XLM": "스텔라루멘",
"XRP": "XRP" "XRP": "엑스알피"
} }
KR_COINS_1 = { KR_COINS_1 = {
"ADA": "ADA", "ADA": "에이다",
"APE": "ApeCoin", "APE": "에이프코인",
"ARB": "Arbitrum", "APT": "앱토스",
"BONK": "BONK", "ARB": "아비트럼",
"ENA": "ETHENA", "BONK": "봉크",
"HBAR": "HBAR", "ENA": "에테나",
"KAIA": "KAIA", "HBAR": "헤데라",
"LINK": "Chainlink", "KAIA": "카이아",
"ONDO": "ONDO", "LINK": "체인링크",
"PENGU": "Pudgy Penguins", "ONDO": "온도파이낸스",
"PEPE": "PEPE", "PENGU": "펏지 펭귄",
"POL": "POL", "PEPE": "페페",
} }
KR_COINS_2 = { KR_COINS_2 = {
"SAND": "Sandbox", "POL": "폴리곤 에코시스템 토큰",
"SEI": "SEI", "SEI": "세이",
"SHIB": "Shiba Inu", "SHIB": "시바이누",
"STORJ": "Storj", "STORJ": "스토리지",
"SUI": "Sui Network", "SUI": "수이",
"TON": "Toncoin", "TON": "톤코인",
"TRX": "TRON", "TRX": "트론",
"UXLINK": "UXLINK", "UXLINK": "유엑스링크",
"VIRTUAL": "Virtuals Protocol", "VIRTUAL": "버추얼 프로토콜",
"WLD": "Worldcoin", "WLD": "월드코인",
"XLM": "XLM", "XLM": "스텔라루멘",
"XRP": "XRP" "XRP": "엑스알피"
} }
# 주식 설정 # 주식 설정

View File

@@ -12,9 +12,10 @@ def inserData(symbol, interval, data):
conn = sqlite3.connect('coins.db') conn = sqlite3.connect('coins.db')
cursor = conn.cursor() cursor = conn.cursor()
tableName = "{}_{}".format(symbol, str(interval))
# 테이블/키 생성 # 테이블/키 생성
cursor.execute("CREATE TABLE IF NOT EXISTS " + symbol + " (interval text, CODE text, NAME text, ymdhms datetime, ymd text, hms text, Close REAL, Open REAL, High REAL, Low REAL, Volume REAL)") cursor.execute("CREATE TABLE IF NOT EXISTS {} (CODE text, NAME text, ymdhms datetime, ymd text, hms text, Close REAL, Open REAL, High REAL, Low REAL, Volume REAL)".format(tableName))
cursor.execute("CREATE INDEX IF NOT EXISTS " + symbol + "_idx on " + symbol + "(interval, CODE, ymdhms)") cursor.execute("CREATE INDEX IF NOT EXISTS {}_idx on {}(CODE, ymdhms)".format(tableName, tableName))
for i in range(len(data)): for i in range(len(data)):
ymd = data.index[i].strftime('%Y%m%d') ymd = data.index[i].strftime('%Y%m%d')
@@ -26,12 +27,12 @@ def inserData(symbol, interval, data):
Close = data.Close.iloc[i] Close = data.Close.iloc[i]
Volume = data.Volume.iloc[i] Volume = data.Volume.iloc[i]
cursor.execute("SELECT * from " + symbol + " where CODE = ? and ymdhms = ? and interval = ?", (symbol, ymdhms, interval)) cursor.execute("SELECT * from {} where CODE = ? and ymdhms = ?".format(tableName), (symbol, ymdhms, ))
arr = cursor.fetchone() arr = cursor.fetchone()
if arr: if arr:
cursor.execute("UPDATE " + symbol + " SET Close=?, Open=?, High=?, Low=?, Volume=? where CODE=? and ymdhms=? and interval=?", (Close, Open, High, Low, Volume, symbol, ymdhms, interval)) cursor.execute("UPDATE {} SET Close=?, Open=?, High=?, Low=?, Volume=? where CODE=? and ymdhms=?".format(tableName), (Close, Open, High, Low, Volume, symbol, ymdhms))
else: else:
cursor.execute("INSERT INTO " + symbol + " (interval, CODE, NAME, ymdhms, ymd, hms, Close, Open, High, Low, Volume) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (interval, symbol, KR_COINS[symbol], ymdhms, ymd, hms, Close, Open, High, Low, Volume)) cursor.execute("INSERT INTO {} (CODE, NAME, ymdhms, ymd, hms, Close, Open, High, Low, Volume) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)".format(tableName), (symbol, KR_COINS[symbol], ymdhms, ymd, hms, Close, Open, High, Low, Volume))
conn.commit() conn.commit()
cursor.close() cursor.close()
@@ -44,9 +45,16 @@ def download():
# 1시간 # 1시간
interval = 60 interval = 60
data = monitorCoin.get_coin_more_data(symbol, interval, bong_count=10000) data = monitorCoin.get_coin_more_data(symbol, interval, bong_count=10000)
if data is not None and not data.empty:
try:
inserData(symbol, interval, data)
except Exception as e:
print(f"Error processing data for {symbol}: {str(e)}")
# 5분
interval = 5
data = monitorCoin.get_coin_more_data(symbol, interval, bong_count=10000)
if data is not None and not data.empty: if data is not None and not data.empty:
try: try:
inserData(symbol, interval, data) inserData(symbol, interval, data)

View File

@@ -311,14 +311,14 @@ class Monitor:
pass pass
current_time = datetime.now() current_time = datetime.now()
if data['sell_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 = 500000 buy_amount = 500000
else: else:
buy_amount = 300000 buy_amount = 300000
if symbol in self.buy_cooldown and symbol in self.last_sell_signal: if symbol in self.buy_cooldown and symbol in self.last_signal:
if self.last_sell_signal[symbol] == 'fall_6p': if self.last_signal[symbol] == 'fall_6p':
time_diff = current_time - self.buy_cooldown[symbol] time_diff = current_time - self.buy_cooldown[symbol]
if time_diff.total_seconds() < 4000: if time_diff.total_seconds() < 4000:
print(f"{symbol}: 매수 금지 중 (남은 시간: {600 - time_diff.total_seconds():.0f}초)") print(f"{symbol}: 매수 금지 중 (남은 시간: {600 - time_diff.total_seconds():.0f}초)")
@@ -331,20 +331,20 @@ class Monitor:
return False return False
buy_amount = 5100 buy_amount = 5100
if data['sell_signal'].iloc[-1] == 'movingaverage': if data['signal'].iloc[-1] == 'movingaverage':
buy_amount = 30000 buy_amount = 30000
elif data['sell_signal'].iloc[-1] == 'deviation40': elif data['signal'].iloc[-1] == 'deviation40':
buy_amount = 50000 buy_amount = 50000
elif data['sell_signal'].iloc[-1] == 'deviation240': elif data['signal'].iloc[-1] == 'deviation240':
buy_amount = 6000 buy_amount = 6000
elif data['sell_signal'].iloc[-1] == 'deviation1440': elif data['signal'].iloc[-1] == 'deviation1440':
if symbol in ['BONK', 'PEPE', 'TON']: if symbol in ['BONK', 'PEPE', 'TON']:
buy_amount = 20000 buy_amount = 20000
else: else:
buy_amount = 30000 buy_amount = 30000
# heikin_ashi 조건 제거 완료 # heikin_ashi 조건 제거 완료
if data['sell_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 *= 4 buy_amount *= 4
@@ -353,14 +353,14 @@ class Monitor:
if self.cooldown_file is not None: if self.cooldown_file is not None:
# 최근 매수 신호를 함께 기록하여 [신규] 포맷으로 저장 # 최근 매수 신호를 함께 기록하여 [신규] 포맷으로 저장
try: try:
self.last_sell_signal[symbol] = str(data['sell_signal'].iloc[-1]) self.last_signal[symbol] = str(data['signal'].iloc[-1])
except Exception: except Exception:
self.last_sell_signal[symbol] = '' self.last_signal[symbol] = ''
self.buy_cooldown[symbol] = current_time self.buy_cooldown[symbol] = current_time
self._save_buy_cooldown() self._save_buy_cooldown()
print(f"{KR_COINS[symbol]} ({symbol}) [{data['sell_signal'].iloc[-1]}], 현재가: {data['Close'].iloc[-1]:.4f}, 20분간 매수 금지 시작") print(f"{KR_COINS[symbol]} ({symbol}) [{data['signal'].iloc[-1]}], 현재가: {data['Close'].iloc[-1]:.4f}, 20분간 매수 금지 시작")
self.sendMsg("[KRW-COIN]" + "\n" + self.format_message('COIN', symbol, KR_COINS[symbol], data['Close'].iloc[-1], data['sell_signal'].iloc[-1])) self.sendMsg("[KRW-COIN]" + "\n" + self.format_message('COIN', symbol, KR_COINS[symbol], data['Close'].iloc[-1], data['signal'].iloc[-1]))
except Exception as e: except Exception as e:
print(f"Error buying {symbol}: {str(e)}") print(f"Error buying {symbol}: {str(e)}")
return False return False
@@ -521,16 +521,12 @@ class Monitor:
conn = sqlite3.connect('coins.db') conn = sqlite3.connect('coins.db')
cursor = conn.cursor() cursor = conn.cursor()
for i in range(1, len(data)): for i in range(1, len(data)):
cursor.execute( cursor.execute("SELECT * from {}_{} where CODE = ? and ymdhms = ?".format(symbol, str(interval)), (symbol, data['datetime'].iloc[-i].strftime('%Y-%m-%d %H:%M:%S')),)
"SELECT * from " + symbol + " where CODE = ? and ymdhms = ? and interval = ?",
(symbol, data['datetime'].iloc[-i].strftime('%Y-%m-%d %H:%M:%S'), interval),
)
arr = cursor.fetchone() arr = cursor.fetchone()
if not arr: if not arr:
cursor.execute( cursor.execute(
"INSERT INTO " + symbol + " (interval, CODE, NAME, ymdhms, ymd, hms, close, open, high, low, volume) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", "INSERT INTO {}_{} (CODE, NAME, ymdhms, ymd, hms, close, open, high, low, volume) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)".format(symbol, interval),
( (
interval,
symbol, symbol,
KR_COINS[symbol], KR_COINS[symbol],
data['datetime'].iloc[-i].strftime('%Y-%m-%d %H:%M:%S'), data['datetime'].iloc[-i].strftime('%Y-%m-%d %H:%M:%S'),
@@ -545,11 +541,7 @@ class Monitor:
) )
else: else:
break break
cursor.execute( cursor.execute("select * from (SELECT Open,Close,High,Low,Volume,ymdhms as datetime from {}_{} order by ymdhms desc limit 7000) subquery order by datetime".format(symbol, str(interval)))
"select * from (SELECT Open,Close,High,Low,Volume,ymdhms as datetime from "
+ symbol
+ " order by ymdhms desc limit 7000) subquery order by datetime"
)
result = cursor.fetchall() result = cursor.fetchall()
conn.commit() conn.commit()
cursor.close() cursor.close()

View File

@@ -2,7 +2,7 @@ from datetime import datetime
import time import time
from config import * from config import *
from monitor_1h import Monitor from monitor import Monitor
class MonitorCoin (Monitor): class MonitorCoin (Monitor):
"""자산(코인/주식/ETF) 모니터링 및 매수 실행 클래스""" """자산(코인/주식/ETF) 모니터링 및 매수 실행 클래스"""

View File

@@ -2,7 +2,7 @@ from datetime import datetime
import time import time
from config import * from config import *
from monitor_1h import Monitor from monitor import Monitor
class MonitorCoin (Monitor): class MonitorCoin (Monitor):
"""자산(코인/주식/ETF) 모니터링 및 매수 실행 클래스""" """자산(코인/주식/ETF) 모니터링 및 매수 실행 클래스"""

View File

@@ -2,7 +2,7 @@ from datetime import datetime
import time import time
from config import * from config import *
from monitor_1h import Monitor from monitor import Monitor
class MonitorCoin (Monitor): class MonitorCoin (Monitor):
"""자산(코인/주식/ETF) 모니터링 및 매수 실행 클래스""" """자산(코인/주식/ETF) 모니터링 및 매수 실행 클래스"""

View File

@@ -5,7 +5,7 @@ import schedule
from config import * from config import *
import FinanceDataReader as fdr import FinanceDataReader as fdr
from monitor_1h import Monitor from monitor import Monitor
class MonitorStock (Monitor): class MonitorStock (Monitor):
"""자산(코인/주식/ETF) 모니터링 및 매수 실행 클래스""" """자산(코인/주식/ETF) 모니터링 및 매수 실행 클래스"""

View File

@@ -9,7 +9,7 @@ plt.rcParams['font.family'] ='AppleGothic'
plt.rcParams['axes.unicode_minus'] =False plt.rcParams['axes.unicode_minus'] =False
from config import * from config import *
from monitor_1h import Monitor from monitor import Monitor
class Simulation: class Simulation: