Fee buffer and error isolation
This commit is contained in:
13
bot.py
13
bot.py
@@ -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
|
||||||
|
|
||||||
|
try:
|
||||||
order_id = client.market_buy(opp.pair, quantity, paper=config.paper_trading)
|
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,
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user