1
0

Allow specifying output folder

This commit is contained in:
Jon Michael Aanes 2024-12-02 17:34:18 +01:00
parent 5e349f95ee
commit 0b2a73be24
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
2 changed files with 18 additions and 17 deletions

View File

@ -177,11 +177,11 @@ class AutoSellRunResults:
def total_input_amount(self) -> Decimal: def total_input_amount(self) -> Decimal:
"""Total amount of assets sold.""" """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: def total_output_amount(self) -> Decimal:
"""Total amount of assets "bought".""" """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: def sample_from_range(rng: random.Random, rang: tuple[Any, Any]) -> Any:

View File

@ -20,21 +20,14 @@ from . import logger as module_logger
logger = logging.getLogger(__name__) 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 # # Application Setup #
def setup_logging(): def setup_logging(path_log_file: Path):
"""Enables logging for the terminal and to a log file.""" """Enables logging for the terminal and to a log file."""
PATH_LOG_FILE.parent.mkdir(parents=True, exist_ok=True) path_log_file.parent.mkdir(parents=True, exist_ok=True)
file_handler = logging.handlers.WatchedFileHandler(filename=PATH_LOG_FILE) file_handler = logging.handlers.WatchedFileHandler(filename=path_log_file)
file_handler.setFormatter( file_handler.setFormatter(
logging.Formatter( logging.Formatter(
'%(levelname)s:%(asctime)s: %(message)s', '%(levelname)s:%(asctime)s: %(message)s',
@ -61,7 +54,7 @@ Sells financial assets from an online account.
""".strip() """.strip()
def load_config(config_path: Path) -> AutoSellConfig: def load_config(config_path: Path, path_trades_file: Path) -> AutoSellConfig:
logger.info('Loading configuration') logger.info('Loading configuration')
from . import secrets_config from . import secrets_config
@ -90,24 +83,32 @@ def load_config(config_path: Path) -> AutoSellConfig:
exit_when_empty=True, exit_when_empty=True,
seller=seller_backend, seller=seller_backend,
sleep=time.sleep, 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(): def parse_args():
parser = argparse.ArgumentParser('crypto_seller', description=CLI_DESCRIPTION) parser = argparse.ArgumentParser('crypto_seller', description=CLI_DESCRIPTION)
parser.add_argument('--config', type=Path, dest='config_file', required=True) 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() return parser.parse_args()
def main(): def main():
"""Initializes the program.""" """Initializes the program."""
setup_logging()
logger.info('Initializing crypto_seller')
args = parse_args() 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) results = run_auto_sell(auto_sell_config)
logging.info('Sell-offs complete') logging.info('Sell-offs complete')
log_results(results) log_results(results)