Skip to content

Commit

Permalink
Draft template for VTB statement import: assets loading was added
Browse files Browse the repository at this point in the history
  • Loading branch information
titov-vv committed Jan 28, 2024
1 parent 9d4243a commit f12b95f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
38 changes: 37 additions & 1 deletion jal/data_import/broker_statements/vtb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import re
from jal.data_import.statement_xls import StatementXLS
from jal.data_import.statement import FOF
from jal.data_import.statement import FOF, Statement_ImportError


JAL_STATEMENT_CLASS = "StatementVTB"
Expand All @@ -15,6 +16,11 @@ class StatementVTB(StatementXLS):
"name": "Валюта",
"cash_end": "Плановый",
}
asset_section = "Отчет об остатках ценных бумаг"
asset_columns = {
"name": "Наименование ценной бумаги, \n№ гос. регистрации, ISIN",
"currency": "Валюта цены \n\(номинала для облигаций\)"
}

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -49,6 +55,36 @@ def _load_money(self):
account = [x for x in self._data[FOF.ACCOUNTS] if x['id'] == account_id][0]
account["cash_end"] = self.account_end_balance[currency]

def _load_assets(self):
AssetPattern = r"^(?P<name>.*), (?P<reg_number>.*), (?P<isin>.*)$"
cnt = 0
asset_type = ''
row, headers = self.find_section_start(self.asset_section, self.asset_columns)
if row < 0:
return False
while row < self._statement.shape[0]:
if self._statement[self.HeaderCol][row].startswith('ИТОГО') or self._statement[self.HeaderCol][row] == '':
break
asset_name = self._statement[headers['name']][row]
parts = re.match(AssetPattern, asset_name, re.IGNORECASE)
if parts is None:
asset_type = asset_name
row += 1
continue
asset_data = parts.groupdict()
if len(asset_data) != AssetPattern.count("(?P<"): # check that expected number of groups was matched
raise Statement_ImportError(self.tr("Asset name miss some data ") + f"'{asset_name}'")
currency = self._statement[headers['currency']][row]
try:
currency_code = self.currency_substitutions[currency]
except KeyError:
currency_code = currency
_ = self.asset_id({'isin': asset_data['isin'], 'reg_number': asset_data['reg_number'],
'currency': currency_code, 'search_offline': True, 'search_online': "MOEX"})
cnt += 1
row += 1
logging.info(self.tr("Securities loaded: ") + f"{cnt}")

def _load_deals(self):
pass

Expand Down
22 changes: 19 additions & 3 deletions tests/test_data/vtb.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,29 @@
],
"assets": [
{"id": 1, "name": "", "type": "money"},
{"id": 2, "name": "", "type": "money"}
{"id": 2, "name": "", "type": "money"},
{"id": 3, "isin": "RU000A102ZT7", "name": "МФК Быстроденьги 02", "type": "bond"},
{"id": 4, "isin": "RU000A102TL7", "name": "МФК Займер - 01", "type": "bond"},
{"id": 5, "isin": "RU000A103117", "name": "МВ ФИНАНС 001Р-01", "type": "bond"},
{"id": 6, "isin": "RU000A1014L8", "name": "БПИФ Ликвидность УК ВИМ", "type": "etf"},
{"id": 7, "isin": "RU0009046510", "name": "Северсталь (ПАО)ао", "type": "stock"}
],
"symbols": [
{"id": 1, "asset": 1, "symbol": "RUB"},
{"id": 2, "asset": 2, "symbol": "USD"}
{"id": 2, "asset": 2, "symbol": "USD"},
{"id": 3, "asset": 3, "symbol": "БДеньги-02", "currency": "RUB", "note": "MOEX"},
{"id": 4, "asset": 4, "symbol": "Займер 01", "currency": "RUB", "note": "MOEX"},
{"id": 5, "asset": 5, "symbol": "МВ ФИН 1Р1", "currency": "RUB", "note": "MOEX"},
{"id": 6, "asset": 6, "symbol": "LQDT", "currency": "RUB", "note": "MOEX"},
{"id": 7, "asset": 7, "symbol": "CHMF", "currency": "RUB", "note": "MOEX"}
],
"assets_data": [
{"id": 1, "asset": 3, "reg_number": "4-01-00487-R", "expiry": 1711584000, "principal": 1000.0},
{"id": 2, "asset": 4, "reg_number": "4-01-00587-R", "expiry": 1708128000, "principal": 1000.0},
{"id": 3, "asset": 5, "reg_number": "4B02-01-00590-R-001P", "expiry": 1713398400, "principal": 1000.0},
{"id": 4, "asset": 6, "reg_number": "3915"},
{"id": 5, "asset": 7, "reg_number": "1-02-00143-A", "principal": 0.01}
],
"assets_data": [],
"trades": [],
"income_spending": [],
"transfers": [],
Expand Down

0 comments on commit f12b95f

Please sign in to comment.