fix on quantities

This commit is contained in:
2026-05-04 16:03:13 -04:00
parent 61987482e1
commit f8addae6b7

7
bot.py
View File

@@ -18,6 +18,7 @@ from __future__ import annotations
import argparse import argparse
import logging import logging
import math
import os import os
import sys import sys
from datetime import datetime, timezone from datetime import datetime, timezone
@@ -106,9 +107,13 @@ def run_cycle(config: Config) -> bool:
if signal is None: if signal is None:
continue continue
try:
order_id = client.market_sell( order_id = client.market_sell(
position.pair, position.quantity, paper=config.paper_trading 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 pnl_usd = (current_price - position.entry_price) * position.quantity
log.info( log.info(
"CLOSED %-10s reason=%-14s entry=$%.6f exit=$%.6f " "CLOSED %-10s reason=%-14s entry=$%.6f exit=$%.6f "
@@ -173,7 +178,7 @@ def run_cycle(config: Config) -> bool:
) )
for opp in to_buy: 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: if opp.order_min > 0 and quantity < opp.order_min:
log.warning( log.warning(