def add_price_for_yesterday(session): """ Create a price entry for test(s) """ value = Decimal("1.0548") app = PriceDbApplication(session=session) datum = Datum() datum.yesterday() symbol = SecuritySymbol("VANGUARD", "BOND") model = PriceModel() model.currency = "AUD" model.datum = datum model.symbol = symbol model.value = value app.add_price(model) # make sure that the price is there first = app.price_repo.query.first() assert first yesterday_str = datum.to_iso_date_string() assert first.date == yesterday_str assert first.currency == "AUD" assert first.value == 10548 assert first.denom == 10000
def add(symbol: str, date, value, currency: str): """ Add individual price """ symbol = symbol.upper() currency = currency.upper() app = PriceDbApplication() price = PriceModel() # security = SecuritySymbol("", "") price.symbol.parse(symbol) # price.symbol.mnemonic = price.symbol.mnemonic.upper() # date_str = f"{date}" # date_format = "%Y-%m-%d" # if time: # date_str = f"{date_str}T{time}" # date_format += "T%H:%M:%S" # datum.from_iso_date_string(date) # price.datetime = datetime.strptime(date_str, date_format) price.datum.from_iso_date_string(date) price.value = Decimal(value) price.currency = currency app.add_price(price) app.save() click.echo("Price added.")
def add_prices_for_yesterday_and_today(session, symbol: SecuritySymbol): """ Add prices for the same symbol for yesterday and today """ app = PriceDbApplication(session) assert isinstance(symbol, SecuritySymbol) price = PriceModel() # Create price for today price.datum = Datum() price.currency = "EUR" price.symbol = symbol price.value = Decimal("150.13") app.add_price(price) # Create price for yesterday price.datum.yesterday() price.value = Decimal("50.28") app.add_price(price)