Skip to content

Commit b9b2183

Browse files
committed
Add fred
1 parent a9be4ee commit b9b2183

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

quantflow/cli/command.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import click
2+
3+
4+
@click.command()
5+
def help() -> None:
6+
print("Help!")

quantflow/cli/config.py

Whitespace-only changes.

quantflow/data/fred.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from fluid.utils.http_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) -> 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)