diff --git a/bot.py b/bot.py index 031a995..a31d558 100644 --- a/bot.py +++ b/bot.py @@ -18,6 +18,7 @@ from __future__ import annotations import argparse import logging +import math import os import sys from datetime import datetime, timezone @@ -106,9 +107,13 @@ def run_cycle(config: Config) -> bool: if signal is None: continue - order_id = client.market_sell( - position.pair, position.quantity, paper=config.paper_trading - ) + try: + order_id = client.market_sell( + position.pair, position.quantity, paper=config.paper_trading + ) + except KrakenError as exc: + log.error("Sell failed for %s: %s — will retry next run", position.pair, exc) + continue pnl_usd = (current_price - position.entry_price) * position.quantity log.info( "CLOSED %-10s reason=%-14s entry=$%.6f exit=$%.6f " @@ -173,7 +178,7 @@ def run_cycle(config: Config) -> bool: ) for opp in to_buy: - quantity = round(alloc_per_asset / opp.last_price, opp.lot_decimals) + quantity = math.floor(alloc_per_asset / opp.last_price * 10 ** opp.lot_decimals) / 10 ** opp.lot_decimals if opp.order_min > 0 and quantity < opp.order_min: log.warning(