示例#1
0
 def historicalDataEnd(self, reqId: int, start: str, end: str):
     """ Marks the ending of the historical bars reception. """
     EWrapper.historicalDataEnd(self, reqId, start, end)
     if self._file:
         self._file.close()
         self._file = None
     self.tws2gui.put('END')
示例#2
0
    def historicalDataEnd(self, reqId: int, start: str, end: str):
        """ Marks the ending of the historical bars reception. """
        #msg=toMessage('DownloadFinish')
        #self.toGui.put(msg)

        EWrapper.historicalDataEnd(self, reqId, start, end)

        #translate back
        #print("translate back",reqId,self.nextIDconID[reqId])
        conID=self.nextIDconID[reqId]
        #print('reqId after transalation ',conID)

        if self.downloadHistInfo[conID].whatToDownload=='histnew5secOneTime':
            msg = toMessage('5secHist')
            #we must send the reaId besides the list
            msg.obj =[conID,self.downloadHistInfo[conID]]
            self.toWat.put(msg) # we send to watch,

            print('histnew5secOneTime - finished',conID)

            #must clear the downloadHistInfo
            self.downloadHistInfo.pop(conID)
            ## maybe we should send some message to gui too to inform the user that we are ready

            return

        ret=self.dbLite.addOneStock(self.downloadHistInfo[conID])

        start = self.downloadHistInfo[conID].oneStock.bars1min[0].date

        del self.downloadHistInfo[conID].oneStock.bars1min[:]

        if ret=='stop': #we don't need to download anymore in case of a newhist

            if self.downloadHistInfo[conID].whatToDownload=='histnewLevel1':
                msg=toMessage('histnewLevel1End')
                msg.obj=conID
                self.toGui.put(msg) #let's anounce that we can go to level 2
                #print('hist new Level1 end')
            self.downloadHistInfo.pop(conID)  # removed from dictionary - no sens to stay there
            print('finish new download')
            return

        #delete all the bars
        self.downloadHistInfo[conID].count += 1

        if self.downloadHistInfo[conID].count>=10 and self.downloadHistInfo[conID].whatToDownload=='histold':
            #we already download 60 for history so do not send anymore messages

            self.downloadHistInfo.pop(conID)
            return

        self.downloadHistInfo[conID].dateToDownload = start
        msg=toMessage('HistFinish')
        msg.obj=self.downloadHistInfo[conID]
        self.toGui.put(msg)
        return