From 7dd0917d153c3915fbd45624a6cbc3b41f7149c8 Mon Sep 17 00:00:00 2001 From: jerick Date: Mon, 4 May 2026 09:44:31 -0400 Subject: [PATCH] Fee buffer and error isolation --- bot.py | 15 ++++++++++----- config.py | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index f0557db..3822cf8 100644 --- a/bot.py +++ b/bot.py @@ -160,11 +160,12 @@ def run_cycle(config: Config) -> bool: return bool(closed) to_buy = opportunities[:num_to_buy] - # Split available balance equally across the chosen assets (always >= min_order_usd) - alloc_per_asset = balance / num_to_buy + # Deduct fee reserve before splitting so each order has room for Kraken's taker fee + fee_multiplier = 1 - (config.taker_fee_pct / 100) + alloc_per_asset = (balance * fee_multiplier) / num_to_buy log.info( - "Buying %d asset(s) @ $%.2f each (total $%.2f)", - num_to_buy, alloc_per_asset, alloc_per_asset * num_to_buy, + "Buying %d asset(s) @ $%.2f each (total $%.2f, %.1f%% fee reserve applied)", + num_to_buy, alloc_per_asset, alloc_per_asset * num_to_buy, config.taker_fee_pct, ) for opp in to_buy: @@ -177,7 +178,11 @@ def run_cycle(config: Config) -> bool: ) 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( pair=opp.pair, diff --git a/config.py b/config.py index 548c23b..11cfa6e 100644 --- a/config.py +++ b/config.py @@ -23,6 +23,7 @@ class Config: # Portfolio limits max_positions: int = 5 # Maximum concurrent holdings 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 ────────────────────────────────────────────────────── # Trailing stop: sell if price drops this % below its peak since purchase.