diff options
| -rw-r--r-- | python/api_quotes/__main__.py | 36 | ||||
| -rw-r--r-- | python/api_quotes/api.py | 4 |
2 files changed, 26 insertions, 14 deletions
diff --git a/python/api_quotes/__main__.py b/python/api_quotes/__main__.py index 26e97dc0..a0e066fe 100644 --- a/python/api_quotes/__main__.py +++ b/python/api_quotes/__main__.py @@ -1,4 +1,5 @@ import logging +from json.decoder import JSONDecodeError from .api import MarkitAPI from .quotes import MarkitQuoteKind @@ -7,21 +8,28 @@ logger = logging.getLogger(__name__) if __name__ == "__main__": for asset_class in ( - "CD", "ABS", + "CD", "TRS", ): - after = None + after = "1670330509000" while True: - if data := MarkitAPI.get_data(asset_class, after): - for row in data: - try: - quote = MarkitQuoteKind[asset_class].from_markit_line(row) - except ValueError as e: - logger.error(f"Couldn't pase {row['quoteid']}: {e}") - else: - quote.stage() - quote.commit() - after = f"{row['receiveddatetime']},{asset_class}-9480-{row['quoteid']}" - else: - break + try: + if data := MarkitAPI.get_data(asset_class, after): + for row in data: + try: + quote = MarkitQuoteKind[asset_class].from_markit_line(row) + except ValueError as e: + logger.error(f"Couldn't pase {row['quoteid']}: {e}") + else: + quote.stage() + quote.commit() + after = ( + f"{row['receiveddatetime']},{asset_class}-9480-{row['quoteid']}" + ) + else: + break + except JSONDecodeError: + print(f"Issue with {asset_class}: {after}") + except AttributeError: + MarkitAPI.update_api_key() diff --git a/python/api_quotes/api.py b/python/api_quotes/api.py index 133fe16b..b9e32226 100644 --- a/python/api_quotes/api.py +++ b/python/api_quotes/api.py @@ -43,3 +43,7 @@ class MarkitAPI: url = urljoin(cls.base_url, path) r = requests.get(url, params) return map(lowercase_keys, json.loads(r.text)) + + @classmethod + def update_api_key(cls): + cls.base_url, cls.api_key = load_api_key() |
