experiments integrating mwfin

This commit is contained in:
Daniil Fajnberg 2022-01-03 22:10:26 +01:00
parent 711e24d244
commit d0aedfc21f
3 changed files with 39 additions and 0 deletions

View File

6
src/mw_stockfin/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class MwStockfinConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'mw_stockfin'

View File

@ -0,0 +1,33 @@
from django_stockfin_db.models import FinancialPosition, ReportingPeriod, Company, Figure
from mwfin import get_balance_sheet
from mwfin.functions import ResultDict, RowData
def end_date_to_reporting_period(date_str: str) -> ReportingPeriod:
"""Convert an end date string into parameters for a ReportingPeriod, `get_or_create` the object and return it."""
pass
def get_or_create_position(name: str, parent_position: FinancialPosition = None) -> FinancialPosition:
return FinancialPosition.objects.get_or_create(name=name, parent=parent_position)
def data_row_to_figures(company: Company, position: FinancialPosition, data: RowData):
pass
def save_single_result_dict(fin_stmt: str, symbol: str, result_dict: ResultDict):
company = Company.objects.get_or_create(symbol=symbol)
def result_dicts_to_db(fin_stmt: str, **data: ResultDict):
for symbol, result_dict in data.items():
save_single_result_dict(fin_stmt, symbol, result_dict)
async def main(*symbols: str):
data = await get_balance_sheet(*symbols)
if len(symbols) == 1:
save_single_result_dict('BS', symbols[0], data)
result_dicts_to_db('BS', **data)