diff --git a/crypto_seller/__init__.py b/crypto_seller/__init__.py index c7b402c..4468006 100644 --- a/crypto_seller/__init__.py +++ b/crypto_seller/__init__.py @@ -177,11 +177,11 @@ class AutoSellRunResults: def total_input_amount(self) -> Decimal: """Total amount of assets sold.""" - return sum((o.input_amount for o in self.order_details), start=Decimal(0)) + return sum((o.input.amount for o in self.order_details), start=Decimal(0)) def total_output_amount(self) -> Decimal: """Total amount of assets "bought".""" - return sum((o.output_amount for o in self.order_details), start=Decimal(0)) + return sum((o.output.amount for o in self.order_details), start=Decimal(0)) def sample_from_range(rng: random.Random, rang: tuple[Any, Any]) -> Any: diff --git a/crypto_seller/__main__.py b/crypto_seller/__main__.py index 662c245..0429b1d 100644 --- a/crypto_seller/__main__.py +++ b/crypto_seller/__main__.py @@ -20,21 +20,14 @@ from . import logger as module_logger logger = logging.getLogger(__name__) -################################################################################ -# Constants # - -PATH_OUTPUT = Path('./output').absolute() -PATH_LOG_FILE = PATH_OUTPUT / 'log.txt' -PATH_TRADES_FILE = PATH_OUTPUT / 'trades.csv' - ################################################################################ # Application Setup # -def setup_logging(): +def setup_logging(path_log_file: Path): """Enables logging for the terminal and to a log file.""" - PATH_LOG_FILE.parent.mkdir(parents=True, exist_ok=True) - file_handler = logging.handlers.WatchedFileHandler(filename=PATH_LOG_FILE) + path_log_file.parent.mkdir(parents=True, exist_ok=True) + file_handler = logging.handlers.WatchedFileHandler(filename=path_log_file) file_handler.setFormatter( logging.Formatter( '%(levelname)s:%(asctime)s: %(message)s', @@ -61,7 +54,7 @@ Sells financial assets from an online account. """.strip() -def load_config(config_path: Path) -> AutoSellConfig: +def load_config(config_path: Path, path_trades_file: Path) -> AutoSellConfig: logger.info('Loading configuration') from . import secrets_config @@ -90,24 +83,32 @@ def load_config(config_path: Path) -> AutoSellConfig: exit_when_empty=True, seller=seller_backend, sleep=time.sleep, - log_order_to_csv=order_csv.CsvFileLogger(PATH_TRADES_FILE), + log_order_to_csv=order_csv.CsvFileLogger(path_trades_file), ) def parse_args(): parser = argparse.ArgumentParser('crypto_seller', description=CLI_DESCRIPTION) parser.add_argument('--config', type=Path, dest='config_file', required=True) + parser.add_argument('--output', type=Path, dest='output_folder', required=True) return parser.parse_args() def main(): """Initializes the program.""" - setup_logging() - logger.info('Initializing crypto_seller') args = parse_args() - auto_sell_config = load_config(args.config_file) + # Setup output paths + path_output = args.output_folder.absolute() + path_output.mkdir(parents=True, exist_ok=True) + path_log_file = path_output / 'log.txt' + path_trades_file = path_output / 'trades.csv' + setup_logging(path_log_file ) + + logger.info('Initializing crypto_seller') + + auto_sell_config = load_config(args.config_file, path_trades_file) results = run_auto_sell(auto_sell_config) logging.info('Sell-offs complete') log_results(results)