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

Commit

Permalink
Updated to match price collector api!
Browse files Browse the repository at this point in the history
  • Loading branch information
fou3fou3 committed Mar 16, 2024
1 parent f688f54 commit 04e99a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/.example.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
JWT_SECRET="JWT_SECRET here"
DB_URI="Mongo Database here"
REDIS_URI="Redis Uri here"
REDIS_URI="Redis Uri here"
PRICE_COLLECTOR_URI="localhost"
11 changes: 7 additions & 4 deletions src/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')

Expand All @@ -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)

0 comments on commit 04e99a9

Please sign in to comment.