From 0a79714f2e5590f6872abb8396020b58b504df2d Mon Sep 17 00:00:00 2001 From: Carlos Wu Fei Date: Tue, 3 Oct 2023 02:36:14 +0100 Subject: [PATCH] Fix scheduler --- api/deals/margin.py | 3 +-- api/market_updates.py | 22 ++++++++++++---------- web/src/pages/dashboard/reducer.js | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/api/deals/margin.py b/api/deals/margin.py index 81f74b200..ff8632c53 100644 --- a/api/deals/margin.py +++ b/api/deals/margin.py @@ -311,14 +311,13 @@ def retry_repayment(self, query_loan, buy_back_fiat): self.save_bot_streaming() self.terminate_margin_short(buy_back_fiat) except Exception as error: - print(error) try: self.transfer_spot_to_isolated_margin( asset=self.active_bot.balance_to_use, symbol=self.active_bot.pair, amount=total_base_qty, ) - self.retry_repayment(query_loan, buy_back_fiat) + # self.retry_repayment(query_loan, buy_back_fiat) except Exception as error: print(error) self._append_errors( diff --git a/api/market_updates.py b/api/market_updates.py index 1a363d123..be8448cc1 100644 --- a/api/market_updates.py +++ b/api/market_updates.py @@ -3,8 +3,7 @@ import logging import time -from apscheduler.schedulers.background import BackgroundScheduler -from account.routes import disable_isolated +from apscheduler.schedulers.background import BlockingScheduler from streaming.streaming_controller import StreamingController from account.assets import Assets from websocket import ( @@ -22,7 +21,8 @@ ) if os.getenv("ENV") != "ci": - scheduler = BackgroundScheduler() + + scheduler = BlockingScheduler() assets = Assets() scheduler.add_job( @@ -30,16 +30,16 @@ trigger="cron", timezone="Europe/London", hour=1, - minute=0, + minute=1, id="store_balance", ) - + scheduler.add_job( func=assets.disable_isolated_accounts, trigger="cron", timezone="Europe/London", hour=2, - minute=0, + minute=1, id="disable_isolated_accounts", ) @@ -48,16 +48,14 @@ trigger="cron", timezone="Europe/London", hour=3, - minute=0, + minute=1, id="clean_balance_assets", ) - scheduler.start() - atexit.register(lambda: scheduler.shutdown(wait=False)) - try: mu = StreamingController() mu.get_klines() + scheduler.start() except WebSocketException as e: if isinstance(e, WebSocketConnectionClosedException): @@ -66,8 +64,12 @@ mu.get_klines() else: logging.error(f"Websocket exception: {e}") + + atexit.register(lambda: scheduler.shutdown(wait=False)) except Exception as error: logging.error(f"Streaming controller error: {error}") mu = StreamingController() mu.get_klines() + + atexit.register(lambda: scheduler.shutdown(wait=False)) diff --git a/web/src/pages/dashboard/reducer.js b/web/src/pages/dashboard/reducer.js index 94789a2da..e8653301e 100644 --- a/web/src/pages/dashboard/reducer.js +++ b/web/src/pages/dashboard/reducer.js @@ -66,7 +66,7 @@ const btcBenchmarkReducer = produce((draft, action) => { } }); // Match dates with diff series - action.data.dates.shift() + action.data.dates.pop() draft.dates = action.data.dates; draft.data = action.data }