def import_miraeasset_foreign_records( fin: io.TextIOWrapper, account: Account, ): provider = Miraeasset() asset_krw = Asset.get_by_symbol('KRW') for r in provider.parse_foreign_transactions(fin): assert r.currency != 'KRW' # FIXME: Handle a case where asset cannot be found target_asset = Asset.get_by_symbol(r.currency) if r.category == '해외주매수': asset_stock = Asset.get_by_isin(r.code) make_double_record_transaction( r.synthesized_created_at, account, target_asset, -r.amount, asset_stock, r.quantity) elif r.category == '해외주매도': asset_stock = Asset.get_by_isin(r.code) make_double_record_transaction( r.synthesized_created_at, account, asset_stock, -r.quantity, target_asset, r.amount) elif r.category == '해외주배당금': make_single_record_transaction( r.synthesized_created_at, account, target_asset, r.amount) elif r.category == '환전매수': local_amount = int(r.raw_columns[6]) # amount in KRW make_double_record_transaction( r.synthesized_created_at, account, asset_krw, -local_amount, target_asset, r.amount) elif r.category == '환전매도': raise NotImplementedError elif r.category == '외화인지세': make_single_record_transaction( r.synthesized_created_at, account, target_asset, -r.amount) else: raise ValueError('Unknown record category: {0}'.format(r.category))
def test_get_asset_by_isin_non_existing(stock_asset_nvda): with pytest.raises(AssetNotFoundException): Asset.get_by_isin('non-exisiting')
def test_get_asset_by_isin(stock_asset_nvda): asset = Asset.get_by_isin('US67066G1040') assert asset.code == 'NVDA'
def test_get_asset_by_isin(stock_asset_nvda): asset = Asset.get_by_isin("US67066G1040") assert asset.code == "NVDA"