Skip to content

Commit

Permalink
Merge branch 'master' into v7.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
enarjord committed Nov 6, 2024
2 parents ec2a44b + 0d06704 commit 53eb607
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions src/passivbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1462,17 +1462,18 @@ def calc_unstucking_close(self, ideal_orders):
)
if ideal_closes and close_price >= ideal_closes[0][1]:
continue
min_entry_qty = calc_min_entry_qty(
close_price,
False,
self.c_mults[symbol],
self.qty_steps[symbol],
self.min_qtys[symbol],
self.min_costs[symbol],
)
close_qty = -min(
self.positions[symbol][pside]["size"],
max(
calc_min_entry_qty(
close_price,
False,
self.c_mults[symbol],
self.qty_steps[symbol],
self.min_qtys[symbol],
self.min_costs[symbol],
),
min_entry_qty,
pbr.round_dn(
pbr.cost_to_qty(
self.balance
Expand All @@ -1494,7 +1495,16 @@ def calc_unstucking_close(self, ideal_orders):
)
pnl_if_closed_abs = abs(pnl_if_closed)
if pnl_if_closed < 0.0 and pnl_if_closed_abs > unstuck_allowances[pside]:
close_qty *= unstuck_allowances[pside] / pnl_if_closed_abs
close_qty = -min(
self.positions[symbol][pside]["size"],
max(
min_entry_qty,
pbr.round_dn(
abs(close_qty) * (unstuck_allowances[pside] / pnl_if_closed_abs),
self.qty_steps[symbol],
),
),
)
return symbol, (close_qty, close_price, "unstuck_close_long")
elif pside == "short":
close_price = min(
Expand All @@ -1512,17 +1522,18 @@ def calc_unstucking_close(self, ideal_orders):
)
if ideal_closes and close_price <= ideal_closes[0][1]:
continue
min_entry_qty = calc_min_entry_qty(
close_price,
False,
self.c_mults[symbol],
self.qty_steps[symbol],
self.min_qtys[symbol],
self.min_costs[symbol],
)
close_qty = min(
abs(self.positions[symbol][pside]["size"]),
max(
calc_min_entry_qty(
close_price,
False,
self.c_mults[symbol],
self.qty_steps[symbol],
self.min_qtys[symbol],
self.min_costs[symbol],
),
min_entry_qty,
pbr.round_dn(
pbr.cost_to_qty(
self.balance
Expand All @@ -1544,7 +1555,16 @@ def calc_unstucking_close(self, ideal_orders):
)
pnl_if_closed_abs = abs(pnl_if_closed)
if pnl_if_closed < 0.0 and pnl_if_closed_abs > unstuck_allowances[pside]:
close_qty *= unstuck_allowances[pside] / pnl_if_closed_abs
close_qty = min(
abs(self.positions[symbol][pside]["size"]),
max(
min_entry_qty,
pbr.round_dn(
close_qty * (unstuck_allowances[pside] / pnl_if_closed_abs),
self.qty_steps[symbol],
),
),
)
return symbol, (close_qty, close_price, "unstuck_close_short")
return "", (0.0, 0.0, "")

Expand Down

0 comments on commit 53eb607

Please sign in to comment.