Beispiel #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()
Beispiel #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()
Beispiel #3
0
def test_get_asset_by_fund_code_non_existing(asset_sp500):
    with pytest.raises(AssetNotFoundException):
        get_asset_by_fund_code('non-exisiting')
Beispiel #4
0
def test_get_asset_by_fund_code(asset_sp500):
    asset = get_asset_by_fund_code('KR5223941018')
    assert asset.name == 'KB Star S&P500'
Beispiel #5
0
def test_get_asset_by_fund_code(asset_sp500):
    asset = get_asset_by_fund_code("KR5223941018")
    assert asset.name == "KB Star S&P500"
Beispiel #6
0
def test_get_asset_by_fund_code_non_existing(asset_sp500):
    with pytest.raises(AssetNotFoundException):
        get_asset_by_fund_code('non-exisiting')
Beispiel #7
0
def test_get_asset_by_fund_code(asset_sp500):
    asset = get_asset_by_fund_code('KR5223941018')
    assert asset.name == 'KB Star S&P500'