def import_price(self, price: PriceModel):
        """ Import individual price """
        # Handle yahoo-style symbols with extension.
        symbol = price.symbol
        if "." in symbol:
            symbol = price.symbol.split(".")[0]
        stock = SecuritiesAggregate(self.book).get_by_symbol(symbol)
        # get_aggregate_for_symbol

        if stock is None:
            logging.warning("security %s not found in book.", price.symbol)
            return False

        # check if there is already a price for the date
        existing_prices = stock.prices.filter(Price.date == price.datetime.date()).all()
        if not existing_prices:
            # Create new price for the commodity (symbol).
            self.__create_price_for(stock, price)
        else:
            logging.warning("price already exists for %s on %s",
                            stock.mnemonic, price.datetime.strftime("%Y-%m-%d"))

            existing_price = existing_prices[0]
            # update price
            existing_price.value = price.value

        return True
def import_price ( self , price : PriceModel ) : symbol = price . symbol if "." in symbol : symbol = price . symbol . split ( "." ) [ 0 ] stock = SecuritiesAggregate ( self . book ) . get_by_symbol ( symbol ) if stock is None : logging . warning ( "security %s not found in book." , price . symbol ) return False existing_prices = stock . prices . filter ( Price . date == price . datetime . date ( ) ) . all ( ) if not existing_prices : self . __create_price_for ( stock , price ) else : logging . warning ( "price already exists for %s on %s" , stock . mnemonic , price . datetime . strftime ( "%Y-%m-%d" ) ) existing_price = existing_prices [ 0 ] existing_price . value = price . value return True
Import individual price