def euronextDate(self, date):
        sp = string.split(date, ' ')
        #print 'euronextDate:',sp

        # Date part is easy
        sdate = jjmmaa2yyyymmdd(sp[0])

        if len(sp) == 1:
            return sdate, "00:00"
        return sdate, sp[1]
    def euronextDate(self,date):
        sp = string.split(date,' ')
        #print 'euronextDate:',sp

        # Date part is easy
        sdate = jjmmaa2yyyymmdd(sp[0])

        if len(sp)==1:
            return sdate,"00:00"
        return sdate,sp[1]
예제 #3
0
    def getdata(self, quote, datedebut=None, datefin=None):

        # get historic data itself !
        if not datefin:
            datefin = date.today()

        if not datedebut:
            datedebut = date.today()

        if isinstance(datedebut, Datation):
            datedebut = datedebut.date()

        if isinstance(datefin, Datation):
            datefin = datefin.date()

        d1 = self.parseDate(datedebut)
        d2 = self.parseDate(datefin)

        mic = euronextmic(quote.market(), quote.place())

        format = '%Y-%m-%d %H:%M:%S'
        #origin = "1970-01-01 00:00:00"
        datefrom = str(datedebut) + " 02:00:00"
        dateto = str(datefin) + " 23:00:00"
        datefrom = time.mktime(time.strptime(datefrom, format))
        datefromurl = str(int(datefrom / 100)) + '00000'
        dateto = time.mktime(time.strptime(dateto, format))
        datefinurl = str(int(dateto) / 100) + '00000'
        endurl = 'typefile=csv&layout=vertical&typedate=dmy&separator=comma&mic=%s&isin=%s&name=&namefile=Price_Data_Historical&from=%s&to=%s&adjusted=1&base=0' % (
            mic, quote.isin(), datefromurl, datefinurl)

        debug("Import_euronext:getdata quote:%s begin:%s end:%s" %
              (quote, d1, d2))

        query = (
            ('typefile', 'csv'),
            ('layout', 'vertical'),
            ('typedate', 'dmy'),
            ('separator', 'comma'),
            ('mic', mic),
            ('isin', quote.isin()),
            ('name', ''),
            ('namefile', 'Price_Data_Historical'),
            ('from', datefromurl),
            ('to', datefinurl),
            ('adjusted', '1'),
            ('base', '0'),
        )

        query = map(lambda (var, val): '%s=%s' % (var, str(val)), query)
        query = string.join(query, '&')
        url = self.m_url + '?' + query

        #print url
        debug("Import_euronext:getdata: url=%s ", url)
        try:

            req = urllib2.Request(url)
            req.add_header(
                'User-Agent',
                'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041202 Firefox/1.0'
            )

            f = urllib2.urlopen(req)
            buf = f.read()
            f.close()

            #buf=self.m_connection.getDataFromUrl(url)
        except:
            debug('Import_euronext:unable to connect :-(')
            return None

        # pull data
        lines = self.splitLines(buf)
        data = ''
        #print lines

        for eachLine in lines[4:]:
            eachLine = eachLine.replace('","', ';')
            eachLine = eachLine.replace('"', '')
            sdata = string.split(eachLine, ';')

            if len(sdata) == 11:
                #print sdata
                #if (sdata[0] != "Date") and (quote.list() == QLIST_INDICES):
                sdate = jjmmaa2yyyymmdd(sdata[2])
                open = self.parseFValue(sdata[3].replace(',', '.'))
                high = self.parseFValue(sdata[4].replace(',', '.'))
                low = self.parseFValue(sdata[5].replace(',', '.'))
                value = self.parseFValue(sdata[6].replace(',', '.'))
                volume = self.parseLValue(sdata[7])
                #print quote.key(),sdate,open,high,low,value,volume

                # encode in EBP format
                # ISIN;DATE;OPEN;HIGH;LOW;CLOSE;VOLUME
                line = (quote.key(), sdate, open, high, low, value, volume)
                line = map(lambda (val): '%s' % str(val), line)
                line = string.join(line, ';')
                #print line

                # append
                data = data + line + '\r\n'
        return data
예제 #4
0
    def getdata(self,quote,datedebut=None,datefin=None):

        # get historic data itself !
        if not datefin:
            datefin = date.today()

        if not datedebut:
            datedebut = date.today()

        if isinstance(datedebut,Datation):
            datedebut = datedebut.date()

        if isinstance(datefin,Datation):
            datefin = datefin.date()

        d1 = self.parseDate(datedebut)
        d2 = self.parseDate(datefin)

        mic = euronextmic(quote.market(),quote.place())
        
        format = '%Y-%m-%d %H:%M:%S'
        #origin = "1970-01-01 00:00:00"
        datefrom = str(datedebut) + " 02:00:00"
        dateto = str(datefin) + " 23:00:00"
        datefrom = time.mktime(time.strptime(datefrom, format))
        datefromurl =str(int(datefrom/100))+'00000'
        dateto = time.mktime(time.strptime(dateto, format))
        datefinurl =str(int(dateto)/100)+'00000'
        endurl = 'typefile=csv&layout=vertical&typedate=dmy&separator=comma&mic=%s&isin=%s&name=&namefile=Price_Data_Historical&from=%s&to=%s&adjusted=1&base=0' % (mic,quote.isin(),datefromurl,datefinurl)

        debug("Import_euronext:getdata quote:%s begin:%s end:%s" % (quote,d1,d2))

        query = (
            ('typefile', 'csv'),
            ('layout', 'vertical'),
            ('typedate', 'dmy'),
            ('separator', 'comma'),
            ('mic', mic),
            ('isin', quote.isin()),
            ('name', ''),
            ('namefile', 'Price_Data_Historical'),
            ('from', datefromurl),
            ('to', datefinurl),
            ('adjusted', '1'),
            ('base', '0'),
        )

        query = map(lambda (var, val): '%s=%s' % (var, str(val)), query)
        query = string.join(query, '&')
        url = self.m_url + '?' + query
        
        #print url
        debug("Import_euronext:getdata: url=%s ",url)
        try:

            req = urllib2.Request(url)
            req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041202 Firefox/1.0')

            f = urllib2.urlopen(req)
            buf = f.read()
            f.close()
            
            #buf=self.m_connection.getDataFromUrl(url)
        except:
            debug('Import_euronext:unable to connect :-(')
            return None

        # pull data
        lines = self.splitLines(buf)
        data = ''
        #print lines

        for eachLine in lines[4:]:
            eachLine = eachLine.replace('","',';')
            eachLine = eachLine.replace('"','')
            sdata = string.split(eachLine,';')
            
            if len(sdata)== 11:
                #print sdata
                #if (sdata[0] != "Date") and (quote.list() == QLIST_INDICES):
                sdate = jjmmaa2yyyymmdd(sdata[2])
                open = self.parseFValue(sdata[3].replace(',','.'))
                high = self.parseFValue(sdata[4].replace(',','.'))
                low = self.parseFValue(sdata[5].replace(',','.'))
                value = self.parseFValue(sdata[6].replace(',','.'))
                volume = self.parseLValue(sdata[7])
                #print quote.key(),sdate,open,high,low,value,volume

                # encode in EBP format
                # ISIN;DATE;OPEN;HIGH;LOW;CLOSE;VOLUME
                line = (
                    quote.key(),
                    sdate,
                    open,
                    high,
                    low,
                    value,
                    volume
                    )
                line = map(lambda (val): '%s' % str(val), line)
                line = string.join(line, ';')
                #print line

                # append
                data = data + line + '\r\n'
        return data
    def getdata(self,quote,datedebut=None,datefin=None):

        #IdInstrument = euronext_InstrumentId(quote)
        #if IdInstrument == None: return None

        # get historic data itself !
        if not datefin:
            datefin = date.today()

        if not datedebut:
            datedebut = date.today()

        if isinstance(datedebut,Datation):
            datedebut = datedebut.date()

        if isinstance(datefin,Datation):
            datefin = datefin.date()

        d1 = self.parseDate(datedebut)
        d2 = self.parseDate(datefin)

        debug("Import_euronext:getdata quote:%s begin:%s end:%s" % (quote,d1,d2))

        query = (
            ('cha', '2593'),
            ('lan', 'EN'),
            #('idInstrument', IdInstrument),
            ('isinCode', quote.isin()),
            ('selectedMep', euronext_place2mep(quote.place())),
            ('indexCompo', ''),
            ('opening', 'on'),
            ('high', 'on'),
            ('low', 'on'),
            ('closing', 'on'),
            ('volume', 'on'),
            ('dateFrom', '%02d/%02d/%04d' % (d1[2],d1[1],d1[0])),
            ('dateTo', '%02d/%02d/%04d' % (d2[2],d2[1],d2[0])),
            ('typeDownload', '2'),
        )
        query = map(lambda (var, val): '%s=%s' % (var, str(val)), query)
        query = string.join(query, '&')
        url = self.m_url + '?' + query

        debug("Import_euronext:getdata: url=%s ",url)
        try:
            buf=self.m_connection.getDataFromUrl(url)
        except:
            debug('Import_euronext:unable to connect :-(')
            return None

        # pull data
        lines = self.splitLines(buf)
        data = ''
        #print lines

        for eachLine in lines:
            sdata = string.split (eachLine, '\t')
            if len(sdata)==6:
                #print sdata
                if (sdata[0]<>"Date") and (quote.list() == QLIST_INDICES or sdata[5]<>'-'):
                    sdate = jjmmaa2yyyymmdd(sdata[0])
                    open = self.parseFValue(sdata[1])
                    high = self.parseFValue(sdata[2])
                    low = self.parseFValue(sdata[3])
                    value = self.parseFValue(sdata[4])
                    volume = self.parseLValue(sdata[5])

                    # encode in EBP format
                    # ISIN;DATE;OPEN;HIGH;LOW;CLOSE;VOLUME
                    line = (
                      quote.key(),
                      sdate,
                      open,
                      high,
                      low,
                      value,
                      volume
                    )
                    line = map(lambda (val): '%s' % str(val), line)
                    line = string.join(line, ';')
                    #print line

                    # append
                    data = data + line + '\r\n'
        return data
    def getdata(self, quote, datedebut=None, datefin=None):

        #IdInstrument = euronext_InstrumentId(quote)
        #if IdInstrument == None: return None

        # get historic data itself !
        if not datefin:
            datefin = date.today()

        if not datedebut:
            datedebut = date.today()

        if isinstance(datedebut, Datation):
            datedebut = datedebut.date()

        if isinstance(datefin, Datation):
            datefin = datefin.date()

        d1 = self.parseDate(datedebut)
        d2 = self.parseDate(datefin)

        debug("Import_euronext:getdata quote:%s begin:%s end:%s" %
              (quote, d1, d2))

        query = (
            ('cha', '2593'),
            ('lan', 'EN'),
            #('idInstrument', IdInstrument),
            ('isinCode', quote.isin()),
            ('selectedMep', euronext_place2mep(quote.place())),
            ('indexCompo', ''),
            ('opening', 'on'),
            ('high', 'on'),
            ('low', 'on'),
            ('closing', 'on'),
            ('volume', 'on'),
            ('dateFrom', '%02d/%02d/%04d' % (d1[2], d1[1], d1[0])),
            ('dateTo', '%02d/%02d/%04d' % (d2[2], d2[1], d2[0])),
            ('typeDownload', '2'),
        )
        query = map(lambda (var, val): '%s=%s' % (var, str(val)), query)
        query = string.join(query, '&')
        url = self.m_url + '?' + query

        debug("Import_euronext:getdata: url=%s ", url)
        try:
            buf = self.m_connection.getDataFromUrl(url)
        except:
            debug('Import_euronext:unable to connect :-(')
            return None

        # pull data
        lines = self.splitLines(buf)
        data = ''
        #print lines

        for eachLine in lines:
            sdata = string.split(eachLine, '\t')
            if len(sdata) == 6:
                #print sdata
                if (sdata[0] <> "Date") and (quote.list() == QLIST_INDICES
                                             or sdata[5] <> '-'):
                    sdate = jjmmaa2yyyymmdd(sdata[0])
                    open = self.parseFValue(sdata[1])
                    high = self.parseFValue(sdata[2])
                    low = self.parseFValue(sdata[3])
                    value = self.parseFValue(sdata[4])
                    volume = self.parseLValue(sdata[5])

                    # encode in EBP format
                    # ISIN;DATE;OPEN;HIGH;LOW;CLOSE;VOLUME
                    line = (quote.key(), sdate, open, high, low, value, volume)
                    line = map(lambda (val): '%s' % str(val), line)
                    line = string.join(line, ';')
                    #print line

                    # append
                    data = data + line + '\r\n'
        return data