Fee buffer and error isolation

This commit is contained in:
2026-05-04 09:44:31 -04:00
parent 9285b303d0
commit 7dd0917d15
2 changed files with 11 additions and 5 deletions

15
bot.py
View File

@@ -160,11 +160,12 @@ def run_cycle(config: Config) -> bool:
return bool(closed) return bool(closed)
to_buy = opportunities[:num_to_buy] to_buy = opportunities[:num_to_buy]
# Split available balance equally across the chosen assets (always >= min_order_usd) # Deduct fee reserve before splitting so each order has room for Kraken's taker fee
alloc_per_asset = balance / num_to_buy fee_multiplier = 1 - (config.taker_fee_pct / 100)
alloc_per_asset = (balance * fee_multiplier) / num_to_buy
log.info( log.info(
"Buying %d asset(s) @ $%.2f each (total $%.2f)", "Buying %d asset(s) @ $%.2f each (total $%.2f, %.1f%% fee reserve applied)",
num_to_buy, alloc_per_asset, alloc_per_asset * num_to_buy, num_to_buy, alloc_per_asset, alloc_per_asset * num_to_buy, config.taker_fee_pct,
) )
for opp in to_buy: for opp in to_buy:
@@ -177,7 +178,11 @@ def run_cycle(config: Config) -> bool:
) )
continue continue
order_id = client.market_buy(opp.pair, quantity, paper=config.paper_trading) try:
order_id = client.market_buy(opp.pair, quantity, paper=config.paper_trading)
except KrakenError as exc:
log.error("Order failed for %s: %s — skipping", opp.pair, exc)
continue
portfolio.add(Position( portfolio.add(Position(
pair=opp.pair, pair=opp.pair,

View File

@@ -23,6 +23,7 @@ class Config:
# Portfolio limits # Portfolio limits
max_positions: int = 5 # Maximum concurrent holdings max_positions: int = 5 # Maximum concurrent holdings
min_order_usd: float = 15.0 # Kraken minimum is ~$10; keep a small buffer min_order_usd: float = 15.0 # Kraken minimum is ~$10; keep a small buffer
taker_fee_pct: float = 0.4 # Reserve this % per order for Kraken's taker fee (actual ~0.26%)
# ── Risk management ────────────────────────────────────────────────────── # ── Risk management ──────────────────────────────────────────────────────
# Trailing stop: sell if price drops this % below its peak since purchase. # Trailing stop: sell if price drops this % below its peak since purchase.