mirror of
https://github.com/webclinic017/drift.git
synced 2026-07-27 18:57:55 +00:00
44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
from .utils import fetch
|
|
|
|
|
|
def create_endpoints_dict(endpoints):
|
|
return {
|
|
endpoint['path']: {
|
|
'assets': {asset['symbol']: asset['tags'] for asset in endpoint['assets']},
|
|
'currencies': endpoint['currencies'],
|
|
'resolutions': endpoint['resolutions'],
|
|
'formats': endpoint['formats']
|
|
}
|
|
for endpoint in endpoints
|
|
}
|
|
|
|
|
|
"""
|
|
@pattern Singleton (GoF:127)
|
|
"""
|
|
|
|
|
|
class MetaEndpoints(type):
|
|
_instances = {}
|
|
|
|
def __call__(cls, *args, **kwargs):
|
|
if cls not in cls._instances:
|
|
instance = super().__call__(*args, **kwargs)
|
|
cls._instances[cls] = instance
|
|
return cls._instances[cls]
|
|
|
|
|
|
class Endpoints(metaclass=MetaEndpoints):
|
|
_endpoints = None
|
|
|
|
@property
|
|
def endpoints(self):
|
|
return self._endpoints
|
|
|
|
@endpoints.setter
|
|
def endpoints(self, api_key):
|
|
self._endpoints = create_endpoints_dict(fetch('/v2/metrics/endpoints', {'api_key': api_key}))
|
|
|
|
def query(self, path):
|
|
return self._endpoints[path]
|