Skip to content

Commit 43ad0b5

Browse files
authored
Merge pull request #2 from dc-aichara/feat/poetry
Feat/poetry
2 parents 3115941 + c267239 commit 43ad0b5

File tree

15 files changed

+2115
-136
lines changed

15 files changed

+2115
-136
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Python package
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
- release/*
9+
pull_request:
10+
branches:
11+
- main
12+
- master
13+
14+
jobs:
15+
build:
16+
17+
runs-on: ubuntu-latest
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
python-version: ["3.9"]
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v3
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
- name: Install Poetry and dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install poetry
33+
poetry install
34+
- name: Check Code Format
35+
run: |
36+
poetry run black .
37+
poetry run isort .
38+
poetry run pflake8 . --config pyproject.toml
39+
- name: Static Type Checking
40+
run: |
41+
poetry run mypy --config-file=pyproject.toml .
42+
- name: Test with pytest
43+
run: |
44+
poetry run pytest tests -s -vv --durations=0 \
45+
--junitxml=test_report.xml \
46+
--cov-report=term \
47+
--cov-report xml PriceIndices \
48+
--cov=PriceIndices
49+
poetry run coverage xml
50+
- name: Upload coverage to Codecov
51+
uses: codecov/codecov-action@v3
52+
with:
53+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_STORE
22
__pycache__/
3-
dist/
43
PriceIndices.egg-info/
54
bist/
5+
dist/
6+
build/

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
repos:
2+
- repo: https://github.com/ambv/black
3+
rev: 23.1.0
4+
hooks:
5+
- id: black
6+
args: [--config=pyproject.toml]
7+
- repo: https://github.com/csachs/pyproject-flake8
8+
rev: v6.0.0.post1
9+
hooks:
10+
- id: pyproject-flake8
11+
entry: pflake8
12+
args: [--config=pyproject.toml]
13+
- repo: https://github.com/kynan/nbstripout
14+
rev: 0.6.1
15+
hooks:
16+
- id: nbstripout
17+
files: ".ipynb"
18+
- repo: https://github.com/pre-commit/mirrors-mypy
19+
rev: v0.991
20+
hooks:
21+
- id: mypy
22+
args: [--config-file=pyproject.toml]
23+
additional_dependencies: [types-requests]
24+
- repo: https://github.com/pre-commit/mirrors-isort
25+
rev: v5.10.1
26+
hooks:
27+
- id: isort

ChangeLog.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
# PriceIndices ChangeLog
22

3+
## Version
4+
5+
## 1.4.0
6+
7+
* Refactored code
8+
* Adapted poetry for development
9+
* Updated documentation.
10+
11+
## Version 1.3.0
12+
13+
* Optimize Indicators calculations.
14+
* Minor bug fixes.
15+
* Refactored code.
16+
317
## Version 1.2.1
418

5-
- Fixed documentation
19+
- Fixed documentation.
620

721
## Version 1.2.0
822

PriceIndices/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
from importlib.metadata import version
2+
3+
__version__ = version("PriceIndices")
4+
15
from .crypto_history import MarketHistory
26
from .price_indicators import Indices
3-
4-
__version__ = "1.3.0"

PriceIndices/crypto_history.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import requests
1+
import warnings
2+
from typing import Optional
3+
24
import pandas as pd
3-
from datetime import datetime
4-
from typing import Any, Optional
5+
import requests
56
from requests.adapters import HTTPAdapter
67
from requests.packages.urllib3.util.retry import Retry
7-
import warnings
88

99
warnings.filterwarnings("ignore")
1010

1111

1212
class MarketHistory(object):
13-
__Crypto_Market_Base_URL = "https://web-api.coinmarketcap.com/v1/cryptocurrency/ohlcv/historical?convert=USD&slug="
13+
__Crypto_Market_Base_URL = "https://web-api.coinmarketcap.com/v1/cryptocurrency/ohlcv/historical?convert=USD&slug=" # noqa
1414

15-
def __init__(self,
16-
base_url: Optional[str] = __Crypto_Market_Base_URL) -> None:
15+
def __init__(
16+
self, base_url: Optional[str] = __Crypto_Market_Base_URL
17+
) -> None:
1718
self.base_url = base_url
1819
self.request_timeout = 120
1920

@@ -23,7 +24,7 @@ def __init__(self,
2324
)
2425
self.session.mount("http://", HTTPAdapter(max_retries=retries))
2526

26-
def __request(self, url: str) -> pd.DataFrame:
27+
def __request(self, url: str) -> Optional[pd.DataFrame]:
2728
try:
2829
response = self.session.get(url, timeout=self.request_timeout)
2930
response.raise_for_status()
@@ -39,10 +40,10 @@ def __request(self, url: str) -> pd.DataFrame:
3940
del df["timestamp"]
4041
return df
4142
except Exception as e:
42-
raise
43+
raise e
4344

4445
def get_history(
45-
self, coin_id: str, start_date: str, end_date: str
46+
self, coin_id: str, start_date: str, end_date: str
4647
) -> Optional[pd.DataFrame]:
4748
"""
4849
Get historical market data of a cryptocurrency from CoinMarketCap.
@@ -63,12 +64,14 @@ def get_history(
6364
except Exception as e:
6465
print(e)
6566
print(
66-
'Please, check inputs. Coin id, and dates are strings. Date '
67+
"Please, check inputs. Coin id, and dates are strings. Date "
6768
'format is "YYYY-MM-DD"'
6869
)
70+
return None
6971

70-
def get_price(self, coin_id: str, start_date: str, end_date: str) -> \
71-
Optional[pd.DataFrame]:
72+
def get_price(
73+
self, coin_id: str, start_date: str, end_date: str
74+
) -> Optional[pd.DataFrame]:
7275
"""
7376
Get historical market price data (closing price) of a cryptocurrency
7477
from CoinMarketCap.
@@ -87,12 +90,14 @@ def get_price(self, coin_id: str, start_date: str, end_date: str) -> \
8790

8891
try:
8992
df = self.__request(url)
93+
assert type(df) == pd.DataFrame
9094
df = df[["date", "close"]]
9195
df.columns = ["date", "price"]
9296
return df
9397
except Exception as e:
9498
print(
9599
e,
96-
'Please, check inputs Coin id, and dates are strings. Date '
100+
"Please, check inputs Coin id, and dates are strings. Date "
97101
'format is "YYYY-MM-DD"',
98102
)
103+
return None

0 commit comments

Comments
 (0)