Skip to content

Commit

Permalink
Add a missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
suminb committed Jul 3, 2016
1 parent a5dce2a commit 853f62e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions finance/importers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""A collection of data import functions."""
from datetime import datetime

from typedecorator import typed

from finance.models import Asset, AssetValue, get_asset_by_stock_code, \
Granularity
from finance.providers.provider import AssetValueProvider


@typed
def import_stock_values(provider: AssetValueProvider, code: str,
from_date: datetime, to_date: datetime):
asset = get_asset_by_stock_code(code)
data = provider.fetch_data(code, from_date, to_date)
for date, open_, high, low, close_, volume, adj_close in data:
AssetValue.create(
evaluated_at=date, granularity=Granularity.day, asset=asset,
open=open_, high=high, low=low, close=close_, volume=volume)

0 comments on commit 853f62e

Please sign in to comment.