init
This commit is contained in:
6
HTS2.py
6
HTS2.py
@@ -10,9 +10,9 @@ from urllib.parse import urlencode
|
|||||||
class HTS:
|
class HTS:
|
||||||
|
|
||||||
bithumb = None
|
bithumb = None
|
||||||
accessKey = None
|
accessKey = "a5d33ce55f598185d37cd26272341b7b965c31a59457f7" # 본인의 Connect Key를 입력한다.
|
||||||
secretKey = None
|
secretKey = "ODBiYWFmNWE2MTkwYjdhMTNhZTM1YjU5OGY4OGE2MGNkNDY2NzMzMjE2Nzc5NDVlMzBhMDk3NTNmM2M2Mg==" # 본인의 Secret Key를 입력한다.
|
||||||
apiUrl = None
|
apiUrl = 'https://api.bithumb.com'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
#self.bithumb = pybithumb.Bithumb(self.con_key, self.sec_key)
|
#self.bithumb = pybithumb.Bithumb(self.con_key, self.sec_key)
|
||||||
|
|||||||
12
monitor.py
12
monitor.py
@@ -9,13 +9,14 @@ import requests
|
|||||||
import json
|
import json
|
||||||
import asyncio
|
import asyncio
|
||||||
from multiprocessing import Pool
|
from multiprocessing import Pool
|
||||||
from config import *
|
|
||||||
import FinanceDataReader as fdr
|
import FinanceDataReader as fdr
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from config import *
|
||||||
|
from HTS2 import HTS
|
||||||
|
|
||||||
class Monitor:
|
class Monitor(HTS):
|
||||||
"""자산(코인/주식/ETF) 모니터링 및 매수 실행 클래스"""
|
"""자산(코인/주식/ETF) 모니터링 및 매수 실행 클래스"""
|
||||||
|
|
||||||
last_signal = None
|
last_signal = None
|
||||||
@@ -224,7 +225,7 @@ class Monitor:
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
# ------------- Strategy -------------
|
# ------------- Strategy -------------
|
||||||
def buy_ticker(self, symbol: str, data: pd.DataFrame) -> bool:
|
def buy_ticker_1h(self, symbol: str, data: pd.DataFrame) -> bool:
|
||||||
try:
|
try:
|
||||||
# 기존 로직 ---------------------------------------------------
|
# 기존 로직 ---------------------------------------------------
|
||||||
#print('BUY: {}'.format(symbol))
|
#print('BUY: {}'.format(symbol))
|
||||||
@@ -253,6 +254,7 @@ class Monitor:
|
|||||||
# 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
|
||||||
|
|
||||||
|
buy_amount = 6000
|
||||||
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:
|
||||||
@@ -311,7 +313,7 @@ class Monitor:
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def sell_ticker(self, symbol: str, data: pd.DataFrame) -> bool:
|
def sell_ticker_1h(self, symbol: str, data: pd.DataFrame, balances) -> bool:
|
||||||
"""Dev40(Deviation40) 매도 조건을 만족할 때만 매도 실행"""
|
"""Dev40(Deviation40) 매도 조건을 만족할 때만 매도 실행"""
|
||||||
try:
|
try:
|
||||||
# 최신 캔들의 시그널이 Dev40이 아니면 매도하지 않음
|
# 최신 캔들의 시그널이 Dev40이 아니면 매도하지 않음
|
||||||
@@ -330,7 +332,7 @@ class Monitor:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# 매도 수량/금액 산정 (예: 50,000 KRW 상당)
|
# 매도 수량/금액 산정 (예: 50,000 KRW 상당)
|
||||||
sell_amount = 50000 # KRW 기준 매도 총액 혹은 수량 설정
|
sell_amount = balances[symbol]['balance'] * 0.7 # KRW 기준 매도 총액 혹은 수량 설정
|
||||||
|
|
||||||
# 실제 매도 실행 (HTS API)
|
# 실제 매도 실행 (HTS API)
|
||||||
_ = self.hts.sellCoinMarket(symbol, 0, sell_amount) # market 매도 (price 파라미터 미사용)
|
_ = self.hts.sellCoinMarket(symbol, 0, sell_amount) # market 매도 (price 파라미터 미사용)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class MonitorCoin (Monitor):
|
|||||||
recent_inverseData = self.check_point(symbol, inverseData)
|
recent_inverseData = self.check_point(symbol, inverseData)
|
||||||
if recent_inverseData['point'].iloc[-1] != 1:
|
if recent_inverseData['point'].iloc[-1] != 1:
|
||||||
continue
|
continue
|
||||||
sell_success = self.sell_ticker(symbol, recent_inverseData)
|
sell_success = self.sell_ticker_1h(symbol, recent_inverseData)
|
||||||
if not sell_success:
|
if not sell_success:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ class MonitorCoin (Monitor):
|
|||||||
|
|
||||||
if recent_data['point'].iloc[-1] != 1:
|
if recent_data['point'].iloc[-1] != 1:
|
||||||
continue
|
continue
|
||||||
buy_success = self.buy_ticker(symbol, recent_data)
|
buy_success = self.buy_ticker_1h(symbol, recent_data)
|
||||||
if not buy_success:
|
if not buy_success:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,13 @@ class MonitorCoin (Monitor):
|
|||||||
super().__init__(cooldown_file)
|
super().__init__(cooldown_file)
|
||||||
|
|
||||||
def monitor_coins(self) -> None:
|
def monitor_coins(self) -> None:
|
||||||
|
tmps = self.getBalances()
|
||||||
|
balances = {}
|
||||||
|
for tmp in tmps:
|
||||||
|
balances[tmp['currency']] = {'balance': float(tmp['balance']), 'avg_buy_price': float(tmp['avg_buy_price'])}
|
||||||
|
|
||||||
for symbol in KR_COINS_1:
|
for symbol in KR_COINS_1:
|
||||||
|
|
||||||
print("[{}] {}".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S'), symbol))
|
print("[{}] {}".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S'), symbol))
|
||||||
interval = 60
|
interval = 60
|
||||||
data = self.get_coin_some_data(symbol, interval)
|
data = self.get_coin_some_data(symbol, interval)
|
||||||
@@ -21,7 +27,7 @@ class MonitorCoin (Monitor):
|
|||||||
recent_inverseData = self.check_point(symbol, inverseData)
|
recent_inverseData = self.check_point(symbol, inverseData)
|
||||||
if recent_inverseData['point'].iloc[-1] != 1:
|
if recent_inverseData['point'].iloc[-1] != 1:
|
||||||
continue
|
continue
|
||||||
sell_success = self.sell_ticker(symbol, recent_inverseData)
|
sell_success = self.sell_ticker_1h(symbol, recent_inverseData, balances)
|
||||||
if not sell_success:
|
if not sell_success:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -29,7 +35,7 @@ class MonitorCoin (Monitor):
|
|||||||
recent_data = self.check_point(symbol, data)
|
recent_data = self.check_point(symbol, data)
|
||||||
if recent_data['point'].iloc[-1] != 1:
|
if recent_data['point'].iloc[-1] != 1:
|
||||||
continue
|
continue
|
||||||
buy_success = self.buy_ticker(symbol, recent_data)
|
buy_success = self.buy_ticker_1h(symbol, recent_data)
|
||||||
if not buy_success:
|
if not buy_success:
|
||||||
continue
|
continue
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class MonitorCoin (Monitor):
|
|||||||
recent_inverseData = self.check_point(symbol, inverseData)
|
recent_inverseData = self.check_point(symbol, inverseData)
|
||||||
if recent_inverseData['point'].iloc[-1] != 1:
|
if recent_inverseData['point'].iloc[-1] != 1:
|
||||||
continue
|
continue
|
||||||
sell_success = self.sell_ticker(symbol, recent_inverseData)
|
sell_success = self.sell_ticker_1h(symbol, recent_inverseData)
|
||||||
if not sell_success:
|
if not sell_success:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ class MonitorCoin (Monitor):
|
|||||||
recent_data = self.check_point(symbol, data)
|
recent_data = self.check_point(symbol, data)
|
||||||
if recent_data['point'].iloc[-1] != 1:
|
if recent_data['point'].iloc[-1] != 1:
|
||||||
continue
|
continue
|
||||||
buy_success = self.buy_ticker(symbol, recent_data)
|
buy_success = self.buy_ticker_1h(symbol, recent_data)
|
||||||
if not buy_success:
|
if not buy_success:
|
||||||
continue
|
continue
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user