This commit is contained in:
dsyoon
2023-01-18 01:35:51 +09:00
parent 327e234412
commit 602cbe2263
3 changed files with 40 additions and 66 deletions

View File

@@ -41,6 +41,7 @@ class HTS_DAILY (HTS):
# final_price가 0이고 diff가 None이면 장부가로 팔겠다는 의미임
sell_price = -1
orderNum = None
jangoDic = self.requstJango()
if jangoDic and len(jangoDic.keys()) > 0:
for code in jangoDic:
@@ -57,13 +58,26 @@ class HTS_DAILY (HTS):
if code == "A"+stock_code:
orderNum = self.requestOrder(OrderType.sell, stock_code, jangoDic[code]['매도가능'], sell_price)
print("ORDER_SELL", stock_code, log_time.strftime('%Y%m%d %H%M%S'), jangoDic[code]['매도가능'], sell_price)
return
return orderNum
def valid_company(self):
valid_company = set()
conn = sqlite3.connect(os.path.join(self.RESOURCE_PATH, "stock.db"))
cursor = conn.cursor()
cursor.execute('select CODE, NAME, max(ymd) as ymd from fnguide where type != "E" group by 1 order by total_assets desc limit 2400')
items = cursor.fetchall()
cursor.close()
conn.close()
for item in items:
valid_company.add(item[0])
return valid_company
def buyRealTime(self, today, n = 200):
print ("START...")
THIS_TIME = datetime.now()
valid_company = self.valid_company()
self.orderChecker.read(today)
while datetime.strptime(today + " 070000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 153100", '%Y%m%d %H%M%S'):
@@ -82,7 +96,7 @@ class HTS_DAILY (HTS):
for idx, item in enumerate(items):
stock_code = item[0]
stock_name = item[1]
if stock_name.find('스팩') >= 0 or re.search("\d.*?호", stock_name) is not None:
if stock_name.find('스팩') >= 0 or re.search("\d.*?호", stock_name) is not None and stock_code not in valid_company:
continue
print(idx, stock_code, stock_name, ", CODE: ", stock_code, ", NAME: ", stock_name)
@@ -99,7 +113,8 @@ class HTS_DAILY (HTS):
bsLine, data = self.buySellChecker.checkTransactionWithEnvelope(data, stock_code, self.analyzed_day, isRealTime=False)
if len(data.index) > 10 and max(bsLine['buy'][len(bsLine['buy']) - 2:]) > 0 and not self.orderChecker.exist(stock_code):
# 다음 조건이면 매수한다.
if len(data.index) > 10 and max(bsLine['buy'][len(bsLine['buy']) - 2:]) > 1000 and not self.orderChecker.exist(stock_code):
last_index = len(bsLine['buy'])-1
if bsLine['buy'][last_index] > 0:
bs_buy_price = bsLine['buy'][last_index]
@@ -113,6 +128,16 @@ class HTS_DAILY (HTS):
# 로그 출력
print("BUY", THIS_TIME.strftime('%Y%m%d %H%M%S'), orderNum, stock_code, stock_name, bs_buy_price, buy_count)
# 다음 조건이면 매도한다.
if len(data.index) > 10 and max(bsLine['sell'][len(bsLine['sell']) - 2:]) > 0:
last_index = len(bsLine['sell']) - 1
if bsLine['sell'][last_index] > 0:
bs_sell_price = bsLine['sell'][last_index]
orderNum = self.getSellingPrice(THIS_TIME, self.stock_code, bs_sell_price)
# 로그 출력
print("SELL", THIS_TIME.strftime('%Y%m%d %H%M%S'), orderNum, stock_code, stock_name, bs_sell_price)
THIS_TIME = datetime.now()
return