Open-Trader/opentrader

Insufficient balance for sell orders due to fee deduction

Offen

#99 geöffnet am 15.01.2025

 (3 Kommentare) (2 Reaktionen) (1 zugewiesene Person)TypeScript (319 Forks)auto 404
bugexchangesgood first issuehelp wanted

Repository-Metriken

Stars
 (2.749 Sterne)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

Problem

When executing trades, the bot encounters an issue with insufficient balance for sell orders due to fee deductions. Specifically:

  1. The bot places a buy order for 1 BTC.
  2. After the exchange deducts a trading fee (e.g., 0.1%), the account ends up with slightly less than 1 BTC (e.g., 0.999 BTC).
  3. When the bot attempts to place a sell order for 1 BTC, the order is rejected due to insufficient funds.

Proposed solution

The bot should calculate the buy order amount in a way that ensures the target amount (e.g., 1 BTC) is available after fees are deducted.

Example

Let's take OKX as an example where the fee is taken in the base currency for buy orders. The fee rate is 0.1%.

  1. Target amount: 1 BTC
  2. Required buy amount (including fee): 𝐵 = 1 ÷ ( 1 − 0.001 ) = 1.001001 BTC
  3. Fee paid: 1.001001 × 0.001 = 0.001001 BTC
  4. Net BTC after fees: 1.001001 − 0.001001 = 1 BTC

Note: Some exchanges may have a complex fee structure, so in certain cases, we may need to cover slightly more than the expected fee.

Checklist

  • Update the bot's logic to calculate the correct buy amount to cover fees.
  • Research the trading fee rate for every exchange (supported exchanges)
  • Test the updated logic to confirm that the balance after buying matches the target amount.

Contributor Guide