1
0

Quantize to avoid issues with kucoin
Some checks failed
Python Ruff Code Quality / ruff (push) Failing after 23s
Run Python tests (through Pytest) / Test (push) Failing after 29s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 27s

This commit is contained in:
Jon Michael Aanes 2024-12-02 17:59:10 +01:00
parent 59cb798f7d
commit 0f4397d9e5
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -129,6 +129,11 @@ from ._version import __version__
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
################################################################################
# Constants
QUANTIZE_DECIMALS = Decimal('1.00')
################################################################################ ################################################################################
# Main code # # 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 return rang[0] + (rang[1] - rang[0]) * multiplier
def run_auto_sell(config: AutoSellConfig) -> AutoSellRunResults: def run_auto_sell(config: AutoSellConfig) -> AutoSellRunResults:
"""Executes the sell-off. """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( input_amount_available = config.seller.get_depo().get_amount_of_asset(
config.input_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: if input_amount_available > 0:
amount_to_sell = sample_from_range(rng, config.input_amount_range) amount_to_sell = sample_from_range(rng, config.input_amount_range)
amount_to_sell = min(input_amount_available, amount_to_sell) 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( order_details = config.seller.place_market_order(
fin_defs.AssetAmount(config.input_asset, amount_to_sell), fin_defs.AssetAmount(config.input_asset, amount_to_sell),