Skip to content

Commit b39c1d2

Browse files
authored
Add fred (#10)
1 parent 7d0bf90 commit b39c1d2

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

quantflow/cli/config.py

Whitespace-only changes.

quantflow/data/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# re-export aio-fluid's http clients
2+
from fluid.utils.http_client import AioHttpClient, HttpxClient
3+
4+
__all__ = ["AioHttpClient", "HttpxClient"]

quantflow/data/fmp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from dataclasses import dataclass, field
33
from datetime import date, timedelta
44
from typing import Any, cast
5-
from fluid.utils.http_client import AioHttpClient
5+
from .client import AioHttpClient
66
from fluid.utils.data import compact_dict
77
import pandas as pd
88
from enum import StrEnum

quantflow/data/fred.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from .client import AioHttpClient
2+
from dataclasses import dataclass, field
3+
from typing import Any, cast
4+
import os
5+
6+
7+
@dataclass
8+
class Fred(AioHttpClient):
9+
url: str = "https://api.stlouisfed.org/fred"
10+
key: str = field(default_factory=lambda: os.environ.get("FRED_API_KEY", ""))
11+
12+
async def categiories(self, **kw: Any) -> list[dict]:
13+
return await self.get_path("category", **kw)
14+
15+
# Internals
16+
async def get_path(self, path: str, **kw: Any) -> list[dict]:
17+
result = await self.get(f"{self.url}/{path}", **self.params(**kw))
18+
return cast(list[dict], result)
19+
20+
def params(self, params: dict | None = None, **kw: Any) -> dict:
21+
params = params.copy() if params is not None else {}
22+
params.update(api_key=self.key, file_type="json")
23+
return {"params": params, **kw}

0 commit comments

Comments
 (0)