Exemple #1
0
 def append_from_default(self):
     with open(self.filename) as csv_file:
         csv_reader = reader(csv_file, delimiter=',')
         line_count = 0
         for row in csv_reader:
             if line_count >0:#Ignores headers line
                 products=self.mem.data.products.find_all_by_ticker(row[1], eTickerPosition.InvestingCom)
                 print(row[1], len(products))
                 if len(products)==0:
                     print(_(f"Product with InvestingCom ticker {row[1]} wasn't found"))
                 for product in products:
                     if row[7].find(":")==-1:#It's a date
                         try:
                             quote=Quote(self.mem)
                             quote.product=product
                             date_=string2date(row[7], "DD/MM")
                             quote.datetime=dtaware(date_,quote.product.stockmarket.closes,self.mem.localzone_name)#Without 4 microseconds becaouse is not a ohcl
                             quote.quote=string2decimal(row[2])
                             self.append(quote)
                         except:
                             debug("Error parsing "+ str(row))
                     else: #It's an hour
                         try:
                             quote=Quote(self.mem)
                             quote.product=product
                             time_=string2time(row[7], "HH:MM:SS")
                             quote.datetime=dtaware(date.today(), time_, self.mem.localzone_name)
                             quote.quote=string2decimal(row[3])
                             self.append(quote)
                         except:
                             debug("Error parsing "+ str(row))
             line_count += 1
     print("Added {} quotes from {} CSV lines".format(self.length(), line_count))
Exemple #2
0
    def append_from_portfolio(self):
        with open(self.filename) as csv_file:
            csv_reader = reader(csv_file, delimiter=',')
            line_count = 0
            for row in csv_reader:
                if line_count > 0:  #Ignores headers line
                    for product in self.mem.data.products.find_all_by_ticker(
                            row[1], eTickerPosition.InvestingCom):
                        ## Casos especiales por ticker repetido se compara con más información.
                        if row[1] == "DE30" and row[2] == "DE":
                            product = self.mem.data.products.find_by_id(
                                78094)  #DAX 30
                            print("DAX30")
                        elif row[1] == "DE30" and row[2] == "Eurex":
                            product = self.mem.data.products.find_by_id(
                                81752)  #CFD DAX 30
                            print("CDFDAX")

                        if row[16].find(":") == -1:  #It's a date
                            try:
                                quote = Quote(self.mem)
                                quote.product = product
                                date_ = string2date(row[16], "DD/MM")
                                quote.datetime = dtaware(
                                    date_, quote.product.stockmarket.closes,
                                    quote.product.stockmarket.zone.name
                                )  #Without 4 microseconds becaouse is not a ohcl
                                quote.quote = string2decimal(row[3])
                                self.append(quote)
                            except:
                                debug("Error parsing " + str(row))
                        else:  #It's an hour
                            try:
                                quote = Quote(self.mem)
                                quote.product = product
                                quote.datetime = string2dtaware(
                                    row[16], "%H:%M:%S",
                                    self.mem.localzone_name)
                                quote.quote = string2decimal(row[3])
                                self.append(quote)
                            except:
                                debug("Error parsing " + str(row))
                line_count += 1
        print("Added {} quotes from {} CSV lines".format(
            self.length(), line_count))