1
0

Quantize correctly
All checks were successful
Test Python / Test (push) Successful in 26s

This commit is contained in:
Jon Michael Aanes 2024-09-02 20:26:17 +02:00
parent f82276eac7
commit 97369e0b74
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
2 changed files with 7 additions and 4 deletions

View File

@ -119,7 +119,7 @@ import datetime
import logging
import random
from collections.abc import Callable
from decimal import Decimal
from decimal import Decimal, ROUND_DOWN
from typing import Any
import fin_defs
@ -192,6 +192,9 @@ def sample_from_range(rng: random.Random, rang: tuple[Any, Any]) -> Any:
return rang[0] + (rang[1] - rang[0]) * multiplier
ROUND_TO_WHOLE = Decimal('1')
def run_auto_sell(config: AutoSellConfig) -> AutoSellRunResults:
"""Executes the sell-off.
@ -214,7 +217,7 @@ def run_auto_sell(config: AutoSellConfig) -> AutoSellRunResults:
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)
amount_to_sell = int(amount_to_sell + Decimal('0.5'))
amount_to_sell = amount_to_sell.quantize(ROUND_TO_WHOLE, rounding=ROUND_DOWN)
logger.info('Attempting to sell %s %s', amount_to_sell, config.input_asset)
order_details = config.seller.place_market_order(

View File

@ -26,7 +26,7 @@ class SellerMock(fin_depo.data.DepoFetcher):
input_asset: fin_defs.Asset,
input_amount: Decimal,
output_asset: fin_defs.Asset,
) -> fin_depo.data.Depo:
) -> fin_depo.data.TradeOrderDetails:
assert input_amount <= self.amount_left, 'Attempt to sell too much'
self.amount_left -= input_amount
@ -40,7 +40,7 @@ class SellerMock(fin_depo.data.DepoFetcher):
output_amount=input_amount,
fee_asset=input_asset,
fee_amount=Decimal(0),
order_id=10000000 - self.amount_left,
order_id=Decimal(10000000 - self.amount_left),
raw_order_details={'TEST': 1, 'DATA': 2},
)