Skip to content

Commit 54860e2

Browse files
authored
Fix errors (#21)
1 parent 0990036 commit 54860e2

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

quantflow/cli/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Any
55

66
import click
7+
from fluid.utils.http_client import HttpResponseError
78
from prompt_toolkit import PromptSession
89
from prompt_toolkit.completion import NestedCompleter
910
from prompt_toolkit.formatted_text import HTML
@@ -82,6 +83,7 @@ def handle_command(self, text: str) -> None:
8283
click.exceptions.MissingParameter,
8384
click.exceptions.NoSuchOption,
8485
click.exceptions.UsageError,
86+
HttpResponseError,
8587
) as e:
8688
self.error(e)
8789

quantflow/cli/commands/crypto.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def volatility(currency: str, length: int, height: int, chart: bool) -> None:
3333
"""Provides information about historical volatility for given cryptocurrency"""
3434
ctx = QuantContext.current()
3535
df = asyncio.run(get_volatility(ctx, currency))
36+
df["volatility"] = df["volatility"].map(lambda p: round_to_step(p, "0.01"))
3637
if chart:
3738
data = df["volatility"].tolist()[:length]
3839
ctx.qf.print(plot(data, {"height": height}))
@@ -99,7 +100,13 @@ def prices(symbol: str, height: int, length: int, chart: bool, frequency: str) -
99100
data = list(reversed(df["close"].tolist()[:length]))
100101
ctx.qf.print(plot(data, {"height": height}))
101102
else:
102-
ctx.qf.print(df_to_rich(df[["date", "open", "high", "low", "close", "volume"]]))
103+
ctx.qf.print(
104+
df_to_rich(
105+
df[["date", "open", "high", "low", "close", "volume"]].sort_values(
106+
"date"
107+
)
108+
)
109+
)
103110

104111

105112
async def get_volatility(ctx: QuantContext, currency: str) -> pd.DataFrame:

quantflow/data/deribit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pandas as pd
66
from dateutil.parser import parse
7-
from fluid.utils.http_client import AioHttpClient, HttpResponse
7+
from fluid.utils.http_client import AioHttpClient, HttpResponse, HttpResponseError
88

99
from quantflow.options.surface import VolSecurityType, VolSurfaceLoader
1010
from quantflow.utils.numbers import round_to_step, to_decimal
@@ -118,6 +118,8 @@ async def get_path(self, path: str, **kw: Any) -> dict:
118118

119119
async def to_result(self, response: HttpResponse) -> list[dict]:
120120
data = await response.json()
121+
if "error" in data:
122+
raise HttpResponseError(response, data["error"])
121123
return cast(list[dict], data["result"])
122124

123125
async def to_df(self, response: HttpResponse) -> pd.DataFrame:

0 commit comments

Comments
 (0)