Пример #1
0
def main():
    """ Main example """
    logging.info("--- SETTING UP IDENTIFIERS ---")
    asset_manager_id = random.randint(1, 2**31 - 1)
    calendar = Calendar()
    # This can fail if yesterday was a holiday - need to add a holiday calendar
    business_date = calendar.addbusdays(date.today(), -2)
    logging.info("Business Date: %s", business_date)
    business_date_str = business_date.isoformat()
    symbols = ['TWTR', 'AAPL', 'RBS.L', 'Z77.SI', '0008.HK']

    logging.info("--- PULL MARKET DATA FROM YAHOO FINANCE ---")
    eod_prices = []
    for symbol in symbols:
        share = Share(symbol=symbol)
        logging.info("Stock Name: %s", share.get_name())
        close = (share.get_historical(
            start_date=business_date_str,
            end_date=business_date_str)[0].get('Close'))
        eod_price = EODPrice(asset_manager_id=asset_manager_id,
                             asset_id=symbol,
                             business_date=business_date,
                             price=Decimal(close))
        logging.info("EOD Price: %s", eod_price.price)
        eod_prices.append(eod_price)

    logging.info("--- PERSIST PRICES TO AMAAS ---")
    # Some of these attributes can be derived from the eod_prices - cleanup
    market_data_interface.persist_eod_prices(asset_manager_id=asset_manager_id,
                                             business_date=business_date,
                                             eod_prices=eod_prices,
                                             update_existing_prices=True)
def generate_eod_price(asset_manager_id=0,
                       asset_id=None,
                       business_date=date.today(),
                       price=None):
    eod_price = EODPrice(asset_manager_id=asset_manager_id,
                         asset_id=asset_id or random_string(10),
                         business_date=business_date,
                         price=price or random_decimal())
    return eod_price
Пример #3
0
def main():
    """ Main example """
    logging.info("--- SETTING UP IDENTIFIERS ---")
    asset_manager_id = random.randint(1, 2**31-1)
    business_date = date.today() - relativedelta(days=1)
    business_date_str = business_date.isoformat()
    symbols = ['TWTR', 'AAPL', 'RBS.L', 'Z77.SI', '0008.HK']

    logging.info("--- PULL MARKET DATA FROM YAHOO FINANCE ---")
    eod_prices = []
    for symbol in symbols:
        share = Share(symbol=symbol)
        print(share.get_name())
        close = (share.get_historical(start_date=business_date_str, end_date=business_date_str)[0].get('Close'))
        eod_price = EODPrice(asset_manager_id=asset_manager_id,
                             asset_id=symbol,
                             business_date=business_date,
                             price=Decimal(close))
        eod_prices.append(eod_price)

    logging.info("--- PERSIST PRICES TO AMAAS ---")
    # Some of these attributes can be derived from the eod_prices - cleanup
    market_data_interface.persist_eod_prices(asset_manager_id=asset_manager_id, business_date=business_date,
                                             eod_prices=eod_prices)
Пример #4
0
def json_to_eod_price(json_eod_price):
    eod_price = EODPrice(**json_eod_price)
    return eod_price