Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
include ?before from price api to replace ?from and ?to
Browse files Browse the repository at this point in the history
  • Loading branch information
CelestialCrafter committed Mar 17, 2024
1 parent 84668e5 commit ca6ae24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_using_pair() -> str:
return pair
return default_pair

def get_prices(interval: int, pair: str):
def get_prices(interval: int, pair: str, before: int = None):
if not interval or not pair:
raise Exception('No Interval/Pair')

Expand All @@ -49,7 +49,11 @@ def get_prices(interval: int, pair: str):
if not is_supported_pair(pair):
raise Exception(f'Unsupported Pair: {pair}')

price_api_response = get(f'{price_collector_uri}/prices/{pair.lower()}?interval={interval}')
if type(before) != 'int' and before:
raise Exception(f'Unsupported before')

price_api_response = get(
f'{price_collector_uri}/prices/{pair}?interval={interval}{f"&before={before}" if before else ""}')
data = price_api_response.json()

prices, timestamps = zip(*(item.values() for item in data))
Expand Down
3 changes: 2 additions & 1 deletion src/views/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ def plot(algorithm_name: str):
interval = get_using_interval()
pair = get_using_pair()
interactive = request.args.get('interactive', type=bool, default=False)
before = request.args.get('before', type=int, default=None)

if algorithm_name not in ['price', *get_algorithms()]:
return 'Unsupported Algorithm', 404

try:
prices, timestamps = get_prices(interval, pair)
prices, timestamps = get_prices(interval, pair, before)
timestamps = timestamps.astype('datetime64[s]')
except Exception as error:
return str(error)
Expand Down

0 comments on commit ca6ae24

Please sign in to comment.