This commit is contained in:
parent
f82276eac7
commit
97369e0b74
|
@ -119,7 +119,7 @@ import datetime
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from decimal import Decimal
|
from decimal import Decimal, ROUND_DOWN
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import fin_defs
|
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
|
return rang[0] + (rang[1] - rang[0]) * multiplier
|
||||||
|
|
||||||
|
|
||||||
|
ROUND_TO_WHOLE = Decimal('1')
|
||||||
|
|
||||||
|
|
||||||
def run_auto_sell(config: AutoSellConfig) -> AutoSellRunResults:
|
def run_auto_sell(config: AutoSellConfig) -> AutoSellRunResults:
|
||||||
"""Executes the sell-off.
|
"""Executes the sell-off.
|
||||||
|
|
||||||
|
@ -214,7 +217,7 @@ def run_auto_sell(config: AutoSellConfig) -> AutoSellRunResults:
|
||||||
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)
|
||||||
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)
|
logger.info('Attempting to sell %s %s', amount_to_sell, config.input_asset)
|
||||||
|
|
||||||
order_details = config.seller.place_market_order(
|
order_details = config.seller.place_market_order(
|
||||||
|
|
|
@ -26,7 +26,7 @@ class SellerMock(fin_depo.data.DepoFetcher):
|
||||||
input_asset: fin_defs.Asset,
|
input_asset: fin_defs.Asset,
|
||||||
input_amount: Decimal,
|
input_amount: Decimal,
|
||||||
output_asset: fin_defs.Asset,
|
output_asset: fin_defs.Asset,
|
||||||
) -> fin_depo.data.Depo:
|
) -> fin_depo.data.TradeOrderDetails:
|
||||||
assert input_amount <= self.amount_left, 'Attempt to sell too much'
|
assert input_amount <= self.amount_left, 'Attempt to sell too much'
|
||||||
self.amount_left -= input_amount
|
self.amount_left -= input_amount
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class SellerMock(fin_depo.data.DepoFetcher):
|
||||||
output_amount=input_amount,
|
output_amount=input_amount,
|
||||||
fee_asset=input_asset,
|
fee_asset=input_asset,
|
||||||
fee_amount=Decimal(0),
|
fee_amount=Decimal(0),
|
||||||
order_id=10000000 - self.amount_left,
|
order_id=Decimal(10000000 - self.amount_left),
|
||||||
raw_order_details={'TEST': 1, 'DATA': 2},
|
raw_order_details={'TEST': 1, 'DATA': 2},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user