Esempio n. 1
0
    def saveAllItems(self):
        watchlist = []
        filename = globals.datapath + '/watchlist.dat'
        for i in range(0, 50):
            item0 = self.tbWatchList.item(i, 0)
            item1 = self.tbWatchList.item(i, 1)
            item2 = self.tbWatchList.item(i, 2)
            d0 = d1 = d2 = ''
            if(item0):
                d0 = item0.data(Qt.DisplayRole)
            if(d0 and item1):
                d1 = item1.data(Qt.DisplayRole)
            if(item2):
                d2 = item2.data(Qt.DisplayRole)

            scode = stock.normalizeStockCode(d0)
            sname = stock.getStockName(scode)
            if(sname):
                watchlist.append([d0, d1, d2])

        #write to file begin
        try:
            f = open(filename, 'wb')
        except IOError:
            exc_type, exc_value = sys.exc_info()[:2]
            errmsg = '{}: {}'.format(exc_type.__name__, exc_value)
            output(errmsg, 'red')
            return False
        
        pickle.dump(watchlist, f)
        f.close() 
Esempio n. 2
0
    def handleCellChanged(self, row, column):
        if(column == 0):
            item0 =  self.tbWatchList.item(row, 0)
            stockcode = item0.data(Qt.DisplayRole)
            if(stockcode):
                norcode = stock.normalizeStockCode(stockcode)
                stockname = stock.getStockName(norcode)
                if(norcode):
                    if(norcode != stockcode):
                        item0 = QTableWidgetItem(norcode)
                        self.tbWatchList.setItem(row, 0, item0)
                    
                    if(stockname):
                        item1 = QTableWidgetItem(stockname)
                    else:
                        item1 = QTableWidgetItem('')

                    item1.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
                    self.tbWatchList.setItem(row, 1, item1) 

            self.saveAllItems()

        if(column == 2):
            item2 =  self.tbWatchList.item(row, 2)
            if(item2 and item2.data(Qt.DisplayRole)):
                self.saveAllItems()
Esempio n. 3
0
def run(subcmd, params):
    chart = globals.mainwin.chart
    stocklist = stock.getStockList()

    if(subcmd == 'di'):
        filterResults = []
        di = indicators.di.Di()

        utils.output('开始di条件过滤')
        prefixstr = 'filter di条件过滤:'
        totalstock = len(stocklist)
        cnt = 0
        start_time = datetime.datetime.now()
        for stockcode in stocklist:
            cnt +=1
            stockcode = stock.normalizeStockCode(stockcode)
            end_time = datetime.datetime.now()
            diffStr = '{}'.format(end_time - start_time)
            outstr = '{} {}/{} 当前代码:{} 符合条件:{} ({})'.format(prefixstr, cnt, totalstock, stockcode, len(filterResults), diffStr)
            utils.overwrite(outstr, prefixstr)
            stockdata = stock.getStockDayDataQianFuQuan(stockcode)
            stockdata = stockdata[-500:]
            didata = di.calculateData(stockdata)
            QCoreApplication.processEvents()
            if(didata[-1] and didata[-1].get('tip')):
                filterResults.append({'code':stockcode, 'date':didata[-1]['date']})

        
        dataArr = []

        for row in filterResults:
            scode = row['code']
            sdate = row['date']
            row=[]
            row.append(scode)
            row.append(stock.getStockName(scode))
            row.append(sdate)
            dataArr.append(row)
    
        #write to file begin
        filename = globals.datapath + '/lastFilterResult.dat'
        try:
            f = open(filename, 'wb')
        except IOError:
            exc_type, exc_value = sys.exc_info()[:2]
            errmsg = '{}: {}'.format(exc_type.__name__, exc_value)
            output(errmsg, 'red')
            return False
        
        pickle.dump(dataArr, f)
        f.close() 
        #write to file end
        
        tablemodel = stockfilterresultdlg.FilterResultModel(dataArr, None)
        tbResults = globals.mainwin.stockfilterresultdlg.tbResults
        tbResults.setModel(tablemodel)
        globals.mainwin.windowStockFilterResult()
Esempio n. 4
0
    def drawCandleSticks(self, painter):
        cnt = 0
        for row in self.kdispdata:
            kposx = self.kleft + cnt*self.kwidth
            kposy_open = self.kmarginh + (1 - (row['open'] - self.pricelow)/self.pricerange) * self.krange
            kposy_high = self.kmarginh + (1 - (row['high'] - self.pricelow)/self.pricerange) * self.krange
            kposy_low = self.kmarginh + (1 - (row['low'] - self.pricelow)/self.pricerange) * self.krange
            kposy_close = self.kmarginh + (1 - (row['close'] - self.pricelow)/self.pricerange) * self.krange
    
            kcolor = 'black'
            painter.setPen(QColor(0, 0, 0))
            if(row['close'] > row['open']):
                kcolor = 'red'
                painter.setPen(QColor(255, 0, 0))
            elif(row['close'] < row['open']):
                kcolor = 'green'
                painter.setPen(QColor(0, 128, 0))


            painter.drawLine(QPointF(kposx, kposy_high), QPointF(kposx, kposy_low))
            if(self.zoom>0.3):
                if(kcolor == 'black'):
                    painter.drawLine(QPointF(kposx-self.kwidth*0.3, kposy_open), QPointF(kposx+self.kwidth*0.3, kposy_close))
                elif(kcolor == 'green'):
                    painter.fillRect(QRectF(QPointF(kposx-self.kwidth*0.3, kposy_open), QPointF(kposx+self.kwidth*0.3, kposy_close)), QColor(0,128,0))
                    painter.drawRect(QRectF(QPointF(kposx-self.kwidth*0.3, kposy_open), QPointF(kposx+self.kwidth*0.3, kposy_close)))
                elif(kcolor == 'red'):
                    painter.fillRect(QRectF(QPointF(kposx-self.kwidth*0.3, kposy_close), QPointF(kposx+self.kwidth*0.3, kposy_open)), QColor(255,255,255))
                    painter.drawRect(QRectF(QPointF(kposx-self.kwidth*0.3, kposy_close), QPointF(kposx+self.kwidth*0.3, kposy_open)))
            
            cnt += 1

        #update title
        maintitle = '{}'.format(self.stockcode)
        stockname = stock.getStockName(self.stockcode)
        if(stockname):
            maintitle = '{} {}'.format(stockname, self.stockcode)
        
        self.maintitle = []
        self.maintitle.append({'x' : 3, 'y':15, 'text':maintitle, 'color':QColor(0, 0, 0)})