Exemplo n.º 1
0
    def __init__(self, refDict, **kwargs):
        super(SFieldSetting, self).__init__(**kwargs)

        self.app = refDict.get(CONSTS.S_APP)
        self.sysConfDict = self.app.confDict.get(CONSTS.SYS_CONF_DICT)
        
        filePath = os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "stkfields_setting.ini")
        alist = sutil.getListFromFile(filePath)
        idDict = {}
        self.nameDict = {}
        seqList = []
        for astr in alist:
            tmpList = astr.strip().split(",")
            if len(tmpList) < 2:
                continue
            if tmpList[0] == "_SEQ_":
                seqList = tmpList[1].strip().split("|")
            else:
                idDict[tmpList[0]] = tmpList[1]
                self.nameDict[tmpList[1]] = tmpList[0]
        
        for seqId in seqList:
            adict = {}
            adict["text"] = idDict.get(seqId, "")
            self.rightrv_id.data.append(adict)
Exemplo n.º 2
0
    def _finishedQueryStktbl(self, gwResult):
        filePath = os.path.join(
            os.path.dirname(__file__),
            ".." + os.sep + "rowdata" + os.sep + "stktbl1TTW.dat")
        alist = sutil.getListFromFile(filePath)
        alist.pop(0)
        tmpList = None
        for astr in alist:
            if astr == "" or len(astr) == 0:
                continue
            tmpList = astr.strip().split("|")
            if len(tmpList) < 2:
                continue
            self.app.stkNameDict[tmpList[0]] = tmpList[1]

        refParam = {}
        refParam[CONSTS.S_APP] = self.app
        refParam["SelfGroupIndex"] = self.selfgroup_index
        refParam["SelfGroupName"] = self.selfgroup_id.text
        refParam["SelfStkList"] = list(self.selfStkList)
        stcLayout = SelfStkSetting(refParam)
        self.stcLayout = stcLayout
        self.self_setting_popup = SPopup(title="自選設定",
                                         content=stcLayout,
                                         size_hint=(None, None),
                                         size=(360, 480),
                                         auto_dismiss=False)
        stcLayout.ensurebtn_id.bind(on_press=self._changeGroup)
        stcLayout.cancelbtn_id.bind(on_press=self._self_setting_popup_dismiss)
        self.self_setting_popup.title_font = CONSTS.FONT_NAME
        self.self_setting_popup.open()
Exemplo n.º 3
0
 def __init__(self, paramDict, **kwargs):
     super(SExecTrade, self).__init__(**kwargs)
     
     self.paramDict = paramDict
     self.app = self.paramDict.get(CONSTS.S_APP)
     self.sysConfDict = self.app.confDict.get(CONSTS.SYS_CONF_DICT)
     self.strategyDict = {}
     
     self.rowdata_id.bind(focus=self.onRowdataFocus)
     
     self.strategyDropDown = SStrategyDropDown()
     firstRecord = True
     strategyList = None
     filePath = os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "strategy.ini")
     alist = sutil.getListFromFile(filePath)
     for astr in alist:
         strategyList = astr.strip().split(",")
         if len(strategyList) < 2:
             continue
         if firstRecord:
             firstRecord = False
             self.strategy_id.text = strategyList[0]
         self.strategyDict[strategyList[0]] = strategyList
         abtn = SButton(text=strategyList[0])
         abtn.size_hint_y = None
         abtn.height = 30
         abtn.bind(on_release=self.strategyDropDown.select)
         self.strategyDropDown.add_widget(abtn)
         
     self.strategy_id.bind(on_release=self.strategyDropDown.open)
     self.strategyDropDown.bind(on_select=self.strategySelect)
     
     self.savefile_id.bind(focus=self.onSavefileFocus)
Exemplo n.º 4
0
    def __init__(self, paramDict, **kwargs):
        super(SStrategy, self).__init__(**kwargs)
        
        self.paramDict = paramDict
        self.app = self.paramDict.get(CONSTS.S_APP)        

        self.size_hint = (1, 1)
        self.orientation = "vertical"

        headLayout = STableGridLayout(cols=3, rows=1, spacing=2, size_hint=(1, None), height=30)
        headLabel = SHeadLabel(text="功能", size_hint=(.15, 1))
        headLabel.halign: 'center'
        headLabel.valign: 'middle'
        headLayout.add_widget(headLabel)
        headLabel = SHeadLabel(text="策略名稱", size_hint=(.6, 1))
        headLabel.halign: 'center'
        headLabel.valign: 'middle'
        headLayout.add_widget(headLabel)
        headLabel = SHeadLabel(text="檔案名稱", size_hint=(.25, 1))
        headLabel.halign: 'center'
        headLabel.valign: 'middle'
        headLayout.add_widget(headLabel)
        self.add_widget(headLayout)
        
        gapLayout = STableBoxLayout(size_hint=(1, None), height=2)
        self.add_widget(gapLayout)
        
        self.maxIndex = 0
        self.def_ids = {}
        
        slview = STableScrollView()
        slview.size_hint = (1, None)
        slview.size = (540, 350)
        self.contentLayout = STableGridLayout(cols=3, spacing=2, size_hint_y=None)
        # Make sure the height is such that there is something to scroll.
        self.contentLayout.bind(minimum_height=self.contentLayout.setter('height'))
        
        filePath = os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "strategy.ini")
        if not os.path.exists(filePath):
            with open(filePath, 'w'): pass        
            
        alist = sutil.getListFromFile(filePath)
        for astr in alist:
            tmpList = astr.strip().split(",")
            if len(tmpList) < 2:
                continue
            self.addListRow(tmpList, False)
            self.maxIndex += 1            

        self.addInsertRow(str(self.maxIndex))
        slview.add_widget(self.contentLayout)
        
        self.add_widget(slview)
        
        closeLayout = BoxLayout(size_hint=(1, None), height=36)
        self.closebtn_id = SButton(text="關閉", size_hint=(1, 1))
        closeLayout.add_widget(self.closebtn_id)
        self.add_widget(closeLayout)
Exemplo n.º 5
0
    def _technicalDropDown(self):
        self.techDropDown = DropDown()
        self.techTypeDict = {}
        filePath = os.path.join(
            os.path.dirname(__file__),
            ".." + os.sep + "conf" + os.sep + "formula_id.ini")
        alist = sutil.getListFromFile(filePath)
        firstRecord = True
        aKey = None
        aValue = None
        for astr in alist:
            aIdx = astr.find("=")
            if aIdx == -1:
                continue
            aKey = astr[:aIdx]
            aValue = astr[aIdx + 1:]
            if firstRecord:
                firstRecord = False
                self.techType_id.text = aValue
                self.techType_index = int(aKey)
            abtn = SInfoButton(extra_info=int(aKey), text=aValue)
            abtn.size_hint_y = None
            abtn.height = 30
            abtn.bind(on_release=self.techDropDown.select)
            self.techDropDown.add_widget(abtn)
            self.techTypeDict[str(abtn.extra_info)] = abtn

        self.techType_id.bind(on_release=self.techDropDown.open)
        self.techDropDown.bind(on_select=self._techDropDownSelect)

        self.formulaMapping = {}
        filePath = os.path.join(
            os.path.dirname(__file__),
            ".." + os.sep + "conf" + os.sep + "formula_mapping.ini")
        alist = sutil.getListFromFile(filePath)
        for astr in alist:
            aIdx = astr.find("=")
            if aIdx == -1:
                continue
            aKey = astr[:aIdx]
            aValue = astr[aIdx + 1:]
            self.formulaMapping[aKey] = aValue.split(",")
Exemplo n.º 6
0
    def execTradeEvent(self, instance):

        rowdataName = self.etLayout.rowdata_id.text
        strategyName = self.etLayout.strategy_id.text
        savefileName = self.etLayout.savefile_id.text
        if rowdataName == "":
            self.app.showErrorView(True, CONSTS.ERR_UNSELECT_HISTORY_DATA)
            return
        elif strategyName == "":
            self.app.showErrorView(True, CONSTS.ERR_UNSELECT_STRATEGY)
            return
        elif savefileName == "":
            self.app.showErrorView(True, CONSTS.ERR_UNSELECT_SAVEFILE)
            return

        strategy_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__),
                         ".." + os.sep + "conf" + os.sep + "strategy"))
        strategyData = None
        if strategyName != "":
            alist = sutil.getListFromFile(
                os.path.join(os.path.dirname(__file__),
                             ".." + os.sep + "conf" + os.sep + "strategy.ini"))
            for astr in alist:
                strategyList = astr.strip().split(",")
                if len(strategyList) < 2:
                    continue
                if strategyName == strategyList[0]:
                    strategyData = strategyList[1]
            isExistFlag = True
            if strategyData != None:
                filePath = os.path.join(strategy_dir, strategyData)
                if os.path.exists(filePath) != True:
                    isExistFlag = False
            else:
                isExistFlag = False
            if isExistFlag == False:
                msgCodeDict = self.app.confDict.get(CONSTS.MSG_CODE_DICT)
                msgText = msgCodeDict.get(CONSTS.ERR_STRATEGY_FILE_NOT_FOUND)
                self.app.showErrorView(False, strategyName, msgText)
                return

        userConf = sutil.getDictFromFile(
            os.path.join(os.path.dirname(__file__),
                         ".." + os.sep + "conf" + os.sep + "user.ini"))
        rowdata_dir = userConf.get("ROWDATA_DIR")
        data_dir = userConf.get("BACKTEST_DIR")

        self.rowdata_file = os.path.join(rowdata_dir, rowdataName)
        self.strategy_file = os.path.join(strategy_dir, strategyData)
        self.savefile_file = os.path.join(data_dir, savefileName)

        self.doPtradeEvent()
Exemplo n.º 7
0
    def _klineDataTypeDropDown(self):
        """
        資料類型:
        1.日線(ABGW_PRICEDATA_DAY)
        2.周線(ABGW_PRICEDATA_WEEK)
        3.月線(ABGW_PRICEDATA_MONTH)
        4.季線(ABGW_PRICEDATA_QUARTER)
        5.半年線(ABGW_PRICEDATA_HYEAR)
        6.年線(ABGW_PRICEDATA_YEAR)
        10.1分線(ABGW_PRICEDATA_MIN)
        11.5分線(ABGW_PRICEDATA_MIN5)
        12.10分線(ABGW_PRICEDATA_MIN10)
        13.15分線(ABGW_PRICEDATA_MIN15)
        14.20分線(ABGW_PRICEDATA_MIN20)
        15.30分線(ABGW_PRICEDATA_MIN30)
        16.60分線(ABGW_PRICEDATA_MIN60)
        100.往前復權基準值(ABGW_PRICEDATA_FRBASE)
        200.往後復權基準值(ABGW_PRICEDATA_BRBASE)
        復權需加上復權基準值,如 往前復權日線: 101,往後復權日線: 201
        """
        self.kdtDropDown = DropDown()
        self.dataTypeDict = {}
        filePath = os.path.join(
            os.path.dirname(__file__),
            ".." + os.sep + "conf" + os.sep + "kline_datatype.ini")
        alist = sutil.getListFromFile(filePath)
        firstRecord = True
        for astr in alist:
            aIdx = astr.find("=")
            if aIdx == -1:
                continue
            aKey = astr[:aIdx]
            aValue = astr[aIdx + 1:]
            if firstRecord:
                firstRecord = False
                self.klineDataType_id.text = aValue
                self.klineDataType_index = int(aKey)
            abtn = SInfoButton(extra_info=int(aKey), text=aValue)
            abtn.size_hint_y = None
            abtn.height = 30
            abtn.bind(on_release=self.kdtDropDown.select)
            self.kdtDropDown.add_widget(abtn)
            self.dataTypeDict[str(abtn.extra_info)] = abtn

        self.klineDataType_id.bind(on_release=self.kdtDropDown.open)
        self.kdtDropDown.bind(on_select=self._kdtDropDownSelect)
Exemplo n.º 8
0
    def saveData(self):
        stkListStr = ""
        for stkId in self.selfStkList:
            stkListStr += stkId + "|"
        if len(stkListStr) != 0:
            stkListStr = stkListStr[0:-1]

        filePath = os.path.join(
            os.path.dirname(__file__),
            ".." + os.sep + "conf" + os.sep + "self_stkquote.ini")
        alist = sutil.getListFromFile(filePath)
        with open(filePath, 'w', encoding='utf-8') as f:
            for tmpStr in alist:
                aList = tmpStr.split(",")
                if int(aList[0]) == self.selfgroup_index:
                    astr = str(
                        self.selfgroup_index
                    ) + "," + self.selfgroup_name_id.text + "," + stkListStr + "\n"
                else:
                    astr = tmpStr + "\n"
                f.write(astr)
Exemplo n.º 9
0
    def saveData(self):
        filePath = os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "stkfields_setting.ini")
        alist = sutil.getListFromFile(filePath)        
        with open(filePath, 'w', encoding = 'utf-8') as f:
            for tmpStr in alist:
                tmpList = tmpStr.strip().split(",")
                if len(tmpList) < 2:
                    astr = tmpStr + "\n"
                    f.write(astr)
                    continue
                if tmpList[0] == "_SEQ_":
                    aFieldId = None
                    self.fieldSeqList = []
                    astr = "_SEQ_,"
                    for aDict in self.rightrv_id.data:
                        aFieldId = self.nameDict.get(aDict.get("text"))
                        astr += aFieldId + "|"
                        self.fieldSeqList.append(aFieldId)
                    astr = astr[0:-1] + "\n"
                else:
                    astr = tmpStr + "\n"           

                f.write(astr)
Exemplo n.º 10
0
    def __init__(self, paramDict, **kwargs):
        super(SelfStkQuote, self).__init__(**kwargs)

        self.paramDict = paramDict
        self.app = self.paramDict.get(CONSTS.S_APP)

        self.quoteDataDict = {}
        self.selfDict = {}
        self.selfDropDown = SSelfDropDown()
        self.dropDownDict = {}
        firstRecord = True
        selfGroupList = None
        filePath = os.path.join(
            os.path.dirname(__file__),
            ".." + os.sep + "conf" + os.sep + "self_stkquote.ini")
        alist = sutil.getListFromFile(filePath)
        for astr in alist:
            selfGroupList = astr.strip().split(",")
            if len(selfGroupList) < 3:
                continue
            if firstRecord:
                firstRecord = False
                self.selfgroup_id.text = selfGroupList[1]
                self.selfgroup_index = int(selfGroupList[0])
            self.selfDict[int(selfGroupList[0])] = selfGroupList
            abtn = SInfoButton(extra_info=int(selfGroupList[0]),
                               text=selfGroupList[1])
            abtn.size_hint_y = None
            abtn.height = 30
            abtn.bind(on_release=self.selfDropDown.select)
            self.selfDropDown.add_widget(abtn)
            self.dropDownDict[str(abtn.extra_info)] = abtn

        self.selfgroup_id.bind(on_release=self.selfDropDown.open)
        self.selfDropDown.bind(on_select=self.selfSelect)

        self.stkidList = []
        self.num_per_page = NUM_PER_PAGE
        self.page_num = 1
        self.max_page_num = 1

        self.page_id.bind(on_text_validate=self._on_page_id_enter)

        filePath = os.path.join(
            os.path.dirname(__file__),
            ".." + os.sep + "conf" + os.sep + "stkfields_setting.ini")
        alist = sutil.getListFromFile(filePath)
        headDefineDict = {}
        for astr in alist:
            astrList = astr.strip().split(",")
            if len(astrList) < 2:
                continue
            headDefineDict[astrList[0]] = astrList[1]
        headDict = {}
        headDict["id"] = headDefineDict.get("id")  #SID
        headDict["name"] = headDefineDict.get("name")  #SNT
        seqStr = headDefineDict.get("_SEQ_")
        seqStrList = seqStr.split("|")
        for headId in seqStrList:
            headDict[headId] = headDefineDict.get(headId)
        self.stkquote = StkQuote({
            CONSTS.S_APP: self.app,
            'headDict': headDict,
            'dispIdName': True
        })

        self.body_layout.remove_widget(self.content_layout)
        self.content_layout = self.stkquote
        self.content_layout.size_hint = (1, 1)
        self.body_layout.add_widget(self.content_layout)

        Clock.schedule_once(self.doQuoteStart, .5)  #此段用意為讓畫面先顯示出來,再做後續的動作