Esempio n. 1
0
def import_fund(code, from_date, to_date):
    """Imports fund data from KOFIA.

    :param code: e.g., KR5223941018
    :param from_date: e.g., 2016-01-01
    :param to_date: e.g., 2016-02-28
    """
    provider = Kofia()

    app = create_app(__name__)
    with app.app_context():
        asset = get_asset_by_fund_code(code)

        # FIXME: Target asset should also be determined by asset.data.code
        base_asset = Asset.query.filter_by(name="KRW").first()

        data = provider.fetch_data(code, parse_date(from_date),
                                   parse_date(to_date))
        for date, unit_price, quantity in data:
            log.info("Import data on {}", date)
            unit_price /= 1000.0
            try:
                AssetValue.create(
                    asset=asset,
                    base_asset=base_asset,
                    evaluated_at=date,
                    close=unit_price,
                    granularity=Granularity.day,
                    source="kofia",
                )
            except IntegrityError:
                log.warn("Identical record has been found for {}. Skipping.",
                         date)
                db.session.rollback()
Esempio n. 2
0
def import_fund(code, from_date, to_date):
    """Imports fund data from KOFIA.

    :param code: e.g., KR5223941018
    :param from_date: e.g., 2016-01-01
    :param to_date: e.g., 2016-02-28
    """
    provider = Kofia()

    app = create_app(__name__)
    with app.app_context():
        asset = get_asset_by_fund_code(code)

        # FIXME: Target asset should also be determined by asset.data.code
        base_asset = Asset.query.filter_by(name='KRW').first()

        data = provider.fetch_data(
            code, parse_date(from_date), parse_date(to_date))
        for date, unit_price, quantity in data:
            log.info('Import data on {}', date)
            unit_price /= 1000.0
            try:
                AssetValue.create(
                    asset=asset, base_asset=base_asset,
                    evaluated_at=date, close=unit_price,
                    granularity=Granularity.day,
                    source='kofia')
            except IntegrityError:
                log.warn('Identical record has been found for {}. Skipping.',
                         date)
                db.session.rollback()
Esempio n. 3
0
def test_kofia_fetch_data():
    provider = Kofia()
    from_date, to_date = parse_date("2016-05-01"), parse_date("2016-05-30")
    data = provider.fetch_data("KR5223941018", from_date, to_date)

    for date, unit_price, quantity in data:
        assert isinstance(date, datetime)
        assert from_date <= date <= to_date
        assert isinstance(unit_price, float)
        assert isinstance(quantity, float)
Esempio n. 4
0
def test_kofia_fetch_data():
    provider = Kofia()
    from_date, to_date = parse_date('2016-05-01'), parse_date('2016-05-30')
    data = provider.fetch_data('KR5223941018', from_date, to_date)

    for date, unit_price, quantity in data:
        assert isinstance(date, datetime)
        assert from_date <= date <= to_date
        assert isinstance(unit_price, float)
        assert isinstance(quantity, float)