49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
|
|
||
|
import fin_defs
|
||
|
from decimal import Decimal
|
||
|
import fin_depo
|
||
|
import datetime
|
||
|
|
||
|
import crypto_seller
|
||
|
|
||
|
class SellerMock(fin_depo.data.DepoFetcher):
|
||
|
|
||
|
def __init__(self, asset: fin_defs.Asset, initial_amount: Decimal):
|
||
|
self.asset = asset
|
||
|
self.amount_left = initial_amount
|
||
|
|
||
|
def get_depo(self) -> fin_depo.data.Depo:
|
||
|
return fin_depo.data.DepoSingle('TestDepo', datetime.datetime.now(tz=datetime.UTC), {self.asset:self.amount_left})
|
||
|
|
||
|
def place_market_order(self, input_asset: fin_defs.Asset, input_amount:
|
||
|
Decimal, output_asset: fin_defs.Asset) -> fin_depo.data.Depo:
|
||
|
assert input_amount <= self.amount_left, 'Attempt to sell too much'
|
||
|
self.amount_left -= input_amount
|
||
|
|
||
|
return fin_depo.data.TradeOrderDetails(
|
||
|
input_asset=input_asset,
|
||
|
input_amount=input_amount,
|
||
|
output_asset=output_asset,
|
||
|
output_amount=input_amount, # TODO?
|
||
|
fee_asset=input_asset,
|
||
|
fee_amount=Decimal(0),
|
||
|
order_id=10000000 - self.amount_left,
|
||
|
raw_order_details={'TEST': 1, 'DATA': 2},
|
||
|
)
|
||
|
|
||
|
|
||
|
def test_auto_run():
|
||
|
config = crypto_seller.AutoSellConfig(
|
||
|
input_amount_range=(Decimal('1'), Decimal('1')),
|
||
|
interval_range=(datetime.timedelta(seconds=0), datetime.timedelta(seconds=0)),
|
||
|
input_asset=fin_defs.USDT,
|
||
|
output_asset=fin_defs.USD,
|
||
|
exit_when_empty=True,
|
||
|
)
|
||
|
seller = SellerMock(fin_defs.USDT, Decimal('1000'))
|
||
|
|
||
|
crypto_seller.run_auto_sell(seller, config)
|
||
|
|
||
|
assert seller.amount_left == 0
|
||
|
|