From 0f4397d9e541b7ee5721a67fddbebac71b19c819 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Mon, 2 Dec 2024 17:59:10 +0100 Subject: [PATCH] Quantize to avoid issues with kucoin --- crypto_seller/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crypto_seller/__init__.py b/crypto_seller/__init__.py index 4468006..0b5b77a 100644 --- a/crypto_seller/__init__.py +++ b/crypto_seller/__init__.py @@ -129,6 +129,11 @@ from ._version import __version__ logger = logging.getLogger(__name__) +################################################################################ +# Constants + +QUANTIZE_DECIMALS = Decimal('1.00') + ################################################################################ # Main code # @@ -192,6 +197,7 @@ def sample_from_range(rng: random.Random, rang: tuple[Any, Any]) -> Any: return rang[0] + (rang[1] - rang[0]) * multiplier + def run_auto_sell(config: AutoSellConfig) -> AutoSellRunResults: """Executes the sell-off. @@ -209,12 +215,13 @@ def run_auto_sell(config: AutoSellConfig) -> AutoSellRunResults: input_amount_available = config.seller.get_depo().get_amount_of_asset( config.input_asset, ) - logger.info('Currently own %s %s', input_amount_available, config.input_asset) + logger.info('Currently own %s %s', input_amount_available, config.input_asset.raw_short_name()) if input_amount_available > 0: amount_to_sell = sample_from_range(rng, config.input_amount_range) amount_to_sell = min(input_amount_available, amount_to_sell) - logger.info('Attempting to sell %s %s', amount_to_sell, config.input_asset) + amount_to_sell = amount_to_sell.quantize(QUANTIZE_DECIMALS) + logger.info('Selling %s %s', amount_to_sell, config.input_asset.raw_short_name()) order_details = config.seller.place_market_order( fin_defs.AssetAmount(config.input_asset, amount_to_sell),