예제 #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))
예제 #2
0
    def generate_4_quotes(self):
        from xulpymoney.objects.quote import Quote
        quotes=[]
        datestart=dtaware(self.date,self.product.stockmarket.starts,self.product.stockmarket.zone.name)
        dateends=dtaware(self.date,self.product.stockmarket.closes,self.product.stockmarket.zone.name)
        datetimefirst=datestart-timedelta(seconds=1)
        datetimelow=(datestart+(dateends-datestart)*1/3)
        datetimehigh=(datestart+(dateends-datestart)*2/3)
        datetimelast=dateends+timedelta(microseconds=4)

        quotes.append(Quote(self.mem).init__create(self.product,datetimelast, Decimal(self.close)))#closes
        quotes.append(Quote(self.mem).init__create(self.product,datetimelow, Decimal(self.low)))#low
        quotes.append(Quote(self.mem).init__create(self.product,datetimehigh, Decimal(self.high)))#high
        quotes.append(Quote(self.mem).init__create(self.product, datetimefirst, Decimal(self.open)))#open        
        return quotes
예제 #3
0
    def on_actionQuoteImport_triggered(self):
        filename = QFileDialog.getOpenFileName(self, "", "",
                                               "LibreOffice Calc (*.ods)")[0]
        got = 0
        if filename != "":
            set = QuoteManager(self.mem)
            ods = ODS_Read(filename)

            for number in range(2, ods.rowNumber(0)):
                date = ods.getCellValue(0, "A" + str(number))
                value = ods.getCellValue(0, "B" + str(number))
                print(date, value)
                try:
                    set.append(
                        Quote(self.mem).init__create(
                            self.product,
                            dtaware(date, self.product.stockmarket.closes,
                                    self.product.stockmarket.zone.name),
                            value))
                    got = got + 1
                except:
                    debug("I couldn't import {} and {} as a quote".format(
                        date, value))
            print("Added {} DPS from {} ODS rows".format(
                got, ods.rowNumber(0)))
            set.save()
            self.mem.con.commit()
            self.product.needStatus(2, downgrade_to=0)
            self.update_due_to_quotes_change()
예제 #4
0
 def setquotesbasic(self):
     from xulpymoney.objects.quote import Quote, QuoteBasicManager
     last=None
     penultimate=None
     lastyear=None
     if self.length()==0:
         return QuoteBasicManager(self.mem, self.product).init__create(Quote(self.mem).none(self.product), Quote(self.mem).none(self.product),  Quote(self.mem).none(self.product))
     ohcl=self.arr[self.length()-1]#last
     last=Quote(self.mem).init__create(self.product, dtaware(ohcl.date, self.product.stockmarket.closes,  self.product.stockmarket.zone.name), ohcl.close)
     ohcl=self.find(ohcl.date-timedelta(days=1))#penultimate
     if ohcl!=None:
         penultimate=Quote(self.mem).init__create(self.product, dtaware(ohcl.date, self.product.stockmarket.closes,  self.product.stockmarket.zone.name), ohcl.close)
     ohcl=self.find(date(date.today().year-1, 12, 31))#lastyear
     if ohcl!=None:
         lastyear=Quote(self.mem).init__create(self.product, dtaware(ohcl.date, self.product.stockmarket.closes,  self.product.stockmarket.zone.name), ohcl.close)        
     return QuoteBasicManager(self.mem, self.product).init__create(last, penultimate, lastyear)
예제 #5
0
    def append_from_portfolio(self):
        line_count = 0
        quotes_count = 0
        for row in self.get_csv_object_seeking():
            if line_count >0:#Ignores headers line
#                ## Casos especiales por ticker repetido se compara con más información.
#                if row[1]=="DE30" and row[2]=="DE":
#                    products=[Products.objects.get(id=78094),]#DAX 30
#                elif row [1]=="DE30" and row[2]=="Eurex":
#                    products=(Products.objects.get(id=81752),)#CFD DAX 30
#                elif row[1]=="US2000" and row[2]=="P":
#                    products=[Products.objects.get(id=81745),]#RUSELL 2000
#                elif row [1]=="US2000" and row[2]=="ICE":
#                    products=(Products.objects.get(id=81760),)#CFD RUSELL 2000
#                elif "EUR/USD" in row [1]:
#                    products=(Products.objects.get(id=74747),)#EUR/USD
#                elif "Oro al " in row [1]:
#                    products=(Products.objects.get(id=81758), Products.objects.get(id=81757))#CFD ORO
#                else:
                if row[2]=="":
                    products=Products.objects.raw('SELECT products.* FROM products where tickers[5]=%s', (f"{row[1]}", ))
                else:
                    products=Products.objects.raw('SELECT products.* FROM products where tickers[5]=%s', (f"{row[1]}#{row[2]}", ))

                if len(products)==0:
                    self.log.append(_(f"Product with InvestingCom ticker {row[1]} wasn't found"))

                for product in products:
                    if row[16].find(":")==-1:#It's a date
                        try:
                            quote=Quotes()
                            quote.products=product
                            date_=string2date(row[16], "DD/MM")
                            quote.datetime=dtaware(date_, product.stockmarkets.closes, product.stockmarkets.zone)#Without 4 microseconds becaouse is not a ohcl
                            quote.quote=string2decimal(row[3])
                            quotes_count=quotes_count+1
                            self.log.append(quote.save())
                        except:
                            self.log.append("Error parsing date"+ str(row) )
                    else: #It's an hour
                        try:
                            quote=Quotes()
                            quote.products=product
                            quote.datetime=string2dtaware(row[16],"%H:%M:%S", self.request.globals["mem__localzone"])
                            quote.quote=string2decimal(row[3])
                            quotes_count=quotes_count+1
                            self.log.append(quote.save())
                        except:
                            self.log.append("Error parsing hour" + str(row))
            line_count += 1
        lis=""
        for o in self.log:
            lis=lis+f"<li>{o}</li>"
        messages.info(self.request,f"""Managed {quotes_count} quotes from {line_count} CSV lines
    <ul>
        {lis}
    </ul>""")
예제 #6
0
 def on_chkNone_stateChanged(self, state):
     if state == Qt.Checked:
         self.wdgDT.set(
             dtaware(self.wdgDT.date(), self.product.stockmarket.closes,
                     self.product.stockmarket.zone.name),
             self.product.stockmarket.zone.name)
         self.wdgDT.teTime.setEnabled(False)
         self.wdgDT.cmbZone.setEnabled(False)
         self.wdgDT.cmdNow.setEnabled(False)
         self.wdgDT.teMicroseconds.setEnabled(False)
     else:
         self.wdgDT.teTime.setEnabled(True)
         self.wdgDT.cmbZone.setEnabled(True)
         self.wdgDT.cmdNow.setEnabled(True)
         self.wdgDT.teMicroseconds.setEnabled(True)
예제 #7
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))
예제 #8
0
 def show_investments_status(self, date):
     """Shows investments status in a date"""
     datet = dtaware(date, time(22, 00), self.mem.localzone_name)
     sumbalance = 0
     print("{0:<40s} {1:>15s} {2:>15s} {3:>15s}".format(
         "Investments at {0}".format(date), "Shares", "Price", "Balance"))
     for inv in self.mem.data.investments.arr:
         balance = inv.balance(date)
         sumbalance = sumbalance + balance
         shares = inv.shares(date)
         price = Quote(self.mem).init__from_query(inv.product, datet)
         if shares != 0:
             print("{0:<40s} {1:>15f} {2:>15s} {3:>15s}".format(
                 inv.name, shares, self.mem.localmoney(price.quote),
                 self.mem.localmoney(balance)))
     print("{0:>40s} {1:>15s} {2:>15s} {3:>15s}".format(
         "Total balance at {0}".format(date), "", "",
         self.mem.localmoney(sumbalance)))
예제 #9
0
    def load_information(self):
        def row_mqtwTPV(quote, row):
            if quote == None:
                return
            self.tblTPC.setItem(
                row, 0, qdatetime(quote.datetime, self.mem.localzone_name))
            self.tblTPC.setItem(
                row, 1,
                self.product.money(quote.quote).qtablewidgetitem(
                    self.product.decimals))

            try:
                tpc = Percentage(
                    self.product.result.basic.last.quote - quote.quote,
                    quote.quote)
                days = (datetime.now(timezone(self.mem.localzone_name)) -
                        quote.datetime).days + 1
                self.tblTPC.setItem(row, 2, tpc.qtablewidgetitem())
                self.tblTPC.setItem(row, 3,
                                    (tpc * 365 / days).qtablewidgetitem())
                if self.investment:
                    self.grpHistoricos.setTitle(
                        self.
                        tr('Report of historic prices. You have {} shares valued at {}.'
                           ).format(self.investment.shares(),
                                    self.investment.balance()))
                    self.tblTPC.setItem(
                        row, 4,
                        self.product.money(
                            self.investment.shares() *
                            (self.product.result.basic.last.quote -
                             quote.quote)).qtablewidgetitem())
            except:
                self.tblTPC.setItem(row, 2, Percentage().qtablewidgetitem())
                self.tblTPC.setItem(row, 3, Percentage().qtablewidgetitem())
                self.tblTPC.setItem(row, 3, qcurrency(None))

        # ---------------------------------
        if len(self.product.result.ohclDaily.arr) != 0:
            now = self.mem.localzone.now()
            penultimate = self.product.result.basic.penultimate
            iniciosemana = Quote(self.mem).init__from_query(
                self.product,
                dt_day_end(now - timedelta(days=date.today().weekday() + 1)))
            iniciomes = Quote(self.mem).init__from_query(
                self.product,
                dtaware(date(now.year, now.month, 1), time(0, 0),
                        self.product.stockmarket.zone.name))
            inicioano = Quote(self.mem).init__from_query(
                self.product,
                dtaware(date(now.year, 1, 1), time(0, 0),
                        self.product.stockmarket.zone.name))
            docemeses = Quote(self.mem).init__from_query(
                self.product, dt_day_end(now - timedelta(days=365)))
            unmes = Quote(self.mem).init__from_query(
                self.product, dt_day_end(now - timedelta(days=30)))
            unasemana = Quote(self.mem).init__from_query(
                self.product, dt_day_end(now - timedelta(days=7)))

            self.tblTPC.setItem(
                0, 0,
                qdatetime(self.product.result.basic.last.datetime,
                          self.mem.localzone_name))
            self.tblTPC.setItem(
                0, 1,
                self.product.money(
                    self.product.result.basic.last.quote).qtablewidgetitem(6))

            row_mqtwTPV(penultimate, 2)
            row_mqtwTPV(iniciosemana, 3)  ## Para que sea el domingo
            row_mqtwTPV(iniciomes, 4)
            row_mqtwTPV(inicioano, 5)
            row_mqtwTPV(unasemana, 7)
            row_mqtwTPV(unmes, 8)
            row_mqtwTPV(docemeses, 9)