Skip to content

Commit 5b5dce7

Browse files
committed
Add frequency enum
1 parent 285137f commit 5b5dce7

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Install poetry
2828
run: pip install -U pip poetry
2929
- name: Install dependencies no book
30-
run: poetry install
30+
run: poetry install --all-extras
3131
- name: run tests no book
3232
run: make tests
3333
- name: Install dependencies

quantflow/data/fmp.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from fluid.utils.http_client import AioHttpClient
66
from fluid.utils.data import compact_dict
77
import pandas as pd
8+
from enum import StrEnum
89

910
from quantflow.utils.dates import isoformat
1011

@@ -14,6 +15,17 @@ class FMP(AioHttpClient):
1415
url: str = "https://financialmodelingprep.com/api"
1516
key: str = field(default_factory=lambda: os.environ.get("FMP_API_KEY", ""))
1617

18+
class freq(StrEnum):
19+
"""FMP historical frequencies"""
20+
21+
one_min = "1min"
22+
five_min = "5min"
23+
fifteen_min = "15min"
24+
thirty_min = "30min"
25+
one_hour = "1hour"
26+
four_hour = "4hour"
27+
daily = ""
28+
1729
async def stocks(self, **kw: Any) -> list[dict]:
1830
return await self.get_path("v3/stock/list", **kw)
1931

@@ -116,6 +128,7 @@ async def search(
116128
async def prices(
117129
self, ticker: str, frequency: str = "", to_date: bool = False, **kw: Any
118130
) -> pd.DataFrame:
131+
"""Historical prices, daily if frequency is not provided"""
119132
base = (
120133
"historical-price-full/"
121134
if not frequency
@@ -148,6 +161,10 @@ def historical_frequencies_annulaized(self) -> dict:
148161
one_year = 525600
149162
return {k: v / one_year for k, v in self.historical_frequencies().items()}
150163

164+
# Crypto
165+
async def crypto_list(self) -> list[dict]:
166+
return await self.get_path("v3/symbol/available-cryptocurrencies")
167+
151168
# Internals
152169
async def get_path(self, path: str, **kw: Any) -> list[dict]:
153170
result = await self.get(f"{self.url}/{path}", **self.params(**kw))

quantflow_tests/test_data.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22

33
import pytest
44

5-
try:
6-
from quantflow.data.fmp import FMP
7-
except ImportError:
8-
FMP = None # type: ignore
5+
from quantflow.data.fmp import FMP
96

10-
pytestmark = pytest.mark.skipif(
11-
FMP is None or not FMP().key, reason="No FMP API key found"
12-
)
7+
pytestmark = pytest.mark.skipif(not FMP().key, reason="No FMP API key found")
138

149

1510
@pytest.fixture
@@ -24,7 +19,7 @@ def test_client(fmp: FMP) -> None:
2419

2520

2621
async def test_historical(fmp: FMP) -> None:
27-
df = await fmp.prices("BTCUSD")
22+
df = await fmp.prices("BTCUSD", fmp.freq.one_hour)
2823
assert df["close"] is not None
2924

3025

0 commit comments

Comments
 (0)