diff --git a/README.md b/README.md index bc36ea1..825873c 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,15 @@ pip install async_rithmic ๐Ÿ‘‰ [See the official documentation for usage examples](https://async-rithmic.readthedocs.io/en/latest/) +## ๐Ÿง  Using it in Production + +This library handles connectivity and streaming with Rithmic, but it does not solve higher-level concerns such as failure handling or ensuring correctness under load. + +For a detailed discussion of how to build fault-tolerant async trading systems in practice: + +๐Ÿ‘‰ [Designing Fault-Tolerant Async Trading Services in Python](https://quant.engineering/designing-fault-tolerant-async-trading-services-python.html) + + ## ๐Ÿงช Testing To execute the tests, use the following command: `make tests` diff --git a/async_rithmic/client.py b/async_rithmic/client.py index 91de918..5a6a3ba 100644 --- a/async_rithmic/client.py +++ b/async_rithmic/client.py @@ -116,6 +116,7 @@ async def connect(self, **kwargs): SysInfraType.TICKER_PLANT, SysInfraType.PNL_PLANT ]) + plant_connect_delay = kwargs.get("plant_connect_delay", 0.1) try: for plant in self.plants.values(): @@ -126,7 +127,7 @@ async def connect(self, **kwargs): await plant._start_background_tasks() await plant._login() - await asyncio.sleep(0.1) + await asyncio.sleep(plant_connect_delay) except: logger.exception("Failed to connect") diff --git a/async_rithmic/helpers/connectivity.py b/async_rithmic/helpers/connectivity.py index db8d70e..7ade7a7 100644 --- a/async_rithmic/helpers/connectivity.py +++ b/async_rithmic/helpers/connectivity.py @@ -43,6 +43,10 @@ async def _try_to_reconnect(plant, attempt): settings = plant.client.reconnection_settings while True: + wait_time = plant.client.reconnection_settings.get_delay(attempt) + plant.logger.info(f"Waiting {wait_time} seconds before the next reconnection attempt ...") + await asyncio.sleep(wait_time) + plant.logger.info(f"Reconnection attempt #{attempt}") if settings.max_retries is not None and attempt > settings.max_retries: @@ -64,8 +68,3 @@ async def _try_to_reconnect(plant, attempt): attempt += 1 - wait_time = plant.client.reconnection_settings.get_delay(attempt) - plant.logger.info(f"Waiting {wait_time} seconds before the next reconnection attempt ...") - await asyncio.sleep(wait_time) - - return False