def stockPurchase(self): pythoncom.CoInitialize() #If sending order is dirupted, try again if xingAPIClassModule.messageCode == "03563": self.algorithm1Timer_purchase() return #disconnected? login! xingAPIClassModule.xingAPILogin() #Buy the stocks which are listed in 'TopStockList' xingAPIClassModule.XAQuery('CSPAT00600', self.TopStockList, self.TheNumberOfStocksPurchase, self.codeList, self.account, "2") stockName = self.TopStockList[0] stockCode = self.codeList[stockName] stockListRequest = stockCode for stockName in self.TopStockList[1:]: stockCode = self.codeList[stockName] stockListRequest = stockListRequest + ";" + stockCode #Request Real time data #self.kiwoom.dynamicCall("SetRealReg(QString, QString, QString, QString)", "0101", stockListRequest, "20", "0") DBconnect = sqlite3.connect("TradingProject.db") dataBaseCursor = DBconnect.cursor() #Connect database cursor! dataBaseCursor.execute("UPDATE kospiTradingState SET tradingState = 1") DBconnect.commit() print("STOCK PURCHASE PROCESS IS COMPLETED") self.algorithm1Timer_sell() time.sleep(10)
def stockSell(self): pythoncom.CoInitialize() xingAPIClassModule.xingAPILogin() sellAmount = xingAPIClassModule.XAQuery('CSPAQ12300', self.account) print("sell:" + str(sellAmount)) xingAPIClassModule.XAQuery('CSPAT00600', self.TopStockList, sellAmount, self.codeList, self.account, "1") DBconnect = sqlite3.connect("TradingProject.db") dataBaseCursor = DBconnect.cursor() #Connect database cursor! dataBaseCursor.execute("UPDATE kospiTradingState SET tradingState = 0") DBconnect.commit() #sleep for 2 minutes! because if the code which is below this line executes, it can make a fetal error. #Why? I set up a purchase algorithm >> 14:30 time.sleep(120) print("STOCK SELL PROCESS IS COMPLETED") #Make daily report import dailyReport report = dailyReport.report() report.printReport()
def APILogIn(self): #Login API xingAPIClassModule.xingAPILogin() self.textBrowser.append("로그인 되었습니다.")