more mbleh

This commit is contained in:
Giulio De Pasquale 2025-10-15 19:03:36 +01:00
parent a06dcab7f9
commit b060d988e7
4 changed files with 970 additions and 105 deletions

1
.gitignore vendored
View File

@ -208,3 +208,4 @@ poetry.toml
pyrightconfig.json
# End of https://www.toptal.com/developers/gitignore/api/python,go
.aider*

View File

@ -5,20 +5,12 @@ from dotenv import load_dotenv
from typing import NoReturn
from paperone.utils import (
parse_date_yyyymmdd,
days_range_from,
format_date_readable,
is_trading_day,
get_last_n_trading_days,
)
from os import environ
from paperone.taapi import TaapiClient, IndicatorEnum
from rich.progress import (
Progress,
SpinnerColumn,
TextColumn,
BarColumn,
TaskProgressColumn,
TimeRemainingColumn,
)
from paperone.client import Client
from rich.progress import track
load_dotenv()
@ -30,100 +22,15 @@ def main() -> NoReturn:
print("API_KEY not set")
exit(0)
client = Client(api_key)
date = parse_date_yyyymmdd("20250821")
days_range = 60
dates_range = days_range_from(date, days_range)
tickers = ["VIX"]
indicators = list(IndicatorEnum)
dates_range = get_last_n_trading_days(date, days_range)
# tickers = ["VIX"]
# indicators = list(IndicatorEnum)
with Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
BarColumn(),
TaskProgressColumn(),
TimeRemainingColumn(),
) as progress:
# Overall ticker progress
ticker_task = progress.add_task(
"[cyan]Processing tickers...", total=len(tickers)
)
with TaapiClient(api_key) as client:
for ticker in [x for x in tickers if x in client.get_available_tickers()]:
# Update ticker task
progress.update(
ticker_task, description=f"[cyan]Processing {ticker}..."
)
# Price loading subtask
price_task = progress.add_task(
f"[green] └─ Loading prices for {ticker}...",
total=len(dates_range),
)
prices = {}
for d in dates_range:
progress.update(
price_task,
description=f"[green] └─ Loading {ticker} price for {format_date_readable(d)}...",
advance=1,
)
result = client.query_price_on_day(ticker, d)
if result:
prices[d.day] = result.value
# Remove price task when done
progress.remove_task(price_task)
# Indicator loading subtask
indicator_task = progress.add_task(
f"[yellow] └─ Loading indicators for {ticker}...",
total=len(indicators),
)
for indicator_enum in indicators:
progress.update(
indicator_task,
description=f"[yellow] └─ Loading {ticker} indicator: {indicator_enum.name}...",
advance=1,
)
try:
indicator_results = client.query_indicator(
ticker, indicator_enum.value, date, results=days_range
)
except Exception as e:
progress.console.print(
f"[red]Error retrieving {indicator_enum.name}: {e}"
)
continue
if not indicator_results:
continue
progress.console.print(
f"\n[bold]{ticker} - {indicator_enum.name}:[/bold]"
)
trading_day_values = [
x for x in indicator_results if is_trading_day(x.datetime)
]
for r in trading_day_values:
price_str = (
f"${prices[r.datetime.day]:.2f}"
if r.datetime.day in prices
else "N/A"
)
progress.console.print(
f" {format_date_readable(r.datetime)} ({price_str}) - {indicator_enum.name}: {r.value:.2f}"
)
# Remove indicator task when done
progress.remove_task(indicator_task)
# Advance overall ticker progress
progress.advance(ticker_task)
for x in track([x for x in dates_range if is_trading_day(x)]):
print(client.ticker_data_for("AAPL", x))
exit(0)

958
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,10 @@ dependencies = [
"requests (>=2.32.5,<3.0.0)",
"python-dotenv (>=1.1.1,<2.0.0)",
"beartype (>=0.22.2,<0.23.0)",
"typer (>=0.19.2,<0.20.0)"
"typer (>=0.19.2,<0.20.0)",
"yfinance (>=0.2.66,<0.3.0)",
"ipython (>=9.6.0,<10.0.0)",
"pandas-market-calendars (>=5.1.1,<6.0.0)"
]