Skip to content

Commit

Permalink
Fix scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Wu Fei authored and Carlos Wu Fei committed Oct 7, 2023
1 parent e22858e commit 0a79714
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
3 changes: 1 addition & 2 deletions api/deals/margin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 12 additions & 10 deletions api/market_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -22,24 +21,25 @@
)

if os.getenv("ENV") != "ci":
scheduler = BackgroundScheduler()

scheduler = BlockingScheduler()
assets = Assets()

scheduler.add_job(
func=assets.store_balance,
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",
)

Expand All @@ -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):
Expand All @@ -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))
2 changes: 1 addition & 1 deletion web/src/pages/dashboard/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0a79714

Please sign in to comment.