init
This commit is contained in:
@@ -17,9 +17,12 @@ class HTS_122630:
|
|||||||
objCpCodeMgr = None
|
objCpCodeMgr = None
|
||||||
|
|
||||||
buySellChecker = None
|
buySellChecker = None
|
||||||
|
stock_code = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, stock_code):
|
||||||
self.buySellChecker = BuySellChecker()
|
self.buySellChecker = BuySellChecker()
|
||||||
|
self.stock_code = stock_code
|
||||||
|
|
||||||
#self.connect()
|
#self.connect()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -545,8 +548,8 @@ class HTS_122630:
|
|||||||
|
|
||||||
return 0, 0
|
return 0, 0
|
||||||
|
|
||||||
def buyRealTime(self, stock_code, GIVEN_DAY):
|
def buyRealTime(self, GIVEN_DAY):
|
||||||
orderChecker = OrderChecker(stock_code)
|
orderChecker = OrderChecker(self.stock_code)
|
||||||
BASE_COUNT = 10
|
BASE_COUNT = 10
|
||||||
|
|
||||||
timecheckList = pd.read_csv("timecheck.csv").values.tolist()
|
timecheckList = pd.read_csv("timecheck.csv").values.tolist()
|
||||||
@@ -569,7 +572,7 @@ class HTS_122630:
|
|||||||
if THIS_TIME.strftime('%Y%m%d %H%M%S') in timecheck and not timecheck[THIS_TIME.strftime('%Y%m%d %H%M%S')]:
|
if THIS_TIME.strftime('%Y%m%d %H%M%S') in timecheck and not timecheck[THIS_TIME.strftime('%Y%m%d %H%M%S')]:
|
||||||
|
|
||||||
# 데이터를 가지고 온다.
|
# 데이터를 가지고 온다.
|
||||||
self.getRealTime(stock_code, GIVEN_DAY, result)
|
self.getRealTime(self.stock_code, GIVEN_DAY, result)
|
||||||
|
|
||||||
# 분석을 통해서 볼린저밴드 상/하단을 계산한다.
|
# 분석을 통해서 볼린저밴드 상/하단을 계산한다.
|
||||||
data = self.buySellChecker.analyze(result)
|
data = self.buySellChecker.analyze(result)
|
||||||
@@ -584,12 +587,12 @@ class HTS_122630:
|
|||||||
BUY_COUNT = int(BASE_COUNT * 1)
|
BUY_COUNT = int(BASE_COUNT * 1)
|
||||||
|
|
||||||
# 매수를 주문한다.
|
# 매수를 주문한다.
|
||||||
orderNum = self.requestOrder(OrderType.buy, stock_code, BUY_COUNT , bs_buy_price)
|
orderNum = self.requestOrder(OrderType.buy, self.stock_code, BUY_COUNT , bs_buy_price)
|
||||||
|
|
||||||
# 미체결 기록을 가져온다.
|
# 미체결 기록을 가져온다.
|
||||||
ORDER_LIST = self.requestOrderList()
|
ORDER_LIST = self.requestOrderList()
|
||||||
# 매수 주문을 기록한다.
|
# 매수 주문을 기록한다.
|
||||||
orderListToCancel = orderChecker.add(stock_code, OrderType.buy, orderNum, BUY_COUNT, bs_buy_price, ORDER_LIST)
|
orderListToCancel = orderChecker.add(self.stock_code, OrderType.buy, orderNum, BUY_COUNT, bs_buy_price, ORDER_LIST)
|
||||||
# 두 시간 이전 미체결을 모두 취소한다.
|
# 두 시간 이전 미체결을 모두 취소한다.
|
||||||
self.cancelOrderList(orderListToCancel)
|
self.cancelOrderList(orderListToCancel)
|
||||||
# 로그 출력
|
# 로그 출력
|
||||||
@@ -599,7 +602,7 @@ class HTS_122630:
|
|||||||
# 미체결 기록을 가져온다.
|
# 미체결 기록을 가져온다.
|
||||||
ORDER_LIST = self.requestOrderList()
|
ORDER_LIST = self.requestOrderList()
|
||||||
# 매도 주문을 기록을 가져온다.
|
# 매도 주문을 기록을 가져온다.
|
||||||
orderListToCancel = orderChecker.remove(stock_code, OrderType.sell, ORDER_LIST)
|
orderListToCancel = orderChecker.remove(self.stock_code, OrderType.sell, ORDER_LIST)
|
||||||
# 매도 미체결을 모두 취소한다.
|
# 매도 미체결을 모두 취소한다.
|
||||||
self.cancelOrderList(orderListToCancel)
|
self.cancelOrderList(orderListToCancel)
|
||||||
|
|
||||||
@@ -608,7 +611,7 @@ class HTS_122630:
|
|||||||
# 분석되 가격으로 매도 요청한다.
|
# 분석되 가격으로 매도 요청한다.
|
||||||
if selling_count != 0 and selling_price != 0:
|
if selling_count != 0 and selling_price != 0:
|
||||||
# 매도를 요청한다.
|
# 매도를 요청한다.
|
||||||
orderNum = self.requestOrder(OrderType.sell, stock_code, selling_count, selling_price)
|
orderNum = self.requestOrder(OrderType.sell, self.stock_code, selling_count, selling_price)
|
||||||
|
|
||||||
# 로그 출력
|
# 로그 출력
|
||||||
print("SELL", THIS_TIME.strftime('%Y%m%d %H%M%S'), selling_count, selling_price, len(orderListToCancel), len(ORDER_LIST))
|
print("SELL", THIS_TIME.strftime('%Y%m%d %H%M%S'), selling_count, selling_price, len(orderListToCancel), len(ORDER_LIST))
|
||||||
@@ -631,7 +634,7 @@ class HTS_122630:
|
|||||||
selling_count, selling_price = self.getSellingPrice(final_price)
|
selling_count, selling_price = self.getSellingPrice(final_price)
|
||||||
# 분석되 가격으로 매도 요청한다.
|
# 분석되 가격으로 매도 요청한다.
|
||||||
if selling_count != 0 and selling_price != 0:
|
if selling_count != 0 and selling_price != 0:
|
||||||
orderNum = self.requestOrder(OrderType.sell, stock_code, selling_count, selling_price)
|
orderNum = self.requestOrder(OrderType.sell, self.stock_code, selling_count, selling_price)
|
||||||
# 로그 출력
|
# 로그 출력
|
||||||
print("SELL", THIS_TIME, selling_count, selling_price)
|
print("SELL", THIS_TIME, selling_count, selling_price)
|
||||||
|
|
||||||
@@ -649,11 +652,11 @@ if __name__ == "__main__":
|
|||||||
RESOURCE_DIR = PROJECT_HOME + "/resources/analysis/"+today.strftime("%Y%m%d")
|
RESOURCE_DIR = PROJECT_HOME + "/resources/analysis/"+today.strftime("%Y%m%d")
|
||||||
|
|
||||||
# KODEX 인버스 * 2
|
# KODEX 인버스 * 2
|
||||||
hts = HTS_122630()
|
stock_code = "122630"
|
||||||
stock_codes = ["122630"]
|
hts = HTS_122630(stock_code)
|
||||||
given_day = datetime.today().strftime('%Y%m%d')
|
given_day = datetime.today().strftime('%Y%m%d')
|
||||||
|
|
||||||
#hts.writeStockData(stock_codes, "20211025")
|
#hts.writeStockData(stock_codes, "20211025")
|
||||||
hts.buyRealTime(stock_codes[0], given_day)
|
hts.buyRealTime(given_day)
|
||||||
|
|
||||||
print ("done...")
|
print ("done...")
|
||||||
|
|||||||
@@ -17,9 +17,12 @@ class HTS_252670:
|
|||||||
objCpCodeMgr = None
|
objCpCodeMgr = None
|
||||||
|
|
||||||
buySellChecker = None
|
buySellChecker = None
|
||||||
|
stock_code = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, stock_code):
|
||||||
self.buySellChecker = BuySellChecker()
|
self.buySellChecker = BuySellChecker()
|
||||||
|
self.stock_code = stock_code
|
||||||
|
|
||||||
#self.connect()
|
#self.connect()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -545,8 +548,8 @@ class HTS_252670:
|
|||||||
|
|
||||||
return 0, 0
|
return 0, 0
|
||||||
|
|
||||||
def buyRealTime(self, stock_code, GIVEN_DAY):
|
def buyRealTime(self, GIVEN_DAY):
|
||||||
orderChecker = OrderChecker(stock_code)
|
orderChecker = OrderChecker(self.stock_code)
|
||||||
BASE_COUNT = 100
|
BASE_COUNT = 100
|
||||||
|
|
||||||
timecheckList = pd.read_csv("timecheck.csv").values.tolist()
|
timecheckList = pd.read_csv("timecheck.csv").values.tolist()
|
||||||
@@ -569,7 +572,7 @@ class HTS_252670:
|
|||||||
if THIS_TIME.strftime('%Y%m%d %H%M%S') in timecheck and not timecheck[THIS_TIME.strftime('%Y%m%d %H%M%S')]:
|
if THIS_TIME.strftime('%Y%m%d %H%M%S') in timecheck and not timecheck[THIS_TIME.strftime('%Y%m%d %H%M%S')]:
|
||||||
|
|
||||||
# 데이터를 가지고 온다.
|
# 데이터를 가지고 온다.
|
||||||
self.getRealTime(stock_code, GIVEN_DAY, result)
|
self.getRealTime(self.stock_code, GIVEN_DAY, result)
|
||||||
|
|
||||||
# 분석을 통해서 볼린저밴드 상/하단을 계산한다.
|
# 분석을 통해서 볼린저밴드 상/하단을 계산한다.
|
||||||
data = self.buySellChecker.analyze(result)
|
data = self.buySellChecker.analyze(result)
|
||||||
@@ -584,12 +587,12 @@ class HTS_252670:
|
|||||||
BUY_COUNT = int(BASE_COUNT * 1)
|
BUY_COUNT = int(BASE_COUNT * 1)
|
||||||
|
|
||||||
# 매수를 주문한다.
|
# 매수를 주문한다.
|
||||||
orderNum = self.requestOrder(OrderType.buy, stock_code, BUY_COUNT , bs_buy_price)
|
orderNum = self.requestOrder(OrderType.buy, self.stock_code, BUY_COUNT , bs_buy_price)
|
||||||
|
|
||||||
# 미체결 기록을 가져온다.
|
# 미체결 기록을 가져온다.
|
||||||
ORDER_LIST = self.requestOrderList()
|
ORDER_LIST = self.requestOrderList()
|
||||||
# 매수 주문을 기록한다.
|
# 매수 주문을 기록한다.
|
||||||
orderListToCancel = orderChecker.add(stock_code, OrderType.buy, orderNum, BUY_COUNT, bs_buy_price, ORDER_LIST)
|
orderListToCancel = orderChecker.add(self.stock_code, OrderType.buy, orderNum, BUY_COUNT, bs_buy_price, ORDER_LIST)
|
||||||
# 두 시간 이전 미체결을 모두 취소한다.
|
# 두 시간 이전 미체결을 모두 취소한다.
|
||||||
self.cancelOrderList(orderListToCancel)
|
self.cancelOrderList(orderListToCancel)
|
||||||
# 로그 출력
|
# 로그 출력
|
||||||
@@ -599,7 +602,7 @@ class HTS_252670:
|
|||||||
# 미체결 기록을 가져온다.
|
# 미체결 기록을 가져온다.
|
||||||
ORDER_LIST = self.requestOrderList()
|
ORDER_LIST = self.requestOrderList()
|
||||||
# 매도 주문을 기록을 가져온다.
|
# 매도 주문을 기록을 가져온다.
|
||||||
orderListToCancel = orderChecker.remove(stock_code, OrderType.sell, ORDER_LIST)
|
orderListToCancel = orderChecker.remove(self.stock_code, OrderType.sell, ORDER_LIST)
|
||||||
# 매도 미체결을 모두 취소한다.
|
# 매도 미체결을 모두 취소한다.
|
||||||
self.cancelOrderList(orderListToCancel)
|
self.cancelOrderList(orderListToCancel)
|
||||||
|
|
||||||
@@ -608,7 +611,7 @@ class HTS_252670:
|
|||||||
# 분석되 가격으로 매도 요청한다.
|
# 분석되 가격으로 매도 요청한다.
|
||||||
if selling_count != 0 and selling_price != 0:
|
if selling_count != 0 and selling_price != 0:
|
||||||
# 매도를 요청한다.
|
# 매도를 요청한다.
|
||||||
orderNum = self.requestOrder(OrderType.sell, stock_code, selling_count, selling_price)
|
orderNum = self.requestOrder(OrderType.sell, self.stock_code, selling_count, selling_price)
|
||||||
|
|
||||||
# 로그 출력
|
# 로그 출력
|
||||||
print("SELL", THIS_TIME.strftime('%Y%m%d %H%M%S'), selling_count, selling_price, len(orderListToCancel), len(ORDER_LIST))
|
print("SELL", THIS_TIME.strftime('%Y%m%d %H%M%S'), selling_count, selling_price, len(orderListToCancel), len(ORDER_LIST))
|
||||||
@@ -631,7 +634,7 @@ class HTS_252670:
|
|||||||
selling_count, selling_price = self.getSellingPrice(final_price)
|
selling_count, selling_price = self.getSellingPrice(final_price)
|
||||||
# 분석되 가격으로 매도 요청한다.
|
# 분석되 가격으로 매도 요청한다.
|
||||||
if selling_count != 0 and selling_price != 0:
|
if selling_count != 0 and selling_price != 0:
|
||||||
orderNum = self.requestOrder(OrderType.sell, stock_code, selling_count, selling_price)
|
orderNum = self.requestOrder(OrderType.sell, self.stock_code, selling_count, selling_price)
|
||||||
# 로그 출력
|
# 로그 출력
|
||||||
print("SELL", THIS_TIME, selling_count, selling_price)
|
print("SELL", THIS_TIME, selling_count, selling_price)
|
||||||
|
|
||||||
@@ -649,11 +652,11 @@ if __name__ == "__main__":
|
|||||||
RESOURCE_DIR = PROJECT_HOME + "/resources/analysis/"+today.strftime("%Y%m%d")
|
RESOURCE_DIR = PROJECT_HOME + "/resources/analysis/"+today.strftime("%Y%m%d")
|
||||||
|
|
||||||
# KODEX 인버스 * 2
|
# KODEX 인버스 * 2
|
||||||
hts = HTS_252670()
|
stock_code = "252670"
|
||||||
stock_codes = ["252670"]
|
hts = HTS_252670(stock_code)
|
||||||
given_day = datetime.today().strftime('%Y%m%d')
|
given_day = datetime.today().strftime('%Y%m%d')
|
||||||
|
|
||||||
#hts.writeStockData(stock_codes, "20211025")
|
#hts.writeStockData(stock_codes, "20211025")
|
||||||
hts.buyRealTime(stock_codes[0], given_day)
|
hts.buyRealTime(given_day)
|
||||||
|
|
||||||
print ("done...")
|
print ("done...")
|
||||||
|
|||||||
@@ -9,8 +9,12 @@ from BuySellChecker import BuySellChecker
|
|||||||
class Simulation:
|
class Simulation:
|
||||||
|
|
||||||
buySellChecker = None
|
buySellChecker = None
|
||||||
def __init__(self):
|
stock_code = None
|
||||||
|
|
||||||
|
def __init__(self, stock_code):
|
||||||
|
|
||||||
self.buySellChecker = BuySellChecker()
|
self.buySellChecker = BuySellChecker()
|
||||||
|
self.stock_code = stock_code
|
||||||
#self.connect()
|
#self.connect()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -50,7 +54,10 @@ class Simulation:
|
|||||||
bsLine['sell'] = [-1 for i in range(size)]
|
bsLine['sell'] = [-1 for i in range(size)]
|
||||||
|
|
||||||
for i in range(6, size-5):
|
for i in range(6, size-5):
|
||||||
|
if self.stock_code == "252670":
|
||||||
buy, weight, sell = self.buySellChecker.getPriceAndWeight1(data, i)
|
buy, weight, sell = self.buySellChecker.getPriceAndWeight1(data, i)
|
||||||
|
else:
|
||||||
|
buy, weight, sell = self.buySellChecker.getPriceAndWeight2(data, i)
|
||||||
bsLine['buy'][i] = buy
|
bsLine['buy'][i] = buy
|
||||||
bsLine['weight'][i] = weight
|
bsLine['weight'][i] = weight
|
||||||
bsLine['sell'][i] = sell
|
bsLine['sell'][i] = sell
|
||||||
@@ -139,7 +146,7 @@ class Simulation:
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def simulate(self, stock_code, GIVEN_DAY):
|
def simulate(self, GIVEN_DAY):
|
||||||
result = {"check": set(),
|
result = {"check": set(),
|
||||||
"time": [],
|
"time": [],
|
||||||
"open": [],
|
"open": [],
|
||||||
@@ -149,7 +156,7 @@ class Simulation:
|
|||||||
"vol": []}
|
"vol": []}
|
||||||
|
|
||||||
# 데이터를 가지고 온다.
|
# 데이터를 가지고 온다.
|
||||||
self.getCSV("./data/"+stock_code+"_"+GIVEN_DAY+".csv", GIVEN_DAY, result)
|
self.getCSV("./data/"+self.stock_code+"_"+GIVEN_DAY+".csv", GIVEN_DAY, result)
|
||||||
|
|
||||||
# 분석을 통해서 볼린저밴드 상/하단을 계산한다.
|
# 분석을 통해서 볼린저밴드 상/하단을 계산한다.
|
||||||
data = self.buySellChecker.analyze(result)
|
data = self.buySellChecker.analyze(result)
|
||||||
@@ -158,7 +165,7 @@ class Simulation:
|
|||||||
bsLine = self.checkTransaction(data)
|
bsLine = self.checkTransaction(data)
|
||||||
|
|
||||||
# 그래프를 그린다.
|
# 그래프를 그린다.
|
||||||
self.draw(stock_code, GIVEN_DAY, data, bsLine)
|
self.draw(self.stock_code, GIVEN_DAY, data, bsLine)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -174,12 +181,11 @@ if __name__ == "__main__":
|
|||||||
'20210914','20210915','20210916','20210917','20210923','20210924','20210927','20210928','20210929',
|
'20210914','20210915','20210916','20210917','20210923','20210924','20210927','20210928','20210929',
|
||||||
'20210930','20211001','20211005','20211006','20211007','20211008','20211012','20211013','20211014',
|
'20210930','20211001','20211005','20211006','20211007','20211008','20211012','20211013','20211014',
|
||||||
'20211018', '20211019','20211020','20211021','20211022']
|
'20211018', '20211019','20211020','20211021','20211022']
|
||||||
given_days = ['20211022']
|
|
||||||
|
|
||||||
simulation = Simulation()
|
simulation = Simulation(stock_codes[1])
|
||||||
|
|
||||||
given_days = sorted(given_days, reverse=True)
|
given_days = sorted(given_days, reverse=True)
|
||||||
for given_day in given_days:
|
for given_day in given_days:
|
||||||
simulation.simulate(stock_codes[0], given_day)
|
simulation.simulate(given_day)
|
||||||
|
|
||||||
print ("done...")
|
print ("done...")
|
||||||
|
|||||||
Reference in New Issue
Block a user