diff --git a/api/account/assets.py b/api/account/assets.py index 0d4432253..8514ebb87 100644 --- a/api/account/assets.py +++ b/api/account/assets.py @@ -337,28 +337,27 @@ async def get_balance_series(self, end_date, start_date): ) return resp - def clean_balance_assets(self): + async def clean_balance_assets(self): """ Check if there are many small assets (0.000.. BTC) if there are more than 5 (number of bots) transfer to BNB """ - balance = self.get_raw_balance() - data = json.loads(balance.body)["data"] + data = self.signed_request(url=self.account_url) assets = [] - for item in data: - if item["asset"] not in ["USDT", "NFT", "BNB"]: - assets.append(item["asset"]) + for item in data["balances"]: + if item["asset"] not in ["USDT", "NFT", "BNB"] and float(item["free"]) > 0: + assets.append(item["free"]) if len(assets) > 5: self.transfer_dust(assets) resp = json_response_message("Sucessfully cleaned balance.") else: - resp = json_response_error("Amount of assets in balance is low. Transfer not performed.") + resp = json_response_error("Amount of assets in balance is low. Transfer not needed.") return resp - def disable_isolated_accounts(self): + async def disable_isolated_accounts(self): """ Check and disable isolated accounts """ @@ -366,5 +365,9 @@ def disable_isolated_accounts(self): for item in info["assets"]: if float(item["liquidatePrice"]) == 0: self.disable_isolated_margin_account(item["symbol"]) - resp = json_response_message("Sucessfully finished disabling isolated margin accounts.") + msg = "Sucessfully finished disabling isolated margin accounts." + else: + msg = "Disabling isolated margin account not required yet." + + resp = json_response_message(msg) return resp \ No newline at end of file diff --git a/api/market_updates.py b/api/market_updates.py index 47a9f1fa0..1a363d123 100644 --- a/api/market_updates.py +++ b/api/market_updates.py @@ -4,7 +4,7 @@ import time from apscheduler.schedulers.background import BackgroundScheduler -from api.account.routes import disable_isolated +from account.routes import disable_isolated from streaming.streaming_controller import StreamingController from account.assets import Assets from websocket import ( @@ -26,7 +26,7 @@ assets = Assets() scheduler.add_job( - func=assets.store_balance(), + func=assets.store_balance, trigger="cron", timezone="Europe/London", hour=1, @@ -35,7 +35,7 @@ ) scheduler.add_job( - func=assets.disable_isolated_accounts(), + func=assets.disable_isolated_accounts, trigger="cron", timezone="Europe/London", hour=2, @@ -43,6 +43,15 @@ id="disable_isolated_accounts", ) + scheduler.add_job( + func=assets.clean_balance_assets, + trigger="cron", + timezone="Europe/London", + hour=3, + minute=0, + id="clean_balance_assets", + ) + scheduler.start() atexit.register(lambda: scheduler.shutdown(wait=False))