예제 #1
0
def test_miraeasset_records():
    """Test with miraeasset_records.csv. Note that the .csv file is encoded
    in euc-kr.
    """
    filename = os.path.join(BASE_PATH, "samples", "miraeasset_records_euckr.csv")
    provider = Miraeasset()
    records = list(provider.read_records(filename))
    # TODO: We need more comprehensive test cases
    assert len(records) == 6
예제 #2
0
class RecordCSVPlainReader(AbstractReader):
    def __init__(self):
        # TODO: Allow other providers
        self.provider = Miraeasset()

    def read(self, filename):
        for row in self.provider.read_records(filename):
            yield row
예제 #3
0
def test_miraeasset_transactions(param):
    provider = Miraeasset()
    filename = os.path.join(
        BASE_PATH, 'samples', 'miraeasset_{}.csv'.format(param))
    with open(filename) as fin:
        if param == 'local':
            records = provider.parse_local_transactions(fin)
        elif param == 'foreign':
            records = provider.parse_foreign_transactions(fin)
        else:
            raise ValueError('Unknown transaction kind: {}'.format(param))

        for record in records:
            assert isinstance(record.created_at, datetime)
            assert isinstance(record.seq, int)
            assert isinstance(record.quantity, int)
            assert record.currency in ['KRW', 'USD']
예제 #4
0
def test_miraeasset_transactions(param):
    provider = Miraeasset()
    filename = os.path.join(BASE_PATH, 'samples',
                            'miraeasset_{}.csv'.format(param))
    with open(filename) as fin:
        if param == 'local':
            records = provider.parse_local_transactions(fin)
        elif param == 'foreign':
            records = provider.parse_foreign_transactions(fin)
        else:
            raise ValueError('Unknown transaction kind: {}'.format(param))

        for record in records:
            assert isinstance(record.created_at, datetime)
            assert isinstance(record.seq, int)
            assert isinstance(record.quantity, int)
            assert record.currency in ['KRW', 'USD']
예제 #5
0
파일: importers.py 프로젝트: suminb/finance
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))
예제 #6
0
 def __init__(self):
     # TODO: Allow other providers
     self.provider = Miraeasset()
예제 #7
0
def parse_miraeasset_local_data(filename):
    """Parses CSV file exported in 거래내역조회 (0650)."""
    provider = Miraeasset()
    _parse_miraeasset_data(filename, provider.parse_local_transactions)
예제 #8
0
def parse_miraeasset_foreign_data(filename):
    """Parses a CSV file exported in 해외거래내역 (9465)."""
    provider = Miraeasset()
    _parse_miraeasset_data(filename, provider.parse_foreign_transactions)