Skip to content

Commit

Permalink
refactor: Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
suminb committed May 23, 2024
1 parent 767df4d commit bae843a
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 282 deletions.
33 changes: 1 addition & 32 deletions finance/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
Transaction,
User,
)
from finance.providers import Kofia, Yahoo
from finance.providers import Kofia
from finance.utils import (
date_to_datetime,
extract_numbers,
insert_stock_record,
parse_date,
Expand Down Expand Up @@ -182,36 +181,6 @@ def import_sp500_records():
session.rollback()


@cli.command()
@click.argument("stock_code") # e.g., NVDA, 027410.KS
@click.option("-s", "--start", "start_date", help="Start date (e.g., 2017-01-01)")
@click.option("-e", "--end", "end_date", help="End date (e.g., 2017-12-31)")
def fetch_stock_values(stock_code, start_date, end_date):
"""Fetches daily stock values from Yahoo Finance."""

start_date = date_to_datetime(
parse_date(start_date if start_date is not None else -30 * 3600 * 24)
)
end_date = date_to_datetime(parse_date(end_date if end_date is not None else 0))

if start_date > end_date:
raise ValueError("start_date must be equal to or less than end_date")

provider = Yahoo()
rows = provider.asset_values(stock_code, start_date, end_date, Granularity.day)

for row in rows:
# TODO: Write a function to handle this for generic cases
# TODO: Convert the timestamp to an ISO format
# NOTE: The last column is data source. Not sure if this is an elegant
# way to handle this.

# FIXME: Think of a better way to handle this
dt = row[0].isoformat()

print(", ".join([dt] + [str(c) for c in row[1:]] + ["yahoo"]))


# NOTE: This will probably be called by AWS Lambda
# TODO: Load data from stdin
@cli.command()
Expand Down
52 changes: 0 additions & 52 deletions finance/fetchers.py

This file was deleted.

2 changes: 0 additions & 2 deletions finance/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from finance.providers.kofia import Kofia
from finance.providers.miraeasset import Miraeasset
from finance.providers.provider import AssetValueProvider, Provider, RecordProvider
from finance.providers.yahoo import Yahoo


__all__ = [
Expand All @@ -12,7 +11,6 @@
"Miraeasset",
"Provider",
"RecordProvider",
"Yahoo",
]


Expand Down
115 changes: 0 additions & 115 deletions finance/providers/yahoo.py

This file was deleted.

12 changes: 1 addition & 11 deletions tests/test___main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from finance.__main__ import (
create_all,
drop_all,
fetch_stock_values,
import_fund,
import_sp500_records,
import_stock_records,
Expand All @@ -16,7 +15,7 @@
insert_test_data,
)
from finance.exceptions import AssetNotFoundException
from finance.models import StockAsset, deposit
from finance.models import StockAsset
from finance.utils import load_stock_codes


Expand Down Expand Up @@ -64,15 +63,6 @@ def test_import_non_existing_fund():
assert isinstance(result.exception, AssetNotFoundException)


@pytest.mark.skip(reason="Yahoo Finance provider is scheduled to be deprecated.")
def test_fetch_stock_values():
runner = CliRunner()
result = runner.invoke(
fetch_stock_values, ["NVDA", "-s", "2017-01-01", "-e", "2017-01-15"]
)
assert result.exit_code == 0


# NOTE: This test case may intermittently fail as some of the stock codes
# is not available for download in Google Finance
def test_import_stock_values():
Expand Down
41 changes: 0 additions & 41 deletions tests/test_fetchers.py

This file was deleted.

30 changes: 1 addition & 29 deletions tests/test_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import pytest

from finance.models import Granularity
from finance.providers import Dart, Kofia, Miraeasset
from finance.providers import Dart, Kofia
from finance.providers.dart import Report as DartReport
from finance.providers.record import Decimal, Float
from finance.providers.yahoo import Yahoo
from finance.utils import parse_date

BASE_PATH = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -98,30 +97,3 @@ def test_dart_fetch_data_with_invalid_code():
provider = Dart()
with pytest.raises(ValueError):
list(provider.fetch_reports("_", "_"))


@pytest.mark.skip
@pytest.mark.parametrize("granularity", [Granularity.min, Granularity.day])
def test_yahoo_provider(granularity):
provider = Yahoo()
symbol = "MSFT"
start_time = datetime.combine(parse_date(-5), time(0))
end_time = datetime.utcnow()
asset_values = provider.asset_values(symbol, start_time, end_time, granularity)
flag = False
for asset_value in asset_values:
flag = True
assert len(asset_value) == 6
assert all([c is not None for c in asset_value])
assert flag


@pytest.mark.skip
def test_yahoo_provider_with_invalid_symbol():
provider = Yahoo()
symbol = "(invalid)"
end_time = datetime.utcnow()
start_time = end_time - timedelta(days=1)

with pytest.raises(ValueError):
provider.asset_values(symbol, start_time, end_time, Granularity.day)

0 comments on commit bae843a

Please sign in to comment.