Files
Mark Aron Szulyovszky 8dd2d88740 chore(Linter): reformatted code with black (#211)
* chore(Linter): reformatted code with black

* Create black.yaml
2022-02-17 19:22:17 +01:00

46 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]