fix on quantities
This commit is contained in:
13
bot.py
13
bot.py
@@ -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
|
||||||
|
|
||||||
order_id = client.market_sell(
|
try:
|
||||||
position.pair, position.quantity, paper=config.paper_trading
|
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
|
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(
|
||||||
|
|||||||
Reference in New Issue
Block a user