This commit is contained in:
dsyoon
2023-03-06 00:27:45 +09:00
parent e85274bdc6
commit 97295eaf61

View File

@@ -1,5 +1,6 @@
import time
import os
import math
import sqlite3
from datetime import datetime, timedelta
@@ -120,17 +121,6 @@ class HTS_etf (HTS):
return result
def getCount(self, stock_code, price, data=None):
MAX_BUY_PRICE = 50000
if stock_code == "252670" or stock_code == "122630":
if data['slow_k'][-2] < data['slow_k'][-1] < 40:
MAX_BUY_PRICE = 200000
if data['slow_k'][-2] < data['slow_k'][-1] < 20:
MAX_BUY_PRICE = 300000
count = int(MAX_BUY_PRICE / price)
return count
def getSlowK(self, stock_code):
slow_k, p_slow_k, slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month = -1, -1, -1, -1, -1, -1
@@ -176,20 +166,55 @@ class HTS_etf (HTS):
return slow_k, p_slow_k, slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month
def getBuyCount(self, stock_code, bs_buy_price, slow_k_kospi, p_slow_k_kospi, slow_k_week_kospi, p_slow_k_week_kospi, slow_k_month_kospi, p_slow_k_month_kospi):
base_price = 10000
# kospi 상태 파악
type_kospi = {'day':1, 'week':1, 'month':1}
if slow_k_kospi < p_slow_k_kospi:
if slow_k_kospi < 20: type_kospi['day'] = 4
if 20 < slow_k_kospi < 30: type_kospi['day'] = 3
if 30 < slow_k_kospi < 40: type_kospi['day'] = 2
if slow_k_week_kospi < p_slow_k_week_kospi:
if slow_k_week_kospi < 20: type_kospi['week'] = 4
if 20 < slow_k_week_kospi < 30: type_kospi['week'] = 3
if 30 < slow_k_week_kospi < 40: type_kospi['week'] = 2
if slow_k_month_kospi < p_slow_k_month_kospi:
if slow_k_month_kospi < 20: type_kospi['month'] = 4
if 20 < slow_k_month_kospi < 30: type_kospi['month'] = 3
if 30 < slow_k_month_kospi < 40: type_kospi['month'] = 2
type_stock = {'day':1, 'week':1, 'month':1}
slow_k, p_slow_k, slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month = self.getSlowK(stock_code)
if slow_k < p_slow_k:
if slow_k < 20: type_stock['day'] = 4
if 20 < slow_k < 30: type_stock['day'] = 3
if 30 < slow_k < 40: type_stock['day'] = 2
if slow_k_week < p_slow_k_week:
if slow_k_week < 20: type_stock['week'] = 4
if 20 < slow_k_week < 30: type_stock['week'] = 3
if 30 < slow_k_week < 40: type_stock['week'] = 2
if slow_k_month < p_slow_k_month:
if slow_k_month < 20: type_stock['month'] = 4
if 20 < slow_k_month < 30: type_stock['month'] = 3
if 30 < slow_k_month < 40: type_stock['month'] = 2
if (type_kospi['day'] == 1 and type_kospi['week'] == 1 and type_kospi['month'] == 1 and
type_stock['day'] == 1 and type_stock['week'] == 1 and type_stock['month'] == 1):
return 0
max_price = math.log(type_kospi['day']*type_kospi['week']*type_kospi['month']*type_stock['day']*type_stock['week']*type_stock['month'], 1.3) * base_price
buy_count = int(math.ceil(max_price / bs_buy_price))
return buy_count
def buyRealTime(self, today, stocks, analyzed_day=1000):
VALID_DAY = True
print ("START...")
THIS_TIME = datetime.now()
slow_k_kospi, p_slow_k_kospi, slow_k_week_kospi, p_slow_k_week_kospi, slow_k_month_kospi, p_slow_k_month_kospi = self.getSlowK("^KS11")
if (50 < slow_k_kospi or 50 < p_slow_k_kospi or (slow_k_kospi < 50 and p_slow_k_kospi < 50 and slow_k_kospi < p_slow_k_kospi)):
print("#1 매수/매도 일이 아닙니다.", slow_k_kospi, p_slow_k_kospi)
VALID_DAY = False
if ((0 < slow_k_week_kospi < 50 and 0 < slow_k_month_kospi < 50) and
not ((20 < slow_k_week_kospi and slow_k_week_kospi < p_slow_k_week_kospi) or (20 < slow_k_month_kospi and slow_k_month_kospi < p_slow_k_month_kospi))):
print("#2 매수/매도 일이 아닙니다.", p_slow_k_week_kospi, slow_k_week_kospi, p_slow_k_month_kospi, slow_k_month_kospi)
VALID_DAY = False
LAST_DATA = {}
for stock in stocks:
@@ -239,11 +264,6 @@ class HTS_etf (HTS):
bs_buy_weight = bsLine['buy_weight'][0]
bs_sell_price = bsLine['sell'][0]
slow_k, p_slow_k, slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month = self.getSlowK(stock['stock_code'])
if ((0 < slow_k_week < 30 and 0 < slow_k_month < 30) and
not ((20 < slow_k_week and slow_k_week < p_slow_k_week) or (20 < slow_k_month and slow_k_month < p_slow_k_month))):
# 미체결 기록을 가져와서 10분 이상 된 매수 주문을 취소 한다.
ORDER_LIST = self.requestOrderList()
orderListToCancel = self.orderChecker.cancel(today, "A" + stock['stock_code'], ORDER_LIST, mins=10)
@@ -253,7 +273,7 @@ class HTS_etf (HTS):
if bs_buy_price > 1000:
if not self.orderChecker.exist(today, "A" + stock['stock_code'], hours=9):
buy_count = self.getCount(stock['stock_code'], bs_buy_price, data)
buy_count = self.getBuyCount(stock['stock_code'], bs_buy_price, slow_k_kospi, p_slow_k_kospi, slow_k_week_kospi, p_slow_k_week_kospi, slow_k_month_kospi, p_slow_k_month_kospi)
if buy_count > 0: