diff --git a/src/strategies/util.py b/src/strategies/util.py index 179703a0..2037128f 100644 --- a/src/strategies/util.py +++ b/src/strategies/util.py @@ -588,69 +588,72 @@ async def eval_sell_denom(denom: str, sell_denom: str, balance: int) -> None: logger.info("Rebalancing %d %s", balance, denom) - async for route_ent, route in listen_routes_with_depth_dfs( - ctx.cli_args["hops"], - denom, - sell_denom, - set(), - pools, - auctions, - ctx, - ): - route_ent.logs_enabled = ctx.cli_args["log_rebalancing"] - - # For logging - _, execution_plan = await quantities_for_route_profit( - balance, route, route_ent, ctx, seek_profit=False + route_ent, route = await anext( + listen_routes_with_depth_dfs( + ctx.cli_args["hops"], + denom, + sell_denom, + set(), + pools, + auctions, + ctx, ) + ) - # The execution plan was aborted - if len(execution_plan) <= len(route): - ctx.log_route( - route_ent, - "info", - "Insufficient execution planning for rebalancing for %s; skipping", - [denom], - ) + route_ent.logs_enabled = ctx.cli_args["log_rebalancing"] - continue + # For logging + _, execution_plan = await quantities_for_route_profit( + balance, route, route_ent, ctx, seek_profit=False + ) - # Check that the execution plan results in a liquidatable quantity - if execution_plan[-1] < ctx.cli_args["rebalance_threshold"]: - ctx.log_route( - route_ent, - "info", - "Not enough funds for rebalancing %s; trying a different execution plan", - [denom], - ) + # The execution plan was aborted + if len(execution_plan) <= len(route): + ctx.log_route( + route_ent, + "info", + "Insufficient execution planning for rebalancing for %s; skipping", + [denom], + ) - continue + continue + # Check that the execution plan results in a liquidatable quantity + if execution_plan[-1] < ctx.cli_args["rebalance_threshold"]: ctx.log_route( - route_ent, "info", "Executing rebalancing plan for %s", [denom] + route_ent, + "info", + "Not enough funds for rebalancing %s; trying a different execution plan", + [denom], ) - # Execute the plan - route_ent.quantities = execution_plan - ctx.update_route(route_ent) - - try: - await exec_arb(route_ent, 0, execution_plan, route, ctx) - - break - except Exception: - ctx.log_route( - route_ent, - "error", - "Arb failed - rebalancing of %s failed: %s", - [ - denom, - traceback.format_exc().replace( - "\n", - f"\n{route_ent.uid}- Arb failed - failed to rebalance funds: ", - ), - ], - ) + continue + + ctx.log_route( + route_ent, "info", "Executing rebalancing plan for %s", [denom] + ) + + # Execute the plan + route_ent.quantities = execution_plan + ctx.update_route(route_ent) + + try: + await exec_arb(route_ent, 0, execution_plan, route, ctx) + + break + except Exception: + ctx.log_route( + route_ent, + "error", + "Arb failed - rebalancing of %s failed: %s", + [ + denom, + traceback.format_exc().replace( + "\n", + f"\n{route_ent.uid}- Arb failed - failed to rebalance funds: ", + ), + ], + ) await asyncio.gather( *[