From 52b55f4cb803c00e89a4c1a0ae8470fb761969a8 Mon Sep 17 00:00:00 2001 From: Luke Kim <80174+lukekim@users.noreply.github.com> Date: Sun, 21 Apr 2024 20:38:11 -0700 Subject: [PATCH] Remove deprecated Asset Prices API support (#84) * Remove deprecated Asset Prices API support * Update spicepy/_http.py Co-authored-by: Phillip LeBlanc --------- Co-authored-by: Phillip LeBlanc --- CONTRIBUTING.md | 10 +++--- LICENSE | 2 +- spicepy/_client.py | 5 --- spicepy/_http.py | 2 +- spicepy/prices.py | 88 ---------------------------------------------- 5 files changed, 7 insertions(+), 100 deletions(-) delete mode 100644 spicepy/prices.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 009e538..3c3450e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ -## Contributing to spicepy +# Contributing to spicepy -### Developing +## Developing The development branch is `trunk`. This is the branch that all pull requests should be made against. @@ -13,7 +13,7 @@ To develop locally: 2. Create a new branch: - ``` + ```bash git checkout -b MY_BRANCH_NAME ``` @@ -21,7 +21,7 @@ To develop locally: 4. Install the dependencies with: - ``` + ```bash # Run this command in the root of the repository pip install -e . ``` @@ -34,6 +34,6 @@ To develop locally: 5. Run the tests with: - ``` + ```bash API_KEY="" make test ``` diff --git a/LICENSE b/LICENSE index 10e9721..dfcb79a 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2022 Spice AI, Inc. + Copyright 2022-2024 Spice AI, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/spicepy/_client.py b/spicepy/_client.py index 8984c81..48b9636 100644 --- a/spicepy/_client.py +++ b/spicepy/_client.py @@ -6,7 +6,6 @@ import certifi from pyarrow._flight import FlightCallOptions, FlightClient, Ticket # pylint: disable=E0611 -from .prices import PriceCollection from ._http import HttpRequests from .error import SpiceAIError from . import config @@ -150,10 +149,6 @@ def query(self, query: str, **kwargs) -> flight.FlightStreamReader: def fire_query(self, query: str, **kwargs) -> flight.FlightStreamReader: return self._firecache.query(query, **kwargs) - @property - def prices(self) -> PriceCollection: - return PriceCollection(client=self.http) - class _ArrowFlightCallThread(threading.Thread): def __init__( diff --git a/spicepy/_http.py b/spicepy/_http.py index 33247f4..2f28788 100644 --- a/spicepy/_http.py +++ b/spicepy/_http.py @@ -66,7 +66,7 @@ def _create_session(self, headers: Dict[str, str]) -> Session: max_retries=Retry( total=5, backoff_factor=2, - # Only retry 500s on GET so we don't unintionally mutute data + # Only retry 500s on GET so we don't unintentionally mutate data allowed_methods=["GET"], # https://support.cloudflare.com/hc/en-us/articles/115003011431-Troubleshooting-Cloudflare-5XX-errors status_forcelist=[ diff --git a/spicepy/prices.py b/spicepy/prices.py deleted file mode 100644 index 99a8653..0000000 --- a/spicepy/prices.py +++ /dev/null @@ -1,88 +0,0 @@ -from dataclasses import dataclass, field -from datetime import datetime, timedelta, timezone -from typing import Any, List, Dict, Optional, Union - -from ._http import HttpRequests - - -@dataclass -class Quote: - prices: Dict[str, float] = field(default_factory=dict) - - min_price: Optional[float] = field(default=None, metadata={"json": "minPrice"}) - max_price: Optional[float] = field(default=None, metadata={"json": "maxPrice"}) - mean_price: Optional[float] = field(default=None, metadata={"json": "avePrice"}) - - @classmethod - def from_dict(cls, _dict: Dict[str, Any]) -> "Quote": - _dict["min_price"] = ( - float(_dict.get("minPrice")) if _dict.get("minPrice") is not None else None - ) - _dict["max_price"] = ( - float(_dict.get("maxPrice")) if _dict.get("maxPrice") is not None else None - ) - _dict["mean_price"] = ( - float(_dict.get("meanPrice")) if _dict.get("meanPrice") is not None else None - ) - - _dict["prices"] = {key: float(value) for key, value in _dict.get("prices", {}).items()} - - return Quote(**{k: v for k, v in _dict.items() if k in Quote.__annotations__}) # pylint: disable=E1101 - - -@dataclass -class Price: - timestamp: Optional[datetime] = None - price: float = 0.0 - high: float = 0.0 - low: float = 0.0 - open: float = 0.0 - close: float = 0.0 - - def __post_init__(self): - if self.timestamp: - self.timestamp = datetime.fromisoformat( - self.timestamp.replace("Z", "") - ).replace(tzinfo=timezone.utc) - - -class PriceCollection: - def __init__(self, client: HttpRequests): - self.client = client - - def get_latest(self, pairs: List[str]) -> Dict[str, Quote]: - if not pairs: - return {} - - if isinstance(pairs, str): - pairs = [pairs] - - resp = self.client.send_request( - "GET", "/v1/prices", param={"pairs": pairs} - ) - return {pair: Quote.from_dict(q) for (pair, q) in resp.items()} - - def get( - self, - pairs: Union[str, List[str]], - start: Optional[datetime] = None, - end: Optional[datetime] = None, - granularity: Optional[timedelta] = None, - ) -> Dict[str, List[Price]]: - if not pairs: - return {} - - if isinstance(pairs, str): - pairs = [pairs] - - resp = self.client.send_request( - "GET", - "/v1/prices/historical", - param={ - "pairs": pairs, - "start": start, - "end": end, - "granularity": granularity, - }, - ) - return {pair: [Price(**p) for p in prices] for (pair, prices) in resp.items()}