Skip to content

Commit

Permalink
Merge pull request #28 from Pasta-fantasia/84-error-stop-loss-amount-…
Browse files Browse the repository at this point in the history
…is-higher-than-balance-balance

84 error stop loss amount is higher than balance balance
  • Loading branch information
fransimo authored Dec 13, 2024
2 parents d99b145 + 2158dd4 commit 5987896
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.1.10
- fix: [ERROR] Stop loss amount is higher than balance. Balance...

# 0.1.9
- fix: [ERROR] Error creating stop loss: binance Stop price would trigger immediately

Expand Down
20 changes: 20 additions & 0 deletions elena_basics/strategies/common_sl_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ def manage_trailing_stop_losses(self, data: pd.DataFrame, estimated_close_price:
base_symbol = self.pair.base
base_free = balance.currencies[base_symbol].free

# in some cases balance is not available after some time
retry = 0
retry_limit = 5

while total_amount_canceled_orders > base_free and retry < retry_limit:
self._logger.warning(f"Orders for {total_amount_canceled_orders} were cancelled but balance is {base_free}. Retrying...")
time.sleep(5)
balance = self.get_balance()
if not balance:
self._logger.error("Cannot get balance")
return

base_symbol = self.pair.base
base_free = balance.currencies[base_symbol].free
retry = retry + 1

if retry >= retry_limit:
self._logger.error(f"Orders for {total_amount_canceled_orders} were cancelled but balance is {base_free}, after retrying {retry_limit} times.")
return # this return will cause to reprocess the bot in the next cycle but leaves any amount without stop loss

max_sell = min(grouped_amount_canceled_orders_and_new_trades, base_free)
if max_sell < grouped_amount_canceled_orders_and_new_trades:
sale_diff = grouped_amount_canceled_orders_and_new_trades - max_sell
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = elena_basics
version = 0.1.9
version = 0.1.10
author = "L Software Foundation"
author_email = "[email protected], [email protected]"
description = Sample project to link L + CCTX + Backtesting.py
Expand Down

0 comments on commit 5987896

Please sign in to comment.