init
This commit is contained in:
@@ -31,12 +31,6 @@ class HTS_122630 (HTS):
|
||||
def checkTransaction(self, data):
|
||||
size = len(data["close"])
|
||||
|
||||
bsLine = {}
|
||||
bsLine['buy'] = [-1 for i in range(size)]
|
||||
bsLine['weight'] = [-1 for i in range(size)]
|
||||
bsLine['sell'] = [-1 for i in range(size)]
|
||||
|
||||
buy, weight, sell = -1, -1, -1
|
||||
last_index = size - 1
|
||||
sell, weight = self.buySellChecker.getSellPriceAndWeight_15000(data, last_index)
|
||||
buy, weight = self.buySellChecker.getBuyPriceAndWeight_15000(data, last_index)
|
||||
@@ -77,34 +71,41 @@ class HTS_122630 (HTS):
|
||||
|
||||
return 0, 0
|
||||
|
||||
def buyRealTime(self, lastday, today):
|
||||
def buyRealTime(self, today):
|
||||
|
||||
timecheckList = pd.read_csv("hts/timecheck.csv").values.tolist()
|
||||
timecheck = {today + " " + str(second).zfill(6):False for second, check in timecheckList}
|
||||
|
||||
print("START...")
|
||||
print ("START...")
|
||||
THIS_TIME = datetime.now()
|
||||
final_sell_check = False
|
||||
while datetime.strptime(today + " 070000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 153100",
|
||||
'%Y%m%d %H%M%S'):
|
||||
LAST_DATA = self.getLastData(self.stock_code, today)
|
||||
|
||||
while datetime.strptime(today + " 070000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 153100", '%Y%m%d %H%M%S'):
|
||||
|
||||
if datetime.strptime(today + " 090000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 151500", '%Y%m%d %H%M%S'):
|
||||
# 3시 까지만 매수를 시도한다.
|
||||
|
||||
if THIS_TIME.strftime('%Y%m%d %H%M%S') in timecheck and not timecheck[THIS_TIME.strftime('%Y%m%d %H%M%S')]:
|
||||
|
||||
# 데이터를 가지고 온다.
|
||||
result = self.getRealTime(self.stock_code, lastday, today)
|
||||
result = self.getRealTime(self.stock_code, today, LAST_DATA)
|
||||
|
||||
# 분석을 통해서 볼린저밴드 상/하단을 계산한다.
|
||||
data = self.buySellChecker.analyze(result)
|
||||
# 규칙 기반의 분석을 통해서 볼린저밴드 상/하단을 계산한다.
|
||||
data = self.buySellChecker.analyzeByRule(result)
|
||||
|
||||
# 사야 할 시점/가격과 팔아야 할 시점/가격을 체크한다.
|
||||
bs_buy_price, bs_weight, bs_sell_price = self.checkTransaction(data)
|
||||
bsLine, data = self.buySellChecker.checkTransaction(data, self.stock_code, True)
|
||||
bs_buy_price = bsLine['buy']
|
||||
bs_weight = bsLine['buy_weight']
|
||||
bs_sell_price = bsLine['sell']
|
||||
|
||||
data_size = len(data["close"])
|
||||
final_price = data["close"][data_size - 1]
|
||||
final_price = data["close"][data_size-1]
|
||||
|
||||
if bs_buy_price > 0:
|
||||
# 기본 100 주에 가중치를 추가해서 매수한다.
|
||||
#33BUY_COUNT = int(self.buy_count * bs_weight)
|
||||
BUY_COUNT = int(self.buy_count * 1)
|
||||
BUY_COUNT = int(self.buy_count * bs_weight)
|
||||
|
||||
# 매수를 주문한다.
|
||||
orderNum = self.requestOrder(OrderType.buy, self.stock_code, BUY_COUNT, bs_buy_price)
|
||||
@@ -118,6 +119,7 @@ class HTS_122630 (HTS):
|
||||
# 로그 출력
|
||||
print("BUY", THIS_TIME.strftime('%Y%m%d %H%M%S'), BUY_COUNT, bs_buy_price, len(orderListToCancel), len(ORDER_LIST))
|
||||
|
||||
|
||||
if bs_sell_price > 0:
|
||||
# 미체결 기록을 가져온다.
|
||||
ORDER_LIST = self.requestOrderList()
|
||||
@@ -136,9 +138,9 @@ class HTS_122630 (HTS):
|
||||
# 로그 출력
|
||||
print("SELL", THIS_TIME.strftime('%Y%m%d %H%M%S'), selling_count, selling_price, len(orderListToCancel), len(ORDER_LIST))
|
||||
|
||||
|
||||
# 로그 출력
|
||||
print(
|
||||
"TIMECHECK: %s, price: %d, open: %d, high: %d, low: %d, avg3: %.2f, avg5: %.2f, avg10: %.2f, avg20: %.2f, avg30: %.2f, avg60: %.2f,\n lower: %.2f, upper: %.2f, macd: %.2f, macds: %.2f, macdo: %.2f,\n rsi: %.2f, rsis: %.2f, fast_k: %.2f, slow_k: %.2f, slow_d: %.2f" %
|
||||
print("TIMECHECK: %s, price: %d, open: %d, high: %d, low: %d, avg3: %.2f, avg5: %.2f, avg10: %.2f, avg20: %.2f, avg30: %.2f, avg60: %.2f,\n lower: %.2f, upper: %.2f, macd: %.2f, macds: %.2f, macdo: %.2f,\n rsi: %.2f, rsis: %.2f, fast_k: %.2f, slow_k: %.2f, slow_d: %.2f" %
|
||||
(str(THIS_TIME), final_price, data["open"][data_size - 1], data["high"][data_size - 1],
|
||||
data["low"][data_size - 1],
|
||||
data["avg3"][data_size - 1], data["avg5"][data_size - 1], data["avg10"][data_size - 1],
|
||||
@@ -151,10 +153,11 @@ class HTS_122630 (HTS):
|
||||
timecheck[THIS_TIME] = True
|
||||
|
||||
elif datetime.strptime(today + " 151530", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 151600", '%Y%m%d %H%M%S'):
|
||||
# 3시 15분 30초부터 3시 16분 사이는 잔량을 매도한다.
|
||||
|
||||
if not final_sell_check:
|
||||
####
|
||||
# 손해 보지 않는 가격에 매도한다.
|
||||
# 손해봐도 매도한다.
|
||||
####
|
||||
|
||||
# 주문 리스트를 가져온다.
|
||||
@@ -163,9 +166,12 @@ class HTS_122630 (HTS):
|
||||
self.cancelOrderList(orderList)
|
||||
|
||||
# 매도 가격을 가져온다.
|
||||
result = self.getRealTime(self.stock_code, lastday, today)
|
||||
result = self.getRealTime(self.stock_code, today, LAST_DATA)
|
||||
final_price = result["close"][len(result["close"]) - 1]
|
||||
|
||||
selling_count, selling_price = self.getFinalSellingPrice(final_price)
|
||||
# selling_count, selling_price = self.getSellingPrice(final_price)
|
||||
|
||||
# 분석되 가격으로 매도 요청한다.
|
||||
if selling_count != 0 and selling_price != 0:
|
||||
orderNum = self.requestOrder(OrderType.sell, self.stock_code, selling_count, selling_price)
|
||||
@@ -193,15 +199,8 @@ if __name__ == "__main__":
|
||||
|
||||
hts = HTS_122630(RESOURCE_PATH, stock_code, buy_count)
|
||||
today_str = today.strftime('%Y%m%d')
|
||||
lastday_str = ""
|
||||
for i in range(1, 10):
|
||||
lastday_str = (today - timedelta(i)).strftime('%Y%m%d')
|
||||
last_hts_data_filename = os.path.join(RESOURCE_PATH, "hts", stock_code + "_" + lastday_str + ".csv")
|
||||
if os.path.isfile(last_hts_data_filename):
|
||||
break
|
||||
|
||||
hts.buyRealTime(lastday_str, today_str)
|
||||
#hts.writeStockData(stock_code, today_str)
|
||||
hts.buyRealTime(today_str)
|
||||
|
||||
db_filename = os.path.join(RESOURCE_PATH, "hts.db")
|
||||
hts.insertStockData(db_filename, stock_code, stock_name, today_str)
|
||||
|
||||
Reference in New Issue
Block a user