From ede1dcfbefae4ecd4106af3a8158082b2dbd1743 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Thu, 28 Nov 2024 21:56:36 +0100 Subject: [PATCH] Updated to match changes to fin-depo that use AssetAmount for more functionality --- crypto_seller/__init__.py | 3 +-- crypto_seller/order_csv.py | 10 +++++++++- test/test_auto_sell.py | 18 +++++++----------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/crypto_seller/__init__.py b/crypto_seller/__init__.py index ff75cf1..c7b402c 100644 --- a/crypto_seller/__init__.py +++ b/crypto_seller/__init__.py @@ -217,8 +217,7 @@ def run_auto_sell(config: AutoSellConfig) -> AutoSellRunResults: logger.info('Attempting to sell %s %s', amount_to_sell, config.input_asset) order_details = config.seller.place_market_order( - config.input_asset, - amount_to_sell, + fin_defs.AssetAmount(config.input_asset, amount_to_sell), config.output_asset, ) diff --git a/crypto_seller/order_csv.py b/crypto_seller/order_csv.py index e957333..c73690a 100644 --- a/crypto_seller/order_csv.py +++ b/crypto_seller/order_csv.py @@ -32,4 +32,12 @@ class CsvFileLogger: # Write row in CSV file with open(self.path, 'a') as f: writer = csv.DictWriter(f, fieldnames=fieldnames) - writer.writerow(trade_order.__dict__) + d = trade_order.__dict__ + d['input_asset'] = d['input'].asset + d['input_amount'] = d['input'].amount + d['output_asset'] = d['output'].asset + d['output_amount'] = d['output'].amount + d['fee_asset'] = d['fee'].asset + d['fee_amount'] = d['fee'].amount + del d['fee'], d['input'], d['output'] + writer.writerow(d) diff --git a/test/test_auto_sell.py b/test/test_auto_sell.py index 64c6075..f5c580d 100644 --- a/test/test_auto_sell.py +++ b/test/test_auto_sell.py @@ -23,23 +23,19 @@ class SellerMock(fin_depo.data.DepoFetcher): def place_market_order( self, - input_asset: fin_defs.Asset, - input_amount: Decimal, + input_: fin_defs.AssetAmount, 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 + ) -> fin_depo.data.TradeOrderDetails: + assert input_.amount <= self.amount_left, 'Attempt to sell too much' + self.amount_left -= input_.amount executed_time = datetime.datetime.now(tz=datetime.UTC) return fin_depo.data.TradeOrderDetails( executed_time=executed_time, - input_asset=input_asset, - input_amount=input_amount, - output_asset=output_asset, - output_amount=input_amount, - fee_asset=input_asset, - fee_amount=Decimal(0), + input=input_, + output=fin_defs.AssetAmount(output_asset, input_.amount), + fee=fin_defs.AssetAmount(input_.asset, Decimal(0)), order_id=10000000 - self.amount_left, raw_order_details={'TEST': 1, 'DATA': 2}, )