Exemple #1
0
    def OnNotifyTicks(self, sMarketNo, sStockidx, nPtr, nDate, nTimehms, nTimemillis, nBid, nAsk, nClose, nQty, nSimulate):
        pStock = sk.SKSTOCK()
        self.skQ.SKQuoteLib_GetStockByIndex(sMarketNo, sStockidx, pStock)
        self.stock_state[pStock.bstrStockNo] = pStock
        ppow = math.pow(10, pStock.sDecimal)

        # 14:30:00 的紀錄不處理
        if nTimehms > 133000:
            return

        # 時間字串化
        s = nTimehms % 100
        nTimehms /= 100
        m = nTimehms % 100
        nTimehms /= 100
        h = nTimehms
        timestr = '%02d:%02d:%02d.%03d' % (h, m, s, nTimemillis//1000)

        entry = {
            'id': pStock.bstrStockNo,
            'name': pStock.bstrStockName,
            'time': timestr,
            'ask': nAsk / ppow,
            'bid': nBid / ppow,
            'close': nClose / ppow,
            'qty': nQty,
            'volume': pStock.nTQty
        }
        self.ticks_hook(entry)
 def Future(self, account, stockNo, sBuySell, sPrice, sQty, tradetype,
            reservetype):
     # 建立下單用的參數(FUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
     oOrder = sk.FUTUREORDER()
     # 填入完整帳號
     oOrder.bstrFullAccount = account
     # 填入期權代號
     oOrder.bstrStockNo = stockNo
     # 買進 = 0、賣出 = 1
     if sBuySell == "Buy":
         oOrder.sBuySell = 0
     elif sBuySell == "Sell":
         oOrder.sBuySell = 1
     # ROD = 0、IOC = 1、FOK = 2
     if tradetype == 'ROD':
         oOrder.sTradeType = 0
     elif tradetype == 'IOC':
         oOrder.sTradeType = 1
     elif tradetype == 'FOK':
         oOrder.sTradeType = 2
     # 非當沖 = 0、當沖 = 1
     oOrder.sDayTrade = 0
     # 委託價、市價 = M
     oOrder.bstrPrice = sPrice
     # 委託數量
     oOrder.nQty = int(sQty)
     # 新倉 = 0、平倉 = 1、自動 = 2
     oOrder.sNewClose = 2
     # 盤中 = 0、T盤預約 = 1
     oOrder.sReserved = reservetype
     return oOrder
    def __SendOrder_Click(self, bAsyncOrder):
        try:
            if self.boxBuyOrSell1.get() == "買進":
                sBuySell = 0
            elif self.boxBuyOrSell1.get() == "賣出":
                sBuySell = 1

            # 建立下單用的參數(FUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.FUTUREORDER()
            # 填入完整帳號
            oOrder.bstrFullAccount = self.__dOrder['boxAccount']
            # 填入期權代號1
            oOrder.bstrStockNo = self.txtStockNo1.get()
            # 買賣別
            oOrder.sBuySell = sBuySell
            # 委託數量
            oOrder.nQty = int(self.txtQty.get())

            message, m_nCode = skO.DisassembleOptions(Global.Global_IID,
                                                      bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode,
                                          "DisassembleOptions",
                                          self.__dOrder['listInformation'])

        except Exception as e:
            messagebox.showerror("error!", e)
Exemple #4
0
 def __init__(self):
     super(SKMainWindow, self).__init__()
     loadUi(r'UI/MainWindow.ui', self)
     self.showMaximized()
     # 帳號處理
     self.SKID = '未登入'  # 登入帳號
     self.IBAccount = ''  #期貨帳號
     self.statusBar.showMessage('帳號:' + self.SKID)
     self.Bill = []
     self.fOrder = sk.FUTUREORDER()
     #下單參數 Future structure
     self.trade_act = -1
     self.OrderPrice = ''
     self.ReplyComplete = False
     # 介面導入
     self.SKLoginUI()  #登入介面
     self.SKMessageFunc()  #系統訊息介面
     self.RightUI()  #權益數介面
     #ManuBar連結
     self.actionLogin.triggered.connect(self.Login.show)  #登入介面連結
     #ToolBar連結
     self.SysDetail.triggered.connect(self.SKMessage.show)
     self.Connectbtn.triggered.connect(self.ConnectFun)
     self.Disconnectbtn.triggered.connect(self.disconnectFun)
     # Tab內功能組連結
     self.commoditybtn.clicked.connect(self.commodityFnc)
     self.BidAct_btn.clicked.connect(self.BidFunc)
     self.AskAct_btn.clicked.connect(self.AskFunc)
     self.LastPrice_btn.clicked.connect(self.LastPriceFunc)
     self.PriceSpin.valueChanged.connect(self.GetPriceFunc)
     self.MarketPrice_btn.clicked.connect(self.MarketPriceFunc)
     self.LimitMarketPrice_btn.clicked.connect(self.LimitMarketPriceFunc)
     self.Order_btn.clicked.connect(self.Order_btn_Func)
     self.OrderCancel_btn.clicked.connect(self.OrderCancelFunc)
     self.ClosePositionAll_btn.clicked.connect(self.ClosePositionAllFunc)
Exemple #5
0
def send_order(buy_sell, b_async_order=False):
    print(datetime.datetime.now(), ' is sending order ......')
    try:
        '''
        Buy: sBuySell = 0 , Sell: sBuySell = 1
        ROD: sTradeType = 0, IOC: sTradeType = 1, FOK: sTradeType = 2
        非當沖: sDayTrade = 0, 當沖: sDayTrade = 1
        新倉: sNewClose = 0, 平倉: sNewClose = 1, 自動: sNewClose = 2
        盤中: sReserved = 0, T盤預約: sReserved = 1
        '''
        order = sk.FUTUREORDER()
        order.bstrFullAccount = global_account[0]
        order.bstrStockNo = 'MTX00'
        order.sBuySell = buy_sell
        order.sTradeType = 1
        order.sDayTrade = 0
        order.bstrPrice = 'M'
        order.nQty = 1
        order.sNewClose = 2
        order.sReserved = 0
        message, stat = skO.SendFutureOrderCLR(global_id, b_async_order, order)
        if stat == 0:
            print('【 SendingOrder successful 】')
        else:
            print('【 SendingOrder error code:' + str(stat) + '】')
    except Exception as e:
        print("error!", e)
    def __SendOrder_Click(self, bAsyncOrder):
        try:
            if self.__dOrder['boxBuySell'].get() == "買進":
                sBuySell = 0
            elif self.__dOrder['boxBuySell'].get() == "賣出":
                sBuySell = 1

            if self.__dOrder['boxPeriod'].get() == "ROD":
                sTradeType = 0
            elif self.__dOrder['boxPeriod'].get() == "IOC":
                sTradeType = 1
            elif self.__dOrder['boxPeriod'].get() == "FOK":
                sTradeType = 2

            if self.__dOrder['boxFlag'].get() == "非當沖":
                sDayTrade = 0
            elif self.__dOrder['boxFlag'].get() == "當沖":
                sDayTrade = 1

            if self.__dOrder['boxNewClose'].get() == "新倉":
                sNewClose = 0
            elif self.__dOrder['boxNewClose'].get() == "平倉":
                sNewClose = 1
            elif self.__dOrder['boxNewClose'].get() == "自動":
                sNewClose = 2

            if self.__dOrder['boxReserved'].get() == "盤中":
                sReserved = 0
            elif self.__dOrder['boxReserved'].get() == "T盤預約":
                sReserved = 1

            # 建立下單用的參數(FUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.FUTUREORDER()
            # 填入完整帳號
            oOrder.bstrFullAccount = self.__dOrder['boxAccount']
            # 填入期權代號
            oOrder.bstrStockNo = self.__dOrder['txtStockNo'].get()
            # 買賣別
            oOrder.sBuySell = sBuySell
            # ROD、IOC、FOK
            oOrder.sTradeType = sTradeType
            # 非當沖、當沖
            oOrder.sDayTrade = sDayTrade
            # 委託價
            oOrder.bstrPrice = self.__dOrder['txtPrice'].get()
            # 委託數量
            oOrder.nQty = int(self.__dOrder['txtQty'].get())
            # 新倉、平倉、自動
            oOrder.sNewClose = sNewClose
            # 盤中、T盤預約
            oOrder.sReserved = sReserved

            message, m_nCode = skO.SendFutureOrderCLR(self.__dOrder['txtID'],
                                                      bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode,
                                          "SendFutureOrderCLR",
                                          self.__dOrder['listInformation'])
        except Exception as e:
            messagebox.showerror("error!", e)
    def __SendCorrectPrice(self, bAsyncOrder):
        try:
            if self.boxBuySell.get() == "買進":
                nBuySell = 0
            elif self.boxBuySell.get() == "賣出":
                nBuySell = 1

            if self.boxNewClose.get() == "新倉":
                nNewClose = 0

            if self.boxPeriod.get() == "ROD":
                nTradeType = 0

            if self.boxSpecialTradeType.get() == "LMT(限價)":
                nSpecialTradeType = 0

            # 建立下單用的參數(OVERSEAFUTUREORDERGW)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.OVERSEAFUTUREORDERFORGW()
            # 填入完整帳號
            oOrder.bstrFullAccount = self.__dOrder['boxAccount']
            # 填入交易所代號
            oOrder.bstrExchangeNo = str(self.txtExchangeNo.get())
            # 填入期權代號
            oOrder.bstrStockNo = str(self.txtStockNo.get())
            # # 填入商品代號2
            # oOrder.bstrStockNo2 = self.txtStockNo2.get()
            # 近月商品年月
            oOrder.bstrYearMonth = str(self.txtYearMonth.get())
            # # 價差商品年月
            # oOrder.bstrYearMonth = self.__dOrder['txtYearMonth'].get()
            # 新委託價
            oOrder.bstrOrderPrice = str(self.txtOrder.get())
            # 新委託價分子
            oOrder.bstrOrderNumerator = str(self.txtOrderNumerator.get())
            # 新委託價分母
            oOrder.bstrOrderDenominator = str(self.txtOrderDenominator.get())
            # 委託書號
            oOrder.bstrBookNo = self.txtBookNo.get()
            # 買賣別
            oOrder.nBuySell = nBuySell
            # 新倉
            oOrder.nNewClose = nNewClose
            # ROD
            oOrder.nTradeType = nTradeType
            # LMT(限價)、MKT(市價)、STL(停損限價)、STP(停損市價)
            oOrder.nSpecialTradeType = nSpecialTradeType

            message, m_nCode = skO.OverSeaCorrectPriceByBookNo(
                Global.Global_IID, bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode,
                                          "OverSeaCorrectPriceSpreadByBookNo",
                                          self.__dOrder['listInformation'])
            if bAsyncOrder == False and m_nCode == 0:
                strMsg = "海期改價: " + str(message)
                self.__oMsg.WriteMessage(strMsg,
                                         self.__dOrder['listInformation'])

        except Exception as e:
            messagebox.showerror("error!", e)
Exemple #8
0
    def __SendOrder_Click(self, bAsyncOrder):
        try:
            if self.__dOrder['boxBuySell'].get() == "買進":
                sBuySell = 0
            elif self.__dOrder['boxBuySell'].get() == "賣出":
                sBuySell = 1

            if self.__dOrder['boxPeriod'].get() == "ROD":
                sTradeType = 0
            elif self.__dOrder['boxPeriod'].get() == "IOC":
                sTradeType = 1
            elif self.__dOrder['boxPeriod'].get() == "FOK":
                sTradeType = 2

            if self.__dOrder['boxNewClose'].get() == "新倉":
                sNewClose = 0
            elif self.__dOrder['boxNewClose'].get() == "平倉":
                sNewClose = 1
            elif self.__dOrder['boxNewClose'].get() == "自動":
                sNewClose = 2

            if self.__dOrder['boxReserved'].get() == "盤中":
                sReserved = 0
            elif self.__dOrder['boxReserved'].get() == "T盤預約":
                sReserved = 1

            # 建立下單用的參數(FUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.FUTUREORDER()
            # 填入完整帳號
            oOrder.bstrFullAccount = self.__dOrder['boxAccount']
            # 填入期權代號
            oOrder.bstrStockNo = self.__dOrder['txtStockNo'].get()
            # 買賣別
            oOrder.sBuySell = sBuySell
            # ROD、IOC、FOK
            oOrder.sTradeType = sTradeType
            # 新倉、平倉、自動
            oOrder.sNewClose = sNewClose
            # 委託價
            oOrder.bstrPrice = self.__dOrder['txtPrice'].get()
            # 委託數量
            oOrder.nQty = int(self.__dOrder['txtQty'].get())
            # 觸發價
            oOrder.bstrTrigger = self.__dOrder['txtTrigger'].get()
            # 盤中、T盤預約
            oOrder.sReserved = sReserved

            message, m_nCode = skO.SendOptionStopLossOrder(
                Global.Global_IID, bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode,
                                          "SendOptionStopLossOrder",
                                          self.__dOrder['listInformation'])
            if bAsyncOrder == False and m_nCode == 0:
                strMsg = "選擇權停損委託: " + str(message)
                self.__oMsg.WriteMessage(strMsg,
                                         self.__dOrder['listInformation'])
        except Exception as e:
            messagebox.showerror("error!", e)
 def OnNotifyQuote(self, sMarketNo, sStockidx):
     pStock = sk.SKSTOCK()
     skQ.SKQuoteLib_GetStockByIndex(sMarketNo, sStockidx, pStock)
     strMsg = pStock.bstrStockNo, pStock.bstrStockName, pStock.nOpen / math.pow(
         10, pStock.sDecimal), pStock.nHigh / math.pow(
             10, pStock.sDecimal), pStock.nLow / math.pow(
                 10, pStock.sDecimal), pStock.nClose / math.pow(
                     10, pStock.sDecimal), pStock.nTQty
     self.StockPrice.append(strMsg)
Exemple #10
0
 def OnNotifyQuote(self, sMarketNo, sStockidx):
     pStock = sk.SKSTOCK()
     skQ.SKQuoteLib_GetStockByIndex(sMarketNo, sStockidx, pStock)
     strMsg = '代碼:', pStock.bstrStockNo, '--名稱:', pStock.bstrStockName, '--開盤價:', pStock.nOpen / math.pow(
         10, pStock.sDecimal), '--最高:', pStock.nHigh / math.pow(
             10, pStock.sDecimal), '--最低:', pStock.nLow / math.pow(
                 10, pStock.sDecimal), '--成交價:', pStock.nClose / math.pow(
                     10, pStock.sDecimal), '--總量:', pStock.nTQty
     WriteMessage(strMsg, Gobal_Quote_ListInformation)
Exemple #11
0
    def __btnSendOrder_Click(self):
        if self.__dOrder['boxAccount'] == '':
            messagebox.showerror("error!", '請選擇期貨帳號!')
        else:
            try:
                if self.__dOrder['boxBuySell'].get() == "買進":
                    sBuySell = 0
                elif self.__dOrder['boxBuySell'].get() == "賣出":
                    sBuySell = 1

                if self.__dOrder['boxPeriod'].get() == "IOC":
                    sTradeType = 1
                elif self.__dOrder['boxPeriod'].get() == "FOK":
                    sTradeType = 2

                if self.__dOrder['boxNewClose'].get() == "新倉":
                    sNewClose = 0
                elif self.__dOrder['boxNewClose'].get() == "平倉":
                    sNewClose = 1
                elif self.__dOrder['boxNewClose'].get() == "自動":
                    sNewClose = 2

                if self.__dOrder['boxASYNC'].get() == "同步":
                    bAsyncOrder = 0
                elif self.__dOrder['boxASYNC'].get() == "非同步":
                    bAsyncOrder = 1

                # 建立下單用的參數(FUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
                oOrder = sk.FUTUREORDER()
                # 填入完整帳號
                oOrder.bstrFullAccount = self.__dOrder['boxAccount']
                # 填入期權代號
                oOrder.bstrStockNo = self.__dOrder['txtStockNo'].get()
                # 買賣別
                oOrder.sBuySell = sBuySell
                # IOC、FOK
                oOrder.sTradeType = sTradeType
                # 新倉、平倉、自動
                oOrder.sNewClose = sNewClose
                # 成交價
                oOrder.bstrDealPrice = self.__dOrder['txtDealPrice'].get()
                # 委託數量
                oOrder.nQty = int(self.__dOrder['txtQty'].get())
                # 觸發價
                oOrder.bstrTrigger = self.__dOrder['txtTrigger'].get()

                message, m_nCode = skO.SendOptionMITOrder(
                    Global.Global_IID, bAsyncOrder, oOrder)
                self.__oMsg.SendReturnMessage("Order", m_nCode,
                                              "SendOptionMITOrder",
                                              self.__dOrder['listInformation'])
                if bAsyncOrder == False and m_nCode == 0:
                    strMsg = "選擇權MIT委託: " + str(message)
                    self.__oMsg.WriteMessage(strMsg,
                                             self.__dOrder['listInformation'])
            except Exception as e:
                messagebox.showerror("error!", e)
    def __SendOrder_Click(self, bAsyncOrder):
        try:
            if self.boxBuyOrSell1.get() == "買進":
                sBuySell = 0
            elif self.boxBuyOrSell1.get() == "賣出":
                sBuySell = 1

            if self.boxBuyOrSell2.get() == "買進":
                sBuySell2 = 0
            elif self.boxBuyOrSell2.get() == "賣出":
                sBuySell2 = 1

            if self.TradeType.get() == "IOC":
                sTradeType = 1
            elif self.TradeType.get() == "FOK":
                sTradeType = 2

            if self.boxNewOrClose.get() == "新倉":
                sNewClose = 0
            elif self.boxNewOrClose.get() == "平倉":
                sNewClose = 1

            # 建立下單用的參數(FUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.FUTUREORDER()
            # 填入完整帳號
            oOrder.bstrFullAccount = self.__dOrder['boxAccount']
            # 填入期權代號1
            oOrder.bstrStockNo = self.txtMerchandise1.get()
            # 填入期權代號2
            oOrder.bstrStockNo2 = self.txtMerchandise2.get()
            # 買賣別1
            oOrder.sBuySell = sBuySell
            # 買賣別2
            oOrder.sBuySell2 = sBuySell2
            # IOC、FOK
            oOrder.sTradeType = sTradeType
            # 委託價
            oOrder.bstrPrice = self.txtPrice.get()
            # 委託數量
            oOrder.nQty = int(self.txtQty.get())
            # 新倉、平倉
            oOrder.sNewClose = sNewClose

            message, m_nCode = skO.SendDuplexOrder(Global.Global_IID,
                                                   bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode, "SendDuplexOrder",
                                          self.__dOrder['listInformation'])
            if bAsyncOrder == False and m_nCode == 0:
                strMsg = "複式單委託: " + str(message)
                self.__oMsg.WriteMessage(strMsg,
                                         self.__dOrder['listInformation'])

        except Exception as e:
            messagebox.showerror("error!", e)
Exemple #13
0
 def OnNotifyQuote(self, sMarketNo, sStockidx):
     self.parent.watchdog = 0
     pStock = sk.SKSTOCK()
     self.parent.skQ.SKQuoteLib_GetStockByIndex(sMarketNo, sStockidx,
                                                pStock)
     self.parent.get_price(
         self, pStock.bstrStockNo,
         pStock.nOpen / math.pow(10, pStock.sDecimal),
         pStock.nHigh / math.pow(10, pStock.sDecimal),
         pStock.nLow / math.pow(10, pStock.sDecimal),
         pStock.nClose / math.pow(10, pStock.sDecimal), pStock.nTQty)
Exemple #14
0
    def __SendOrder_Click(self, bAsyncOrder):
        try:
            if self.__dOrder['boxPrime'].get() == "上市櫃":
                sPrime = 0
            elif self.__dOrder['boxPrime'].get() == "興櫃":
                sPrime = 1

            if self.__dOrder['boxPeriod'].get() == "盤中":
                sPeriod = 0
            elif self.__dOrder['boxPeriod'].get() == "盤後":
                sPeriod = 1
            elif self.__dOrder['boxPeriod'].get() == "零股":
                sPeriod = 2

            if self.__dOrder['boxFlag'].get() == "現股":
                sFlag = 0
            elif self.__dOrder['boxFlag'].get() == "融資":
                sFlag = 1
            elif self.__dOrder['boxFlag'].get() == "融券":
                sFlag = 2
            elif self.__dOrder['boxFlag'].get() == "無券":
                sFlag = 3

            if self.__dOrder['boxBuySell'].get() == "買進":
                sBuySell = 0
            elif self.__dOrder['boxBuySell'].get() == "賣出":
                sBuySell = 1

            # 建立下單用的參數(STOCKORDER)物件(下單時要填股票代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.STOCKORDER()
            # 填入完整帳號
            oOrder.bstrFullAccount = self.__dOrder['boxAccount']
            # 填入股票代號
            oOrder.bstrStockNo = self.__dOrder['txtStockNo'].get()
            # 上市、上櫃、興櫃
            oOrder.sPrime = sPrime
            # 盤中、盤後、零股
            oOrder.sPeriod = sPeriod
            # 現股、融資、融券
            oOrder.sFlag = sFlag
            # 買賣別
            oOrder.sBuySell = sBuySell
            # 委託價
            oOrder.bstrPrice = self.__dOrder['txtPrice'].get()
            # 委託數量
            oOrder.nQty = int(self.__dOrder['txtQty'].get())

            message, m_nCode = skO.SendStockOrder(self.__dOrder['txtID'],
                                                  bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode, "SendStockOrder",
                                          self.__dOrder['listInformation'])
        except Exception as e:
            messagebox.showerror("error!", e)
Exemple #15
0
    def get_best5(self, sMarketNo, sStockIdx, nBestBid1, nBestBidQty1,
                  nBestBid2, nBestBidQty2, nBestBid3, nBestBidQty3, nBestBid4,
                  nBestBidQty4, nBestBid5, nBestBidQty5, nExtendBid,
                  nExtendBidQty, nBestAsk1, nBestAskQty1, nBestAsk2,
                  nBestAskQty2, nBestAsk3, nBestAskQty3, nBestAsk4,
                  nBestAskQty4, nBestAsk5, nBestAskQty5, nExtendAsk,
                  nExtendAskQty, nSimulate):
        '''
		sMarketNo,	市埸代碼
		sStockidx,	系統編碼後的特殊商品代號
		nBestBid1,nBestBidQty1,  買價1, 買量1
		nBestBid2,nBestBidQty2,  買價2, 買量2
		nBestBid3,nBestBidQty3,  買價3, 買量3
		nBestBid4,nBestBidQty4,  買價4, 買量4
		nBestBid5,nBestBidQty5,  買價5, 買量5
		nExtendBid,nExtendBidQty,延伸買價,延伸買量		
		nBestAsk1,nBestAskQty1,  買價1, 買量1
		nBestAsk2,nBestAskQty2,  買價2, 買量2
		nBestAsk3,nBestAskQty3,  買價3, 買量3
		nBestAsk4,nBestAskQty4,  買價4, 買量4
		nBestAsk5,nBestAskQty5,  買價5, 買量5
		nExtendAsk,nExtendAskQty,延伸賣價,延伸賣量		
		nSimulate 0:一般揭示 1:試算揭示
		'''
        #for debug only #
        if SHOW_DETAIL == True:
            print(sMarketNo, sStockIdx, nBestBid1, nBestBidQty1, nBestBid2,
                  nBestBidQty2, nBestBid3, nBestBidQty3, nBestBid4,
                  nBestBidQty4, nBestBid5, nBestBidQty5, nExtendBid,
                  nExtendBidQty, nBestAsk1, nBestAskQty1, nBestAsk2,
                  nBestAskQty2, nBestAsk3, nBestAskQty3, nBestAsk4,
                  nBestAskQty4, nBestAsk5, nBestAskQty5, nExtendAsk,
                  nExtendAskQty, nSimulate)
        #################
        if sStockIdx in self.best5_id_dict:
            pStock = sk.SKSTOCK()
            self.skQ.SKQuoteLib_GetStockByIndex(sMarketNo, sStockIdx, pStock)
            df = math.pow(10, pStock.sDecimal)
            bstrStockName = self.best5_id_dict[sStockIdx]
            self.best5_dict[bstrStockName] = (
                self.timestr, nBestBid1 / df, nBestBidQty1, nBestBid2 / df,
                nBestBidQty2, nBestBid3 / df, nBestBidQty3, nBestBid4 / df,
                nBestBidQty4, nBestBid5 / df, nBestBidQty5, nExtendBid / df,
                nExtendBidQty, nBestAsk1 / df, nBestAskQty1, nBestAsk2 / df,
                nBestAskQty2, nBestAsk3 / df, nBestAskQty3, nBestAsk4 / df,
                nBestAskQty4, nBestAsk5 / df, nBestAskQty5, nExtendAsk / df,
                nExtendAskQty, nSimulate)
Exemple #16
0
    def __SendOrder_Click(self, bAsyncOrder):
        try:
            if self.__dOrder['boxAccountType'].get() == "外幣專戶":
                nAccountType = 1
            elif self.__dOrder['boxAccountType'].get() == "台幣專戶":
                nAccountType = 2

            if self.__dOrder['boxExchangeNo'].get() == "美股":
                bstrExchangeNo = 'US'

            if self.__dOrder['boxBuySell'].get() == "買進":
                sBuySell = 0
            elif self.__dOrder['boxBuySell'].get() == "賣出":
                sBuySell = 1

            # 建立下單用的參數(FOREIGNORDER)物件(下單時要填股票代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.FOREIGNORDER()
            # 填入完整帳號
            oOrder.bstrFullAccount = self.__dOrder['boxAccount']
            # 專戶別
            oOrder.nAccountType = nAccountType
            # 扣款幣別(順序)
            oOrder.bstrCurrency1 = self.__dOrder['boxCurrency1'].get()
            oOrder.bstrCurrency2 = self.__dOrder['boxCurrency2'].get()
            oOrder.bstrCurrency3 = self.__dOrder['boxCurrency3'].get()
            # 交易所
            oOrder.bstrExchangeNo = bstrExchangeNo
            # 填入股票代號
            oOrder.bstrStockNo = self.__dOrder['txtStockNo'].get()
            # 買賣別
            oOrder.sBuySell = sBuySell
            # 委託價
            oOrder.bstrPrice = self.__dOrder['txtPrice'].get()
            # 委託數量
            oOrder.nQty = int(self.__dOrder['txtQty'].get())

            message, m_nCode = skO.SendForeignStockOrder(
                self.__dOrder['txtID'], bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode,
                                          "SendForeignStockOrder",
                                          self.__dOrder['listInformation'])
            if bAsyncOrder == False and m_nCode == 0:
                strMsg = "複委託: " + str(message)
                self.__oMsg.WriteMessage(strMsg,
                                         self.__dOrder['listInformation'])
        except Exception as e:
            messagebox.showerror("error!", e)
Exemple #17
0
    def __SendOrder_Click(self, bAsyncOrder):
        try:
            if self.__dOrder['boxBuySell'].get() == "買進":
                sBuySell = 0
            elif self.__dOrder['boxBuySell'].get() == "賣出":
                sBuySell = 1

            if self.__dOrder['boxPeriod'].get() == "ROD":
                sTradeType = 0
            elif self.__dOrder['boxPeriod'].get() == "IOC":
                sTradeType = 1
            elif self.__dOrder['boxPeriod'].get() == "FOK":
                sTradeType = 2

            if self.__dOrder['boxFlag'].get() == "非當沖":
                sDayTrade = 0
            elif self.__dOrder['boxFlag'].get() == "當沖":
                sDayTrade = 1

            # 建立下單用的參數(FUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.FUTUREORDER()
            # 填入完整帳號
            oOrder.bstrFullAccount = self.__dOrder['boxAccount']
            # 填入期權代號
            oOrder.bstrStockNo = self.__dOrder['txtStockNo'].get()
            # 買賣別
            oOrder.sBuySell = sBuySell
            # ROD、IOC、FOK
            oOrder.sTradeType = sTradeType
            # 非當沖、當沖
            oOrder.sDayTrade = sDayTrade
            # 委託價
            oOrder.bstrPrice = self.__dOrder['txtPrice'].get()
            # 委託數量
            oOrder.nQty = int(self.__dOrder['txtQty'].get())

            message, m_nCode = skO.SendFutureOrder(Global.Global_IID,
                                                   bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode, "SendFutureOrder",
                                          self.__dOrder['listInformation'])
            if bAsyncOrder == False and m_nCode == 0:
                strMsg = "期貨委託: " + str(message)
                self.__oMsg.WriteMessage(strMsg,
                                         self.__dOrder['listInformation'])
        except Exception as e:
            messagebox.showerror("error!", e)
    def __SendOrder_Click(self, bAsyncOrder):
        try:
            # 建立下單用的參數(FUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.FUTUREORDER()
            # 填入完整帳號
            oOrder.bstrFullAccount = self.__dOrder['boxAccount']
            # 填入期權代號
            oOrder.bstrStockNo = self.txtMerchandise1.get()
            # 委託數量
            oOrder.nQty = int(self.txtQty.get())

            message, m_nCode = skO.CoverAllProduct(Global.Global_IID,
                                                   bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode, "CoverAllProduct",
                                          self.__dOrder['listInformation'])

        except Exception as e:
            messagebox.showerror("error!", e)
Exemple #19
0
    def OnNotifyQuote(self, sMarketNo, sStockidx):
        pStock = sk.SKSTOCK()
        skQ.SKQuoteLib_GetStockByIndex(sMarketNo, sStockidx, pStock)

        Open = pStock.nOpen/math.pow(10, pStock.sDecimal)
        High = pStock.nHigh/math.pow(10, pStock.sDecimal)
        Low = pStock.nLow/math.pow(10, pStock.sDecimal)
        Close = pStock.nClose/math.pow(10, pStock.sDecimal)
        Qty = pStock.nTQty
        a = datetime.datetime.now()

        try:
            # modelSql.s_insert(a, pStock.bstrStockNo, pStock.bstrStockName, Open, High, Low, Close, Qty)
            # testdb.commit()
            strMsg = '代碼:', pStock.bstrStockNo, '--名稱:', pStock.bstrStockName, '--開盤價:', pStock.nOpen/math.pow(10, pStock.sDecimal), '--最高:', pStock.nHigh/math.pow(
                10, pStock.sDecimal), '--最低:', pStock.nLow/math.pow(10, pStock.sDecimal), '--成交價:', pStock.nClose/math.pow(10, pStock.sDecimal), '--總量:', pStock.nTQty
            print('OnNotifyQuote: ', a)
            print(strMsg)

        except mysql.connector.Error as error:
            print("Failed to update record to database rollback: {}".format(error))
Exemple #20
0
def daily_stop_loss_order(stop_loss_point=85):
    print('sending stop loss order ...')
    try:
        get_open_position()
        while True:
            pythoncom.PumpWaitingMessages()
            if global_now_open_position:
                break
            time.sleep(0.5)
        order = sk.FUTUREORDER()
        order.bstrFullAccount = global_account[0]
        order.bstrStockNo = 'MTX00'
        order.sTradeType = 1
        order.sDayTrade = 0
        order.bstrPrice = 'M'
        order.nQty = 1
        order.sNewClose = 2
        order.sReserved = 0
        if 'NO DATA' in global_now_open_position[0][0]:
            return
        elif global_now_open_position[0][3] == 'B':
            stop_loss_price = str(
                int(global_now_open_position[0][6]) / 1000 - stop_loss_point)
            print('Stop loss point: ', stop_loss_price)
            order.bstrTrigger = stop_loss_price
            order.sBuySell = 1
        elif global_now_open_position[0][3] == 'S':
            stop_loss_price = str(
                int(global_now_open_position[0][6]) / 1000 + stop_loss_point)
            print('Stop loss point: ', stop_loss_price)
            order.bstrTrigger = stop_loss_price
            order.sBuySell = 0

        message, stat = skO.SendFutureStopLossOrder(global_id, False, order)
        if stat == 0:
            print('【 SendFutureStopLossOrder successful 】')
        else:
            print('【 SendFutureStopLossOrder error code:' + str(stat) + '】')
    except Exception as e:
        print("error!", e)
 def Stock(self, account, stockNo, sBuySell, sPrice, sQty):
     # 建立下單用的參數(STOCKORDER)物件(下單時要填股票代號,買賣別,委託價,數量等等的一個物件)
     oOrder = sk.STOCKORDER()
     # 填入完整帳號
     oOrder.bstrFullAccount = account
     # 填入股票代號
     oOrder.bstrStockNo = stockNo
     # 上市櫃 = 0、興櫃 = 1
     oOrder.sPrime = 0  #sPrime
     # 盤中 = 0、盤後 = 1、零股 = 2
     oOrder.sPeriod = 0  #sPeriod
     # 現股 = 0、融資 = 1、融券 = 2
     oOrder.sFlag = 0  #sFlag
     # 買進 = 0、賣出 = 1
     if sBuySell == "Buy":
         oOrder.sBuySell = 0
     elif sBuySell == "Sell":
         oOrder.sBuySell = 1
     # 委託價、參考昨日收盤價 = M
     oOrder.bstrPrice = sPrice
     # 委託數量
     oOrder.nQty = int(sQty)
     return oOrder
Exemple #22
0
 def OnNotifyQuote(self, sMarketNo, sStockidx):
     pStock = sk.SKSTOCK()
     self.skQ.SKQuoteLib_GetStockByIndex(sMarketNo, sStockidx, pStock)
     if pStock.bstrStockNo not in self.stock_state:
         self.stock_state[pStock.bstrStockNo] = pStock
    def __SendOrder_Click(self, bAsyncOrder):
        try:
            # 建立下單用的參數(STOCKSTRATEGYORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.STOCKSTRATEGYORDER()
            # 填入完整帳號
            oOrder.bstrFullAccount = self.__dOrder['boxAccount']
            # 填入期權代號
            oOrder.bstrStockNo = self.txtStockNo.get()
            # 委託數量
            oOrder.nQty = int(self.txtQty.get())
            # 委託價
            oOrder.bstrOrderPrice = self.txtOrderPrice.get()
            # 停利條件設置
            if self.__TakeProfitFlag.get() == 1:
                oOrder.nTakeProfitFlag = 1
                if self.__TPPercnetradVar.get() == 0:
                    oOrder.nRDOTPPercent = 1
                    oOrder.bstrTPPercnet = self.__dOrder['txtTPPercnet'].get()
                elif self.__TPPercnetradVar.get() == 3:
                    oOrder.nRDOTPPercent = 0
                    oOrder.bstrTPTrigger = self.__dOrder['txtTPTrigger'].get()

                if self.__TPPriceradVar.get() == 0:
                    oOrder.nRDTPMarketPriceType = 2
                    oOrder.bstrTPOrderPrice = self.txtTPOrderPrice.get()
                elif self.__TPPriceradVar.get() == 2:
                    oOrder.nRDTPMarketPriceType = 1
            elif self.__TakeProfitFlag.get() == 0:
                oOrder.nTakeProfitFlag = 0
            # -----------------------------------------------------
            # 停損條件設置
            if self.__StopLossFlag.get() == 1:
                oOrder.nStopLossFlag = 1
                if self.__SLPercnetradVar.get() == 0:
                    oOrder.nRDOSLPercent = 1
                    oOrder.bstrSLPerent = self.__dOrder['txtSLPercnet'].get()
                elif self.__SLPercnetradVar.get() == 3:
                    oOrder.nRDOSLPercent = 0
                    oOrder.bstrSLTrigger = self.__dOrder['txtSLTrigger'].get()

                if self.__SLPriceradVar.get() == 0:
                    oOrder.nRDSLMarketPriceType = 2
                    oOrder.bstrSLOrderPrice = self.txtSLOrderPrice.get()
                elif self.__SLPriceradVar.get() == 2:
                    oOrder.nRDSLMarketPriceType = 1
            elif self.__StopLossFlag.get() == 0:
                oOrder.nStopLossFlag = 0
            # -----------------------------------------------------
            # 出清條件委託
            if self.__ClearAllFlag.get() == 1:
                oOrder.nClearAllFlag = 1
                oOrder.bstrClearCancelTime = self.boxHour.get(
                ) + self.boxMinute.get()
                if self.__ClearPriceradVar.get() == 0:
                    oOrder.nClearAllPriceType = 2
                    oOrder.bstrClearAllOrderPrice = self.txtClearOrderPrice.get(
                    )
                elif self.__ClearPriceradVar.get() == 2:
                    oOrder.nClearAllPriceType = 1
            elif self.__ClearAllFlag.get() == 0:
                oOrder.nClearAllFlag = 0
            # -----------------------------------------------------
            # 盤後條件設定
            if self.__FinalClearFlag.get() == 1:
                oOrder.sFinalClearFlag = 1
            elif self.__FinalClearFlag.get() == 0:
                oOrder.sFinalClearFlag = 0
            # -----------------------------------------------------
            if self.boxBuySell.get() == "現股買":
                oOrder.nBuySell = 0
            elif self.boxBuySell.get() == "無券賣出":
                oOrder.nBuySell = 1
            # -----------------------------------------------------
            # 建立下單用的參數(OVERSEAFUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
            # oOrder = sk.STOCKSTRATEGYORDER()
            # # 填入完整帳號
            # oOrder.bstrFullAccount =  self.__dOrder['boxAccount']
            # # 買賣別
            # oOrder.nBuySell = nBuySell
            # # 執行時間出清
            # oOrder.nClearAllFlag = nClearAllFlag
            # # 出清時間
            # oOrder.bstrClearCancelTime = bstrClearCancelTime
            # # 出清委託價方式
            # oOrder.nClearAllPriceType = nClearAllPriceType
            # # 出清委託價
            # oOrder.bstrClearAllOrderPrice = bstrClearAllOrderPrice
            # # 盤後定盤交易
            # oOrder.sFinalClearFlag = sFinalClearFlag
            #
            # # 出場停利條件
            # oOrder.nTakeProfitFlag = nTakeProfitFlag
            # # 停利類型
            # oOrder.nRDOTPPercent = nRDOTPPercent
            # # 停利漲幅百分比
            # oOrder.bstrTPPercnet = bstrTPPercnet
            # # 停利觸發價
            # oOrder.bstrTPTrigger = bstrTPTrigger
            # # 停利委託價方式
            # oOrder.nRDTPMarketPriceType = nRDTPMarketPriceType
            # # 停利委託價
            # oOrder.bstrTPOrderPrice = bstrTPOrderPrice
            #
            # # 出場停損條件
            # oOrder.nStopLossFlag = nStopLossFlag
            # # 停損類型
            # oOrder.nRDOSLPercent = nRDOSLPercent
            # # 停損百分比
            # oOrder.bstrSLPerent = bstrSLPerent
            # # 停損觸發價
            # oOrder.bstrSLTrigger = bstrSLTrigger
            # # 停損委託價方式
            # oOrder.nRDSLMarketPriceType = nRDSLMarketPriceType
            # # 停損委託價
            # oOrder.bstrSLOrderPrice = bstrSLOrderPrice

            message, m_nCode = skO.SendStockStrategyDayTrade(
                Global.Global_IID, bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode,
                                          "SendStockStrategyDayTrade",
                                          self.__dOrder['listInformation'])
            if bAsyncOrder == False and m_nCode == 0:
                strMsg = "現股當沖組合: " + str(message)
                self.__oMsg.WriteMessage(strMsg,
                                         self.__dOrder['listInformation'])
        except Exception as e:
            messagebox.showerror("error!", e)
    def __SendOrder_Click(self, bAsyncOrder):
        try:
            # 建立下單用的參數(STOCKSTRATEGYORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.STOCKSTRATEGYORDEROUT()
            # 填入完整帳號
            oOrder.bstrFullAccount = self.__dOrder['boxAccount']
            # 填入期權代號
            oOrder.bstrStockNo = self.txtStockNo.get()
            # 委託數量
            oOrder.nQty = int(self.txtQty.get())

            # 條件一參數設置
            if self.__GTEFlag.get() == 1:
                oOrder.nGTEFlag = 1
                oOrder.bstrGTETriggerPrice = self.txtGTETriggerPrice.get()
                if self.__GTEPriceradVar.get() == 0:
                    oOrder.nGTEMarketPrice = 0
                    oOrder.bstrGTEOrderPrice = self.txtGTEOrderPrice.get()
                elif self.__GTEPriceradVar.get() == 2:
                    oOrder.nGTEMarketPrice = 1
            elif self.__GTEFlag.get() == 0:
                oOrder.nGTEFlag = 0
            # -----------------------------------------------------
            # 條件二參數設置
            if self.__LTEFlag.get() == 1:
                oOrder.nLTEFlag = 1
                oOrder.bstrLTETriggerPrice = self.txtLTETriggerPrice.get()
                if self.__LTEPriceradVar.get() == 0:
                    oOrder.nLTEMarketPrice = 0
                    oOrder.bstrLTEOrderPrice = self.txtLTEOrderPrice.get()
                elif self.__LTEPriceradVar.get() == 2:
                    oOrder.nLTEMarketPrice = 1
            elif self.__LTEFlag.get() == 0:
                oOrder.nLTEFlag = 0
            # -----------------------------------------------------
            # 條件三參數設置
            if self.__ClearAllFlag.get() == 1:
                oOrder.nClearAllFlag = 1
                oOrder.bstrClearCancelTime = self.boxHour.get(
                ) + self.boxMinute.get()
                if self.__ClearPriceradVar.get() == 0:
                    oOrder.nClearAllPriceType = 2
                    oOrder.bstrClearAllOrderPrice = self.txtClearOrderPrice.get(
                    )
                elif self.__ClearPriceradVar.get() == 2:
                    oOrder.nClearAllPriceType = 1
            elif self.__ClearAllFlag.get() == 0:
                oOrder.nClearAllFlag = 0
            # -----------------------------------------------------
            # 盤後條件設定
            if self.__FinalClearFlag.get() == 1:
                oOrder.sFinalClearFlag = 1
            elif self.__FinalClearFlag.get() == 0:
                oOrder.sFinalClearFlag = 0
            # -----------------------------------------------------
            if self.boxBuySell.get() == "買進":
                oOrder.nBuySell = 0
            elif self.boxBuySell.get() == "賣出":
                oOrder.nBuySell = 1
            # -----------------------------------------------------
            if self.boxOrderType == "現股":
                oOrder.nOrderType = 0
            elif self.boxOrderType == "融資":
                oOrder.nOrderType = 1
            elif self.boxOrderType == "融券":
                oOrder.nOrderType = 2
            # -----------------------------------------------------

            # # 買賣別
            # oOrder.nBuySell = nBuySell
            # # 進場委託別
            # oOrder.nOrderType = nOrderType
            #
            # # 執行時間出清
            # oOrder.nClearAllFlag = nClearAllFlag
            # # 出清時間
            # oOrder.bstrClearCancelTime = bstrClearCancelTime
            # # 出清委託價方式
            # oOrder.nClearAllPriceType = nClearAllPriceType
            # # 出清委託價
            # oOrder.bstrClearAllOrderPrice = bstrClearAllOrderPrice
            #
            # # 盤後定盤交易
            # oOrder.sFinalClearFlag = sFinalClearFlag
            #
            # # 出場條件(大於)
            # oOrder.nGTEFlag = nGTEFlag
            # # (大於)觸發價
            # oOrder.bstrGTETriggerPrice = bstrGTETriggerPrice
            # # (大於)委託價
            # oOrder.bstrGTEOrderPrice = bstrGTEOrderPrice
            # # (大於)市價與否
            # oOrder.nGTEMarketPrice = nGTEMarketPrice
            #
            # # 出場條件(小於)
            # oOrder.nLTEFlag = nLTEFlag
            # # (小於)觸發價
            # oOrder.bstrLTETriggerPrice = bstrLTETriggerPrice
            # # (小於)委託價
            # oOrder.bstrLTEOrderPrice = bstrLTEOrderPrice
            # # (小於)市價與否
            # oOrder.nLTEMarketPrice = nLTEMarketPrice
            #
            # # 停損委託價方式
            # oOrder.nRDSLMarketPriceType = nRDSLMarketPriceType
            # # 停損委託價
            # oOrder.bstrSLOrderPrice = bstrSLOrderPrice

            message, m_nCode = skO.SendStockStrategyClear(
                Global.Global_IID, bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode,
                                          "SendStockStrategyClear",
                                          self.__dOrder['listInformation'])
            if bAsyncOrder == False and m_nCode == 0:
                strMsg = "出清策略: " + str(message)
                self.__oMsg.WriteMessage(strMsg,
                                         self.__dOrder['listInformation'])
        except Exception as e:
            messagebox.showerror("error!", e)
Exemple #25
0
        strMsg = skC.SKCenterLib_GetReturnCodeMessage(res)

        Logs('Order {} @ {}, Vol : {}, msg :{}'.format(sMer, sPrice, sVol,
                                                       strMsg))

        if res == 0:
            return True, resMsg
        else:
            return False, resMsg

    def FutureOCOOrder(self, async, sMer, sBuySell, sBuySell2, sTradeType,
                       sDayTrade, sPrice, sPrice2, sTrigger, sTrigger2, sVol,
                       sNewClose, sReserved):

        # 建立下單用的參數(FUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
        oOrder = sk.FUTUREOCOORDER()
        # 填入完整帳號
        oOrder.bstrFullAccount = self.account_list['future']
        # 填入期權代號
        oOrder.bstrStockNo = sMer
        # 買賣別
        oOrder.sBuySell = sBuySell
        oOrder.sBuySell2 = sBuySell2
        # ROD、IOC、FOK
        oOrder.sTradeType = sTradeType
        # 非當沖、當沖
        oOrder.sDayTrade = sDayTrade
        # 委託價
        oOrder.bstrPrice = sPrice
        oOrder.bstrPrice2 = sPrice2
        # 觸發價
Exemple #26
0
class Trader(object):
    def __init__(self, username, password, exchange, merchandise, isReal):

        self.isReal = isReal
        if not self.isReal:
            skC.SKCenterLib_ResetServer('morder1.capital.com.tw')
        # else:
        # 	skC.SKCenterLib_ResetServer('Order2.capital.com.tw')

        self.username = username
        self.password = password
        self.exchange = exchange
        self.merchandise = merchandise

        self.SKOrderEvent = SKOrderLibEvent(self)
        self.SKOrderLibEventHandler = comtypes.client.GetEvents(
            skO, self.SKOrderEvent)

        self.SKQuoteEvent = SKQuoteLibEvents(self)
        self.SKQuoteLibEventHandler = comtypes.client.GetEvents(
            skQ, self.SKQuoteEvent)

        self.SKReplyEvent = SKReplyLibEvent(self)
        self.SKReplyLibEventHandler = comtypes.client.GetEvents(
            skR, self.SKReplyEvent)

        self.account_list = None

        self.updater = select_updater(self.exchange)

        self.isRun = True
        self.isTrade = False

        self.tradeThread = threading.Thread()

        self.position = N_STR
        self.signal = N_STR

        self.tradeSignal = TradeSignal()

        self.cur_time = None

    def __pumpwait(self):

        while self.isTrade:
            pythoncom.PumpWaitingMessages()

    def __pumpwaitForT(self, t=1):

        for i in range(t):
            time.sleep(1)
            pythoncom.PumpWaitingMessages()

    def record(self):
        if self.__login():

            res = skQ.SKQuoteLib_EnterMonitor()
            strMsg = skC.SKCenterLib_GetReturnCodeMessage(res)
            Logs('Enter Monitor : {}'.format(strMsg))
            self.__pumpwaitForT(8)

            res = skQ.SKQuoteLib_RequestKLineAM(self.merchandise,
                                                sKLineType=0,
                                                sOutType=1,
                                                sTradeSession=0)
            strMsg = skC.SKCenterLib_GetReturnCodeMessage(res)
            Logs('Request K Line : {}'.format(strMsg))

            df_klin = self.SKQuoteEvent.GetKLineData()
            list_kline = df_klin.T.to_dict().values()

            mongo = DataMongo()
            mongo.insert('TWS', 'TX00', list_kline)

        else:
            Logs('Close Recording Program')

    def FutureOrder(self, async, sMer, sBuySell, sTradeType, sDayTrade, sPrice,
                    sVol, sNewClose, sReserved):

        # 建立下單用的參數(FUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
        oOrder = sk.FUTUREORDER()
        # 填入完整帳號
        oOrder.bstrFullAccount = self.account_list['future']
        # 填入期權代號
        oOrder.bstrStockNo = sMer
        # 買賣別
        oOrder.sBuySell = sBuySell
        # ROD、IOC、FOK
        oOrder.sTradeType = sTradeType
        # 非當沖、當沖
        oOrder.sDayTrade = sDayTrade
        # 委託價
        oOrder.bstrPrice = sPrice
        # 委託數量
        oOrder.nQty = sVol
        # 新倉、平倉、自動
        oOrder.sNewClose = sNewClose
        # 盤中、T盤預約
        oOrder.sReserved = sReserved

        resMsg, res = skO.SendFutureOrder(self.username, async, oOrder)
        strMsg = skC.SKCenterLib_GetReturnCodeMessage(res)

        Logs('Order {} @ {}, Vol : {}, msg :{}'.format(sMer, sPrice, sVol,
                                                       strMsg))

        if res == 0:
            return True, resMsg
        else:
            return False, resMsg
Exemple #27
0
    def __SendOrder_Click(self, bAsyncOrder):
        try:
            if self.__dOrder['boxCallPut'].get() == "CALL":
                sCallPut = 0
            elif self.__dOrder['boxCallPut'].get() == "PUT":
                sCallPut = 1

            if self.__dOrder['boxBuySell'].get() == "買進":
                sBuySell = 0
            elif self.__dOrder['boxBuySell'].get() == "賣出":
                sBuySell = 1

            if self.__dOrder['boxNewClose'].get() == "新倉":
                sNewClose = 0
            elif self.__dOrder['boxNewClose'].get() == "平倉":
                sNewClose = 1

            if self.__dOrder['boxFlag'].get() == "非當沖":
                sDayTrade = 0
            elif self.__dOrder['boxFlag'].get() == "當沖":
                sDayTrade = 1

            if self.__dOrder['boxPeriod'].get() == "ROD":
                sTradeType = 0

            if self.__dOrder['boxSpecialTradeType'].get() == "LMT(限價)":
                sSpecialTradeType = 0

            # 建立下單用的參數(OVERSEAFUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.OVERSEAFUTUREORDER()
            # 填入完整帳號
            oOrder.bstrFullAccount =  self.__dOrder['boxAccount']
            # 填入交易所代號
            oOrder.bstrExchangeNo = self.__dOrder['txtExchangeNo'] .get()
            # 填入期權代號
            oOrder.bstrStockNo = self.__dOrder['txtStockNo'].get()
            # 近月商品年月
            oOrder.bstrYearMonth = self.__dOrder['txtYearMonth'].get()
            # 履約價
            oOrder.bstrStrikePrice = self.__dOrder['txtStrikePrice'].get()
            # Call Put
            oOrder.sCallPut = sCallPut
            # 委託數量
            oOrder.nQty = int(self.__dOrder['txtQty'].get())
            # 委託價
            oOrder.bstrOrder = self.__dOrder['txtOrder'].get()
            # 委託價分子
            oOrder.bstrOrderNumerator = self.__dOrder['txtOrderNumerator'].get()
            # 買賣別
            oOrder.sBuySell = sBuySell
            # 新倉、平倉
            oOrder.sNewClose = sNewClose
            # 非當沖、當沖
            oOrder.sDayTrade = sDayTrade
            # ROD
            oOrder.sTradeType = sTradeType
            # LMT(限價)
            oOrder.sSpecialTradeType = sSpecialTradeType
            # 觸發價
            oOrder.bstrTrigger = self.__dOrder['txtTrigger'].get()
            # 觸發價分子
            oOrder.bstrTriggerNumerator = self.__dOrder['txtTriggerNumerator'].get()

            message, m_nCode = skO.SendOverSeaOptionOrder(Global.Global_IID, bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode, "SendOverSeaOptionOrder", self.__dOrder['listInformation'])
            if bAsyncOrder == False and m_nCode == 0:
                strMsg = "海選委託: " + str(message)
                self.__oMsg.WriteMessage( strMsg, self.__dOrder['listInformation'])
        except Exception as e:
            messagebox.showerror("error!", e)
Exemple #28
0
    def __SendOrder_Click(self, bAsyncOrder):
        try:
            if self.__dOrder['boxBuySell'].get() == "買進":
                sBuySell = 0
            elif self.__dOrder['boxBuySell'].get() == "賣出":
                sBuySell = 1

            if self.__dOrder['boxNewClose'].get() == "新倉":
                sNewClose = 0

            if self.__dOrder['boxFlag'].get() == "非當沖":
                sDayTrade = 0
            elif self.__dOrder['boxFlag'].get() == "當沖":
                sDayTrade = 1

            if self.__dOrder['boxPeriod'].get() == "ROD":
                sTradeType = 0

            if self.__dOrder['boxSpecialTradeType'].get() == "LMT(限價)":
                sSpecialTradeType = 0
            elif self.__dOrder['boxSpecialTradeType'].get() == "MKT(市價)":
                sSpecialTradeType = 1
            elif self.__dOrder['boxSpecialTradeType'].get() == "STL(停損限價)":
                sSpecialTradeType = 2
            elif self.__dOrder['boxSpecialTradeType'].get() == "STP(停損市價)":
                sSpecialTradeType = 3

            # 建立下單用的參數(OVERSEAFUTUREORDER)物件(下單時要填商品代號,買賣別,委託價,數量等等的一個物件)
            oOrder = sk.OVERSEAFUTUREORDER()
            # 填入完整帳號
            oOrder.bstrFullAccount = self.__dOrder['boxAccount']
            # 填入交易所代號
            oOrder.bstrExchangeNo = self.__dOrder['txtExchangeNo'].get()
            # 填入期權代號
            oOrder.bstrStockNo = self.__dOrder['txtStockNo'].get()
            # 近月商品年月
            oOrder.bstrYearMonth = self.__dOrder['txtYearMonth'].get()
            # 委託價
            oOrder.bstrOrder = self.__dOrder['txtOrder'].get()
            # 委託價分子
            oOrder.bstrOrderNumerator = self.__dOrder['txtOrderNumerator'].get(
            )
            # 觸發價
            oOrder.bstrTrigger = self.__dOrder['txtTrigger'].get()
            # 觸發價分子
            oOrder.bstrTriggerNumerator = self.__dOrder[
                'txtTriggerNumerator'].get()
            # 委託數量
            oOrder.nQty = int(self.__dOrder['txtQty'].get())

            # 買賣別
            oOrder.sBuySell = sBuySell
            # 新倉
            oOrder.sNewClose = sNewClose
            # 非當沖、當沖
            oOrder.sDayTrade = sDayTrade
            # ROD
            oOrder.sTradeType = sTradeType
            # LMT(限價)、MKT(市價)、STL(停損限價)、STP(停損市價)
            oOrder.sSpecialTradeType = sSpecialTradeType

            message, m_nCode = skO.SendOverSeaFutureOrder(
                self.__dOrder['txtID'], bAsyncOrder, oOrder)
            self.__oMsg.SendReturnMessage("Order", m_nCode,
                                          "SendOverSeaFutureOrder",
                                          self.__dOrder['listInformation'])
        except Exception as e:
            messagebox.showerror("error!", e)