Ejemplo n.º 1
0
def __get_model_for_portfolio_value(input_model: PortfolioValueInputModel
        ) -> PortfolioValueViewModel:
    """ loads the data for portfolio value """
    result = PortfolioValueViewModel()
    result.filter = input_model

    ref_datum = Datum()
    ref_datum.from_datetime(input_model.as_of_date)
    ref_date = ref_datum.end_of_day()

    result.stock_rows = []
    with BookAggregate() as svc:
        book = svc.book
        stocks_svc = svc.securities

        if input_model.stock:
            symbols = input_model.stock.split(",")
            stocks = stocks_svc.get_stocks(symbols)
        else:
            stocks = stocks_svc.get_all()

        for stock in stocks:
            row: StockViewModel = portfoliovalue.get_stock_model_from(
                book, stock, as_of_date=ref_date)
            if row and row.balance > 0:
                result.stock_rows.append(row)

    return result
Ejemplo n.º 2
0
    def get_transactions(self, date_from: datetime, date_to: datetime) -> List[Transaction]:
        """ Returns account transactions """
        assert isinstance(date_from, datetime)
        assert isinstance(date_to, datetime)

        # fix up the parameters as we need datetime
        dt_from = Datum()
        dt_from.from_datetime(date_from)
        dt_from.start_of_day()
        dt_to = Datum()
        dt_to.from_datetime(date_to)
        dt_to.end_of_day()

        query = (
            self.book.session.query(Transaction)
            .join(Split)
            .filter(Split.account_guid == self.account.guid)
            .filter(Transaction.post_date >= dt_from.date, Transaction.post_date <= dt_to.date)
            .order_by(Transaction.post_date)
        )
        return query.all()
Ejemplo n.º 3
0
    def parse_date(self, date_str: str):
        ''' parse date/time '''
        from dateutil.parser import parse
        from dateutil import tz
        from pydatum import Datum

        # Can be "19 Jul 2019" or "6:06am EDT".

        if "EDT" in date_str:
            # the format is "6:06am EDT"
            from_zone = tz.gettz('US/Eastern')
            #est = tz.gettz('EST')
            to_zone = tz.tzlocal()
            parsed_date = parse(date_str)
            date_val = parsed_date.replace(tzinfo=from_zone).astimezone(
                tz=to_zone)
        else:
            # the date format is "19 Jul 2019"
            #date_val = datetime.strptime(date_str, "%d %b %Y")
            date_val = parse(date_str)

        datum = Datum()
        result = datum.from_datetime(date_val)
        return result