From 04e99a9e67a96db16297254156f98829dd25bd68 Mon Sep 17 00:00:00 2001 From: Fouad Date: Sat, 16 Mar 2024 16:44:55 +0100 Subject: [PATCH] Updated to match price collector api! --- src/.example.env | 3 ++- src/price.py | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/.example.env b/src/.example.env index 558914c..2d75a1d 100644 --- a/src/.example.env +++ b/src/.example.env @@ -1,3 +1,4 @@ JWT_SECRET="JWT_SECRET here" DB_URI="Mongo Database here" -REDIS_URI="Redis Uri here" \ No newline at end of file +REDIS_URI="Redis Uri here" +PRICE_COLLECTOR_URI="localhost" \ No newline at end of file diff --git a/src/price.py b/src/price.py index 13f7e29..0622a2b 100644 --- a/src/price.py +++ b/src/price.py @@ -3,9 +3,11 @@ from redis import from_url from dotenv import load_dotenv from flask import has_request_context, request +from requests import get load_dotenv() redis = from_url(os.environ['REDIS_URI']) +price_collector = os.environ['PRICE_COLLECTOR_URI'] point_count = 720 default_interval = 240 @@ -37,7 +39,7 @@ def get_using_pair() -> str: return pair return default_pair -def get_prices(interval, pair): +def get_prices(interval: int, pair: str): if not interval or not pair: raise Exception('No Interval/Pair') @@ -47,9 +49,10 @@ def get_prices(interval, pair): if not is_supported_pair(pair): raise Exception(f'Unsupported Pair: {pair}') - slicing_ratio = int(interval / price_collector_interval) + print(f'http://{price_collector}/prices/{pair.lower()}?interval={interval}') + price_api = get(f'http://{price_collector}/prices/{pair.lower()}?interval={interval}') + data = price_api.json() - prices = redis.lrange(f'{pair}:prices', 0, -1)[::slicing_ratio] - timestamps = redis.lrange(f'{pair}:timestamps', 0, -1)[::slicing_ratio] + prices, timestamps = zip(*(item.values() for item in data)) return np.array(prices).astype(float), np.array(timestamps).astype(int)