Skip to content

Commit

Permalink
Disable exhaustive rebalancing attempts.
Browse files Browse the repository at this point in the history
  • Loading branch information
dowlandaiello committed Oct 14, 2024
1 parent 3ad374c commit 3ba9498
Showing 1 changed file with 57 additions and 54 deletions.
111 changes: 57 additions & 54 deletions src/strategies/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
*[
Expand Down

0 comments on commit 3ba9498

Please sign in to comment.