init
This commit is contained in:
29
monitor.py
29
monitor.py
@@ -151,6 +151,29 @@ class Monitor:
|
||||
# ------------- Strategy -------------
|
||||
def buy_ticker(self, symbol: str, data: pd.DataFrame) -> bool:
|
||||
try:
|
||||
check_5_week_lowest = False
|
||||
|
||||
# 5주봉이 20주봉이나 40주봉보다 아래에 있는지 체크
|
||||
try:
|
||||
# Convert hourly data to week-based rolling periods (5, 20, 40 weeks)
|
||||
hours_in_week = 24 * 7 # 168 hours
|
||||
period_5w = 5 * hours_in_week # 840 hours
|
||||
period_20w = 20 * hours_in_week # 3,360 hours
|
||||
period_40w = 40 * hours_in_week # 6,720 hours
|
||||
|
||||
if len(data) >= period_40w:
|
||||
wma5 = data['Close'].rolling(window=period_5w).mean().iloc[-1]
|
||||
wma20 = data['Close'].rolling(window=period_20w).mean().iloc[-1]
|
||||
wma40 = data['Close'].rolling(window=period_40w).mean().iloc[-1]
|
||||
|
||||
# 5-week MA is the lowest among 5, 20, 40 week MAs
|
||||
if (wma5 < wma20) and (wma5 < wma40):
|
||||
check_5_week_lowest = True
|
||||
|
||||
except Exception:
|
||||
# Ignore errors in MA calculation so as not to block trading logic
|
||||
pass
|
||||
|
||||
current_time = datetime.now()
|
||||
if data['buy_signal'].iloc[-1] == 'fall_6p':
|
||||
if data['Close'].iloc[-1] > 100:
|
||||
@@ -184,6 +207,10 @@ class Monitor:
|
||||
else:
|
||||
buy_amount = 50000
|
||||
|
||||
if data['buy_signal'].iloc[-1] in ['movingaverage', 'deviation40', 'deviation240', 'deviation1440']:
|
||||
if check_5_week_lowest:
|
||||
buy_amount *= 2
|
||||
|
||||
_ = self.hts.buyCoinMarket(symbol, buy_amount)
|
||||
|
||||
if self.cooldown_file is not None:
|
||||
@@ -390,7 +417,7 @@ class Monitor:
|
||||
cursor.execute(
|
||||
"select * from (SELECT Open,Close,High,Low,Volume,ymdhms as datetime from "
|
||||
+ symbol
|
||||
+ " order by ymdhms desc limit 5000) subquery order by datetime"
|
||||
+ " order by ymdhms desc limit 7000) subquery order by datetime"
|
||||
)
|
||||
result = cursor.fetchall()
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user