diff options
Diffstat (limited to 'python/api_quotes')
| -rw-r--r-- | python/api_quotes/__main__.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/python/api_quotes/__main__.py b/python/api_quotes/__main__.py index a0e066fe..31fa8ba8 100644 --- a/python/api_quotes/__main__.py +++ b/python/api_quotes/__main__.py @@ -1,5 +1,7 @@ import logging +import argparse from json.decoder import JSONDecodeError +import datetime from .api import MarkitAPI from .quotes import MarkitQuoteKind @@ -7,12 +9,23 @@ from .quotes import MarkitQuoteKind logger = logging.getLogger(__name__) if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "--start_from", + type=datetime.date.fromisoformat, + default=None, + nargs="?", + ) + args = parser.parse_args() for asset_class in ( "ABS", "CD", "TRS", ): - after = "1670330509000" + # We must add one day to include the day we start from + after = ( + int((args.start_from + datetime.timedelta(days=1)).strftime("%s")) * 1000 + ) while True: try: if data := MarkitAPI.get_data(asset_class, after): @@ -20,16 +33,18 @@ if __name__ == "__main__": try: quote = MarkitQuoteKind[asset_class].from_markit_line(row) except ValueError as e: - logger.error(f"Couldn't pase {row['quoteid']}: {e}") + logger.error(f"Couldn't parse {row['quoteid']}: {e}") else: quote.stage() quote.commit() + # The after is specific so that we can avoid skipping any quotes + # We would also get stuck sometimes without the quoteid being specified after = ( f"{row['receiveddatetime']},{asset_class}-9480-{row['quoteid']}" ) else: break except JSONDecodeError: - print(f"Issue with {asset_class}: {after}") + logger.error(f"Issue with {asset_class}: {after}") except AttributeError: MarkitAPI.update_api_key() |
