Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions CryptoPrice/common/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

@dataclass(frozen=True)
class Price:
value: float
high: float
low: float
open: float
close: float
asset: str
ref_asset: str
timestamp: int
Expand All @@ -16,7 +19,10 @@ class Price:

@dataclass(frozen=True)
class MetaPrice:
value: float
high: float
low: float
open: float
close: float
asset: str
ref_asset: str
prices: List[Union[Price, MetaPrice]]
Expand All @@ -41,7 +47,7 @@ def mean_from_meta_price(meta_prices: List[MetaPrice]) -> MetaPrice:
for meta_price in meta_prices:
if (asset, ref_asset) != (meta_price.asset, meta_price.ref_asset):
raise ValueError("asset and ref asset are inconsistent")
cum_value += meta_price.value
cum_value += meta_price.close
source.update(meta_price.source)
return MetaPrice(cum_value / len(meta_prices), asset, ref_asset, meta_prices, source=source)

Expand All @@ -66,9 +72,9 @@ def from_price_path(assets: List[str], price_path: List[Price]) -> MetaPrice:
for i, price in enumerate(price_path):
current_asset, next_asset = assets[i:i + 2]
if price.asset == next_asset:
cumulated_price /= price.value
cumulated_price /= price.close
else:
cumulated_price *= price.value
cumulated_price *= price.close
source.add(price.source)
return MetaPrice(cumulated_price, assets[0], assets[-1], price_path, source=source)

Expand Down
2 changes: 1 addition & 1 deletion CryptoPrice/retrievers/KlineRetriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _get_closest_price(self, asset: str, ref_asset: str, timestamp: int) -> Opti
closest_open_timestamp, self.closest_window)

if closest_kline is not None:
return Price(closest_kline.open, asset, ref_asset, closest_kline.open_timestamp, closest_kline.source)
return Price(closest_kline.high, closest_kline.low, closest_kline.open, closest_kline.close, asset, ref_asset, closest_kline.open_timestamp, closest_kline.source)

msg = f"no Kline found for {asset}, {ref_asset}, {self.kline_timeframe.name}, {timestamp}," \
f" w={self.closest_window}"
Expand Down