Skip to content

Commit

Permalink
Add frequency to command line chart
Browse files Browse the repository at this point in the history
  • Loading branch information
lsbardel committed Mar 24, 2024
1 parent 6505ab7 commit e7e03cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 5 additions & 1 deletion notebooks/data/timeseries.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ cli = FMP()
```

```{code-cell} ipython3
prices = await cli.prices("aapl")
prices = await cli.prices("ethusd")
```

```{code-cell} ipython3
candlestick_plot(prices).update_layout(height=500)
```

```{code-cell} ipython3
prices
```

```{code-cell} ipython3
```
21 changes: 15 additions & 6 deletions quantflow/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

dotenv.load_dotenv()

FREQUENCIES = tuple(FMP().historical_frequencies())


@click.group()
def qf():
Expand Down Expand Up @@ -41,16 +43,23 @@ def profile(symbol: str):
show_default=True,
help="Number of data points",
)
def chart(symbol: str, height: int, length: int):
@click.option(
"-f",
"--frequency",
type=click.Choice(FREQUENCIES),
default="",
help="Number of data points",
)
def chart(symbol: str, height: int, length: int, frequency: str) -> None:
"""Symbol chart"""
df = asyncio.run(get_prices(symbol))
data = df["close"].tolist()
print(plot(data[:length], {"height": height}))
df = asyncio.run(get_prices(symbol, frequency))
data = list(reversed(df["close"].tolist()[:length]))
print(plot(data, {"height": height}))


async def get_prices(symbol: str) -> pd.DataFrame:
async def get_prices(symbol: str, frequency: str) -> pd.DataFrame:
async with FMP() as cli:
return await cli.prices(symbol)
return await cli.prices(symbol, frequency)


async def get_profile(symbol: str) -> dict:
Expand Down

0 comments on commit e7e03cf

Please sign in to comment.