Example #1
0
    def getdata(self, quote):
        self.m_connected = False
        debug("LiveUpdate_Euronext:getdata quote:%s market:%s" %
              (quote, self.m_market))

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

        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'),
            ('typeDownload', '3'),
            ('format', ''),
        )
        query = map(lambda (var, val): '%s=%s' % (var, str(val)), query)
        query = string.join(query, '&')
        url = self.m_url + '?' + query

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

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

        indice = {}
        """
        "Instrument's name";
        "ISIN";
        "Euronext code";
        "MEP";
        "Symbol";
        "ICB Sector (Level 4)";
        "Trading currency";
        "Last";
        "Volume";
        "D/D-1 (%)";
        "Date - time (CET)";
        "Turnover";
        "Total number of shares";
        "Capitalisation";
        "Trading mode";
        "Day First";
        "Day High";
        "Day High / Date - time (CET)";
        "Day Low";
        "Day Low / Date - time (CET)";
        "31-12/Change (%)";
        "31-12/High";
        "31-12/High/Date";
        "31-12/Low";
        "31-12/Low/Date";
        "52 weeks/Change (%)";
        "52 weeks/High";
        "52 weeks/High/Date";
        "52 weeks/Low";
        "52 weeks/Low/Date";
        "Suspended";
        "Suspended / Date - time (CET)";
        "Reserved";
        "Reserved / Date - time (CET)"
        """

        for eachLine in lines:
            sdata = string.split(eachLine, '\t')
            #print sdata,len(sdata)

            if len(sdata) > 2:
                if not indice.has_key("ISIN"):
                    i = 0
                    for ind in sdata:
                        indice[ind] = i
                        i = i + 1

                    iName = indice["Instrument's name"]
                    iISIN = indice["ISIN"]
                    iDate = indice["Date - time (CET)"]
                    iOpen = indice["Day First"]
                    iLast = indice["Last"]
                    iHigh = indice["Day High"]
                    iLow = indice["Day Low"]
                    iPercent = indice["D/D-1 (%)"]

                    if indice.has_key("Volume"):
                        iVolume = indice["Volume"]
                    else:
                        iVolume = -1

                else:
                    if (sdata[iISIN] <> "ISIN") and (sdata[iDate] != '-'):
                        c_datetime = datetime.today()
                        c_date = "%04d%02d%02d" % (
                            c_datetime.year, c_datetime.month, c_datetime.day)
                        #print 'Today is :', c_date

                        sdate, sclock = self.euronextDate(sdata[iDate])

                        # be sure we have volume (or indices)
                        if (quote.list() == QLIST_INDICES
                                or sdata[iVolume] <> '-'):

                            # be sure not an oldest day !
                            if (c_date == sdate) or (quote.list()
                                                     == QLIST_INDICES):
                                key = quote.key()
                                self.m_dcmpd[key] = sdate
                                self.m_clock[key] = self.convertClock(
                                    quote.place(), sclock, sdate)

                            #
                            open = self.parseFValue(sdata[iOpen])
                            high = self.parseFValue(sdata[iHigh])
                            low = self.parseFValue(sdata[iLow])
                            value = self.parseFValue(sdata[iLast])
                            percent = self.parseFValue(sdata[iPercent])

                            if iVolume != -1:
                                volume = self.parseLValue(sdata[iVolume])
                            else:
                                volume = 0

                            # ISIN;DATE;OPEN;HIGH;LOW;CLOSE;VOLUME;PERCENT
                            data = (quote.key(), sdate, open, high, low, value,
                                    volume, percent)
                            data = map(lambda (val): '%s' % str(val), data)
                            data = string.join(data, ';')

                            return data
                    else:
                        print sdata
                        pass

        return None
    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):
        self.m_connected = False
        debug("LiveUpdate_Euronext:getdata quote:%s market:%s" % (quote,self.m_market))

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

        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'),
            ('typeDownload', '3'),
            ('format', ''),
        )
        query = map(lambda (var, val): '%s=%s' % (var, str(val)), query)
        query = string.join(query, '&')
        url = self.m_url + '?' + query

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

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

        indice = {}
        """
        "Instrument's name";
        "ISIN";
        "Euronext code";
        "MEP";
        "Symbol";
        "ICB Sector (Level 4)";
        "Trading currency";
        "Last";
        "Volume";
        "D/D-1 (%)";
        "Date - time (CET)";
        "Turnover";
        "Total number of shares";
        "Capitalisation";
        "Trading mode";
        "Day First";
        "Day High";
        "Day High / Date - time (CET)";
        "Day Low";
        "Day Low / Date - time (CET)";
        "31-12/Change (%)";
        "31-12/High";
        "31-12/High/Date";
        "31-12/Low";
        "31-12/Low/Date";
        "52 weeks/Change (%)";
        "52 weeks/High";
        "52 weeks/High/Date";
        "52 weeks/Low";
        "52 weeks/Low/Date";
        "Suspended";
        "Suspended / Date - time (CET)";
        "Reserved";
        "Reserved / Date - time (CET)"
        """

        for eachLine in lines:
            sdata = string.split (eachLine, '\t')
            #print sdata,len(sdata)

            if len(sdata)>2:
                if not indice.has_key("ISIN"):
                    i = 0
                    for ind in sdata:
                        indice[ind] = i
                        i = i + 1

                    iName = indice["Instrument's name"]
                    iISIN = indice["ISIN"]
                    iDate = indice["Date - time (CET)"]
                    iOpen = indice["Day First"]
                    iLast = indice["Last"]
                    iHigh = indice["Day High"]
                    iLow = indice["Day Low"]
                    iPercent = indice["D/D-1 (%)"]

                    if indice.has_key("Volume"):
                        iVolume = indice["Volume"]
                    else:
                        iVolume = -1

                else:
                    if (sdata[iISIN]<>"ISIN") and (sdata[iDate]!='-'):
                        c_datetime = datetime.today()
                        c_date = "%04d%02d%02d" % (c_datetime.year,c_datetime.month,c_datetime.day)
                        #print 'Today is :', c_date

                        sdate,sclock = self.euronextDate(sdata[iDate])

                        # be sure we have volume (or indices)
                        if (quote.list() == QLIST_INDICES or sdata[iVolume]<>'-'):

                            # be sure not an oldest day !
                            if (c_date==sdate) or (quote.list() == QLIST_INDICES):
                                key = quote.key()
                                self.m_dcmpd[key] = sdate
                                self.m_clock[key] = self.convertClock(quote.place(),sclock,sdate)

                            #
                            open = self.parseFValue(sdata[iOpen])
                            high = self.parseFValue(sdata[iHigh])
                            low = self.parseFValue(sdata[iLow])
                            value = self.parseFValue(sdata[iLast])
                            percent = self.parseFValue(sdata[iPercent])

                            if iVolume!=-1:
                                volume = self.parseLValue(sdata[iVolume])
                            else:
                                volume = 0

                            # ISIN;DATE;OPEN;HIGH;LOW;CLOSE;VOLUME;PERCENT
                            data = (
                              quote.key(),
                              sdate,
                              open,
                              high,
                              low,
                              value,
                              volume,
                              percent
                            )
                            data = map(lambda (val): '%s' % str(val), data)
                            data = string.join(data, ';')

                            return data
                    else:
                        print sdata
                        pass

        return None
    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