Skip to content

Commit

Permalink
Next pp add future endpoint (#133)
Browse files Browse the repository at this point in the history
* its working boyz

* remove log

* fix lint
  • Loading branch information
azurwastaken authored Jul 4, 2024
1 parent d1a75e1 commit 8a62b38
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
17 changes: 12 additions & 5 deletions price-pusher/price_pusher/core/request_handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ async def fetch_latest_entry(self, data_type: DataTypes, pair: Pair) -> Optional
Fetch last entry for the asset from the API.
TODO: Currently only works for spot assets.
"""
entry_result: EntryResult = await self.client.get_entry(
pair=pair.__repr__(),
interval=Interval.ONE_MINUTE,
aggregation=AggregationMode.MEDIAN,
)
if data_type is DataTypes.FUTURE:
entry_result: EntryResult = await self.client.get_future_entry(
pair=pair.__repr__(),
interval=Interval.ONE_MINUTE,
aggregation=AggregationMode.MEDIAN,
)
else:
entry_result: EntryResult = await self.client.get_entry(
pair=pair.__repr__(),
interval=Interval.ONE_MINUTE,
aggregation=AggregationMode.MEDIAN,
)
entry = SpotEntry(
pair_id=entry_result.pair_id,
price=int(entry_result.data, 16),
Expand Down
12 changes: 9 additions & 3 deletions price-pusher/price_pusher/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,23 @@ def _flush_entries_for_assets(self, pairs_per_type: Dict[DataTypes, List[Pair]])

for data_type, pairs in pairs_per_type.items():
for pair in pairs:
if data_type not in self.latest_prices[f"{pair}"]:
pair_name = f"{pair}"
if (
pair_name not in self.latest_prices
or data_type not in self.latest_prices[pair_name]
):
logger.warning(f"ORCHESTRATOR : {pair_name} not found, continuing ...")
continue
entries_to_push.extend(list(self.latest_prices[f"{pair}"][data_type].values()))
del self.latest_prices[f"{pair}"][data_type]
entries_to_push.extend(list(self.latest_prices[pair_name][data_type].values()))
del self.latest_prices[pair_name][data_type]

return entries_to_push

def callback_update_prices(self, entries: List[Entry]) -> None:
"""
Function called by the poller whenever new prices are retrieved.
"""

for entry in entries:
pair_id = entry.get_pair_id()
source = entry.get_source()
Expand Down

0 comments on commit 8a62b38

Please sign in to comment.