def __init__(self): self.isSB = False # 실시간 처리 ##################################################################### # data self.stkCurData = CpData.StkCurData() self.stkTickData = CpData.StkTickData() # 주문 현재가/10차 호가 저장 self.strtgyData = StrtgyData() self.strtgyDataT = StrtgyData() self.stkBlncData = StkBlncData() ############################################################################### # 주문결과 self.stkOdrRsltData = StkOdrRsltData() ##################################################################### # object self.objOdr = CpOrder() self.objSBcur = CpData.CpSBStockCur() self.objSBbid = CpData.CpSBStockBid() self.objCurBid = CpData.CpStockCurBid() self.objCurBid2 = CpData.CpStockCurBid2() self.objDB = CpDB.CpDB() ##################################################################### # 잔고조회 / 미체결조회 self.objBlnc = Cp6033() self.objUnCon = Cp5339()
def itemRequest(self, item): print(item) pythoncom.CoInitialize() objIdx = CpData.CpMarketEye2() objMktEye = win32com.client.Dispatch("CpSysDib.MarketEye") objDBRQ = CpDB.CpDB() con = objDBRQ.connect() print("con", con) for i in range(10000): stkCurDataIdx = CpData.StkCurData() remainCount = com.g_objCpStatus.GetLimitRemainCount(1) # 1 시세 제한 if remainCount <= 0: print('시세 연속 조회 제한 회피를 위해 sleep', com.g_objCpStatus.LimitRequestRemainTime) time.sleep(com.g_objCpStatus.LimitRequestRemainTime / 1000) objIdx.Request(objMktEye, item, stkCurDataIdx) print(stkCurDataIdx.item, stkCurDataIdx.item_nm, stkCurDataIdx.close) self.objDBRQ.stkidxt('I', con, stkCurDataIdx, stkCurDataIdx) time.sleep(3) return
def load_data(fpath, date_from, date_to, stock_code, ver='v2'): header = None if ver == 'v1' else 0 """ data = pd.read_csv(fpath, thousands=',', header=header, converters={'date': lambda x: str(x)}) """ cpdb = CpDB.CpDB() con = cpdb.connect() stkData = StkData() stkData.from_ymd = date_from stkData.to_ymd = date_to stkData.item = stock_code print(date_from, date_to, stock_code) data = cpdb.stkhistprc(con, 'S', stkData) # 대소문자 구분 if ver == 'v1': data.columns = ['date', 'open', 'high', 'low', 'close', 'volume'] # 데이터 전처리 print(data) data = preprocess(data) print(data) # 기간 필터링 #if len(data['date'].str) > 8: # data['date'] = data['date'].str.replace('-', '') #data = data[(data['date'] >= date_from) & (data['date'] <= date_to)] data = data.dropna() # 차트 데이터 분리 chart_data = data[COLUMNS_CHART_DATA] # 학습 데이터 분리 training_data = None if ver == 'v1': training_data = data[COLUMNS_TRAINING_DATA_V1] elif ver == 'v1.rich': training_data = data[COLUMNS_TRAINING_DATA_V1_RICH] elif ver == 'v2': data.loc[:, ['per', 'pbr', 'roe']] = \ data[['per', 'pbr', 'roe']].apply(lambda x: x / 100) training_data = data[COLUMNS_TRAINING_DATA_V2] training_data = training_data.apply(np.tanh) else: raise Exception('Invalid version.') return chart_data, training_data, data
def btchart1_clicked(self): pythoncom.CoInitialize() print("def btchart1_clicked(self) ", self.ticktp, self.code, self.fromdt, self.todt) if self.ticktp == 'D': if self.objChart.RequestFromTo(self.code, self.fromdt, self.todt, self) == False: exit() # 분봉 데이터 if self.ticktp == 'M': if self.objChart.RequestMTT(self.code, ord('m'), 100, self) == False: exit() # 틱 데이터 if self.ticktp == 'T': if self.objChart.RequestMTT(self.code, ord('T'), 100, self) == False: exit() self.stkDataHist = CpData.StkDataHist() self.stkDataHist.ymd = self.dates self.stkDataHist.item = self.item for i in range(len(self.dates)): self.stkDataHist.item_nm.append(self.item_nm) self.stkDataHist.open = self.opens self.stkDataHist.high = self.highs self.stkDataHist.low = self.lows self.stkDataHist.close = self.closes self.stkDataHist.acc_vol = self.vols self.stkDataHist.diff = self.diff print("def btchart1_clicked(self) ", self.code, self.item_nm, len(self.dates)) self.cpdb = CpDB.CpDB() self.con = self.cpdb.connect() self.cpdb.stkhistprc(self.con, 'I', self.stkDataHist) ##################################################################### # 호가 데이터 TCP 통신 """
def ivtRequest(self): pythoncom.CoInitialize() objDBRQ = CpDB.CpDB() con = objDBRQ.connect() print("con", con) objIvt = CpData.Cp7222() while True: remainCount = com.g_objCpStatus.GetLimitRemainCount(1) # 1 시세 제한 if remainCount <= 0: print('시세 연속 조회 제한 회피를 위해 sleep', com.g_objCpStatus.LimitRequestRemainTime) time.sleep(com.g_objCpStatus.LimitRequestRemainTime / 1000) objIvtData = CpData.Ivt7222() objIvt.Request(objIvtData) objDBRQ.tivtt(con, 'I', objIvtData, objIvtData) time.sleep(10) return
def __init__(self): super().__init__() # plus 상태 체크 if com.InitPlusCheck() == False: exit() if com.InitTradeInit() == False: exit() ##################################################################### # account info self.acc_no = com.g_objCpTrade.AccountNumber[0] # 계좌번호 self.acc_tp = com.g_objCpTrade.GoodsList(self.acc_no, 1) # 주식상품 구분 ##################################################################### # stock object self.stkCurData = CpData.StkCurData() self.stkTickData = CpData.StkTickData() # 주문 현재가/10차 호가 저장 self.objSBCur = CpData.CpSBStockCur() self.objSBid = CpData.CpSBStockBid() ##################################################################### # 시세종목 #self.codelist = ['A05930', 'A151860'] self.codelist = ['A151860'] ##################################################################### # logger self.logger = logging.getLogger("my_setting") self.logger = LoggerAdapter(CpDataWindow.__name__, self.logger) self.logger.debug(f'CpDataWindow Start') ##################################################################### # db object self.objDB = CpDB.CpDB() ##################################################################### # 이동평균 self.cntTick = 0 self.stkCur = [] self.futCur = [] self.stkShortOdrTP = 'N' self.stkLongOdrTP = 'N' self.setWindowTitle(sys.argv[0]) self.setGeometry(300, 300, 300, 700) nH = 20 btnBuy = QPushButton("종목 분 데이터 조회", self) btnBuy.move(20, nH) # btnBuy.resize(200,30) btnBuy.clicked.connect(self.btnBuy_clicked) nH += 50 btnExit = QPushButton("종료", self) btnExit.move(20, nH) # btnExit.resize(200,30) btnExit.clicked.connect(self.btnExit_clicked) nH += 50 btnMst = QPushButton("기본정보", self) btnMst.move(20, nH) # btnExit.resize(200,30) btnMst.clicked.connect(self.btnMst_clicked) nH += 50 btnInv = QPushButton("투자자종합", self) btnInv.move(20, nH) btnInv.clicked.connect(self.btnInv_clicked)
def __init__(self): super().__init__() pythoncom.CoInitialize() self.odrExec0 = CpOdr.CpOrderExec() self.odrExec1 = CpOdr.CpOrderExec() self.odrExec2 = CpOdr.CpOrderExec() self.odrExec3 = CpOdr.CpOrderExec() # plus 상태 체크 if com.InitPlusCheck() == False: exit() if com.InitTradeInit() == False: exit() self.acc_no = com.g_objCpTrade.AccountNumber[0] # 계좌번호 self.acc_tp = com.g_objCpTrade.GoodsList(self.acc_no, 1) # 주식상품 구분 ##################################################################### # logger self.logger = logging.getLogger("my_setting") self.logger = LoggerAdapter(CpOdrWindow.__name__, self.logger) self.logger.debug(f'CpOdrWindow Start {self.acc_no} {self.acc_tp}') ##################################################################### # 전략, 체결 self.strtgyData = CpOdr.StrtgyData() ##################################################################### # 체결 data class self.stkConData = CpOdr.StkConData() self.objSBCon = CpOdr.CpSBConclusion() ##################################################################### # 체겷 Subscribe # def monitorCon(self): 실시간 업데이트 self.objSBCon.Subscribe(self.stkConData, self) ##################################################################### # 잔고 self.objBlnc = CpOdr.Cp6033() ##################################################################### # stock object self.stkCurData = CpData.StkCurData() self.stkTickData = CpData.StkTickData() # 주문 현재가/10차 호가 저장 self.objSBCur = CpData.CpSBStockCur() self.objSBbid = CpData.CpSBStockBid() ##################################################################### # db object self.objDB = CpDB.CpDB() self.setWindowTitle("PLUS API TEST") self.setGeometry(300, 300, 300, 700) nH = 20 btnBuy = QPushButton("매수/매도 주문", self) btnBuy.move(20, nH) # btnBuy.resize(200,30) btnBuy.clicked.connect(self.btnBuy_clicked) nH += 50 btnExit = QPushButton("종료", self) btnExit.move(20, nH) # btnExit.resize(200,30) btnExit.clicked.connect(self.btnExit_clicked) nH += 50 btnMst = QPushButton("기본정보", self) btnMst.move(20, nH) # btnExit.resize(200,30) btnMst.clicked.connect(self.btnMst_clicked) nH += 50 btnInv = QPushButton("투자자종합", self) btnInv.move(20, nH) btnInv.clicked.connect(self.btnInv_clicked)
def __init__(self): # plus 상태 체크 if com.InitPlusCheck() == False: exit() if com.InitTradeInit() == False: exit() ##################################################################### # account info self.acc_no = com.g_objCpTrade.AccountNumber[0] # 계좌번호 self.acc_tp = com.g_objCpTrade.GoodsList(self.acc_no, 1) # 주식상품 구분 ##################################################################### # stock object self.stkCurData = CpData.StkCurData() self.stkTickData = CpData.StkTickData() # 주문 현재가/10차 호가 저장 self.objSBCur = CpData.CpSBStockCur() self.objSBid = CpData.CpSBStockBid() ##################################################################### # future object self.futCurData = CpDataFut.FutCurData() self.objSBCurFut = CpDataFut.CpFutureCurOnly() self.futTickData = CpDataFut.FutTickData() ##################################################################### # db object self.objDB = CpDB.CpDB() ##################################################################### # db object self.cntTick = 0 self.stkCur = [] self.futCur = [] super().__init__() self.setWindowTitle(sys.argv[0]) self.setGeometry(300, 300, 300, 700) nH = 20 btnBuy = QPushButton("종목 분 데이터 조회", self) btnBuy.move(20, nH) # btnBuy.resize(200,30) btnBuy.clicked.connect(self.btnBuy_clicked) nH += 50 btnExit = QPushButton("종료", self) btnExit.move(20, nH) # btnExit.resize(200,30) btnExit.clicked.connect(self.btnExit_clicked) nH += 50 btnMst = QPushButton("기본정보", self) btnMst.move(20, nH) # btnExit.resize(200,30) btnMst.clicked.connect(self.btnMst_clicked) nH += 50 btnInv = QPushButton("투자자종합", self) btnInv.move(20, nH) btnInv.clicked.connect(self.btnInv_clicked)