init
This commit is contained in:
84
hts/HTS.py
84
hts/HTS.py
@@ -987,12 +987,35 @@ class HTS:
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def getSellingPrice(self, final_price):
|
||||||
|
# 만약 잔고가 있으면 장부가보다 5원 높게 매도한다.
|
||||||
|
jangoDic = self.requstJango()
|
||||||
|
if jangoDic and len(jangoDic.keys()) > 0:
|
||||||
|
for code in jangoDic:
|
||||||
|
if jangoDic[code]['매도가능'] > 0:
|
||||||
|
if final_price > jangoDic[code]['장부가'] + 5:
|
||||||
|
return jangoDic[code]['매도가능'], final_price
|
||||||
|
else:
|
||||||
|
# 장부가 가격의 마지막 자리를 0으로 만든다. (2090 -> 2090, 2092 -> 2090, 2098 -> 2090)
|
||||||
|
sell_price = int(jangoDic[code]['장부가'] / 10) * 10
|
||||||
|
# 장부가의 마지막 자리수를 가져온다.
|
||||||
|
last_number = int(jangoDic[code]['장부가']) % 10
|
||||||
|
if last_number in [0, 1, 2]:
|
||||||
|
# 장부가의 마지막 자리수가 0,1,2 라면 (2090, 2091, 2092 -> 2095 에 매도)
|
||||||
|
return jangoDic[code]['매도가능'], sell_price + 5
|
||||||
|
elif last_number in [3, 4, 5, 6]:
|
||||||
|
# 장부가의 마지막 자리수가 3,4,5,6 라면 (2093, 2094, 2095, 2096 -> 2100 에 매도)
|
||||||
|
return jangoDic[code]['매도가능'], sell_price + 10
|
||||||
|
else:
|
||||||
|
# 장부가의 마지막 자리수가 7,8,9 라면 (2097, 2098, 2099 -> 2105 에 매도)
|
||||||
|
return jangoDic[code]['매도가능'], sell_price + 15
|
||||||
|
|
||||||
|
return 0, 0
|
||||||
|
|
||||||
def buyRealTime(self, stock_code, given_day):
|
def buyRealTime(self, stock_code, given_day):
|
||||||
PREVIOUS_PRICE = 0
|
PREVIOUS_PRICE = 0
|
||||||
BUY_COUNT = 130
|
BUY_COUNT = 130
|
||||||
|
|
||||||
logFp = open(given_day+".log", "w")
|
|
||||||
|
|
||||||
timecheckList = pd.read_csv("timecheck.csv").values.tolist()
|
timecheckList = pd.read_csv("timecheck.csv").values.tolist()
|
||||||
timecheck = {given_day + " " + str(second).zfill(6):False for second, check in timecheckList}
|
timecheck = {given_day + " " + str(second).zfill(6):False for second, check in timecheckList}
|
||||||
|
|
||||||
@@ -1004,7 +1027,6 @@ class HTS:
|
|||||||
"low": [],
|
"low": [],
|
||||||
"vol": []}
|
"vol": []}
|
||||||
|
|
||||||
TOTAL_BUY_AMT = 0
|
|
||||||
final_price = 0
|
final_price = 0
|
||||||
print ("START...")
|
print ("START...")
|
||||||
while datetime.strptime(given_day + " 070000", '%Y%m%d %H%M%S') < datetime.now() < datetime.strptime(given_day + " 15200", '%Y%m%d %H%M%S'):
|
while datetime.strptime(given_day + " 070000", '%Y%m%d %H%M%S') < datetime.now() < datetime.strptime(given_day + " 15200", '%Y%m%d %H%M%S'):
|
||||||
@@ -1014,8 +1036,6 @@ class HTS:
|
|||||||
if datetime.strptime(given_day + " 090100", '%Y%m%d %H%M%S') < datetime.now() < datetime.strptime(given_day + " 151500", '%Y%m%d %H%M%S'):
|
if datetime.strptime(given_day + " 090100", '%Y%m%d %H%M%S') < datetime.now() < datetime.strptime(given_day + " 151500", '%Y%m%d %H%M%S'):
|
||||||
if second in timecheck and not timecheck[second]:
|
if second in timecheck and not timecheck[second]:
|
||||||
print("TIMECHECK", second)
|
print("TIMECHECK", second)
|
||||||
logFp.write("%s,%s,\n" %("TIMECHECK", second))
|
|
||||||
logFp.flush()
|
|
||||||
|
|
||||||
# 데이터를 가지고 온다.
|
# 데이터를 가지고 온다.
|
||||||
self.getRealTime(stock_code, given_day, result)
|
self.getRealTime(stock_code, given_day, result)
|
||||||
@@ -1045,62 +1065,32 @@ class HTS:
|
|||||||
|
|
||||||
# 매수 주문
|
# 매수 주문
|
||||||
# 현재까지 매입금액이 7백만원 이하일 때만 매수를 한다.
|
# 현재까지 매입금액이 7백만원 이하일 때만 매수를 한다.
|
||||||
if TOTAL_BUY_AMT < 7000000:
|
self.requestOrder("2", stock_code, BUY_COUNT , bs_buy_price)
|
||||||
self.requestOrder("2", stock_code, BUY_COUNT , bs_buy_price)
|
print("BUY", second, bs_buy_price)
|
||||||
|
|
||||||
print("BUY", second, bs_buy_price)
|
|
||||||
logFp.write("%s,%s, %d\n" % ("BUY", second, bs_buy_price))
|
|
||||||
logFp.flush()
|
|
||||||
|
|
||||||
if bs_sell_price > 0:
|
if bs_sell_price > 0:
|
||||||
# 매도 전에 모든 미체결을 취소한다.
|
# 매도 전에 모든 미체결을 취소한다.
|
||||||
self.cancelOrderList()
|
self.cancelOrderList()
|
||||||
# 잔고 모든 항목을 매도한다.
|
# 매도 가격을 가져온다.
|
||||||
jangoDic = self.requstJango()
|
selling_count, selling_price = self.getSellingPrice(final_price)
|
||||||
if jangoDic and len(jangoDic.keys()) > 0:
|
# 분석되 가격으로 매도 요청한다.
|
||||||
|
if selling_count != 0 and selling_price != 0:
|
||||||
for code in jangoDic:
|
self.requestOrder("1", stock_code, selling_count, selling_price)
|
||||||
TOTAL_BUY_AMT = jangoDic[code]['매입금액']
|
|
||||||
if jangoDic[code]['매도가능'] > 0:
|
|
||||||
self.requestOrder("1", stock_code, jangoDic[code]['매도가능'], bs_sell_price)
|
|
||||||
|
|
||||||
timecheck[second] = True
|
timecheck[second] = True
|
||||||
else:
|
|
||||||
#print("NONE", second)
|
|
||||||
logFp.write("%s,%s,\n" % ("NONE", second))
|
|
||||||
logFp.flush()
|
|
||||||
|
|
||||||
if datetime.strptime(given_day + " 151500", '%Y%m%d %H%M%S') < datetime.now():
|
if datetime.strptime(given_day + " 151500", '%Y%m%d %H%M%S') < datetime.now():
|
||||||
# 15:15:00 이후라면 모든 미체결 취소
|
# 15:15:00 이후라면 모든 미체결 취소
|
||||||
self.cancelOrderList()
|
self.cancelOrderList()
|
||||||
|
# 매도 가격을 가져온다.
|
||||||
# 만약 잔고가 있으면 장부가보다 5원 높게 매도한다.
|
selling_count, selling_price = self.getSellingPrice(final_price)
|
||||||
jangoDic = self.requstJango()
|
# 분석되 가격으로 매도 요청한다.
|
||||||
if jangoDic and len(jangoDic.keys()) > 0:
|
if selling_count != 0 and selling_price !=0:
|
||||||
for code in jangoDic:
|
self.requestOrder("1", stock_code, selling_count, selling_price)
|
||||||
if jangoDic[code]['매도가능'] > 0:
|
|
||||||
|
|
||||||
if final_price > jangoDic[code]['장부가'] + 5:
|
|
||||||
self.requestOrder("1", stock_code, jangoDic[code]['매도가능'], final_price)
|
|
||||||
else:
|
|
||||||
# 장부가 가격의 마지막 자리를 0으로 만든다. (2090 -> 2090, 2092 -> 2090, 2098 -> 2090)
|
|
||||||
sell_price = int(jangoDic[code]['장부가'] / 10) * 10
|
|
||||||
# 장부가의 마지막 자리수를 가져온다.
|
|
||||||
last_number = int(jangoDic[code]['장부가']) % 10
|
|
||||||
if last_number in [0, 1, 2]:
|
|
||||||
# 장부가의 마지막 자리수가 0,1,2 라면 (2090, 2091, 2092 -> 2095 에 매도)
|
|
||||||
self.requestOrder("1", stock_code, jangoDic[code]['매도가능'], sell_price + 5)
|
|
||||||
elif last_number in [3, 4, 5, 6]:
|
|
||||||
# 장부가의 마지막 자리수가 3,4,5,6 라면 (2093, 2094, 2095, 2096 -> 2100 에 매도)
|
|
||||||
self.requestOrder("1", stock_code, jangoDic[code]['매도가능'], sell_price + 10)
|
|
||||||
else:
|
|
||||||
# 장부가의 마지막 자리수가 7,8,9 라면 (2097, 2098, 2099 -> 2105 에 매도)
|
|
||||||
self.requestOrder("1", stock_code, jangoDic[code]['매도가능'], sell_price + 15)
|
|
||||||
|
|
||||||
break
|
break
|
||||||
time.sleep(0.9)
|
time.sleep(0.9)
|
||||||
|
|
||||||
logFp.close()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -481,7 +481,8 @@ class Analyzer:
|
|||||||
result_3 = result[3]
|
result_3 = result[3]
|
||||||
if result[3] != result[3]:
|
if result[3] != result[3]:
|
||||||
result_3 = result[3].replace("NaN", "0")
|
result_3 = result[3].replace("NaN", "0")
|
||||||
if result[3]==None:
|
|
||||||
|
if result[3]==None or (result[2]=="[]" or result[3]=='' or result[4] == ''):
|
||||||
rowid += 1
|
rowid += 1
|
||||||
cursor.execute('SELECT CODE, NAME, PRICE, STOCHASTIC, BOLINGERBAND FROM ' + self.tableName + ' WHERE rowid=?', (rowid,))
|
cursor.execute('SELECT CODE, NAME, PRICE, STOCHASTIC, BOLINGERBAND FROM ' + self.tableName + ' WHERE rowid=?', (rowid,))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
|
|||||||
Reference in New Issue
Block a user