1
0

Improved CLI

This commit is contained in:
Jon Michael Aanes 2024-09-04 17:53:06 +02:00
parent c8ce383751
commit af07c75820
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
2 changed files with 33 additions and 16 deletions

View File

@ -95,14 +95,20 @@ most mature on the danish market, and does support KuCoin.
## TODO
- [ ] Present an overview of what the script will be doing
* Sell what for what? How much, how often?
* Give an estimate of how long it will take.
* Wait 20 seconds before starting, to allow the user to review.
- [ ] Allow multiple secrets configs
- [ ] Allow multiple output directories
- [ ] Fix `TimeoutError` issue occuring from slow Kucoin endpoint. Might
require implementing own kucoin backend in `fin_depo`.
- [ ] Ensure that a failure during selling results in a safe winding down of the system.
* Catch runtime errors when selling
* Show errors to log.
* Stop loop and exit with results, and error indicator.
* Catch runtime errors when selling
* Show status
* Show errors to log.
* Stop loop and exit with results, and error indicator.
- [X] Present an overview of what the script will be doing
* Sell what for what? How much, how often?
* Give an estimate of how long it will take.
* Wait 20 seconds before starting, to allow the user to review.
- [X] Document command-line arguments
- [X] Document configuration
- [X] Document code auditing
- [X] Parse configuration from json.
@ -195,7 +201,7 @@ def sample_from_range(rng: random.Random, rang: tuple[Any, Any]) -> Any:
ROUND_TO_WHOLE = Decimal('1')
def run_auto_sell(config: AutoSellConfig, skip_first:int=0) -> AutoSellRunResults:
def run_auto_sell(config: AutoSellConfig, initial_rounds_to_skip:int=0) -> AutoSellRunResults:
"""Executes the sell-off.
Sell-offs are performed in rounds of sizes and with intervals randomly
@ -214,9 +220,9 @@ def run_auto_sell(config: AutoSellConfig, skip_first:int=0) -> AutoSellRunResult
)
logger.info('Currently own %s %s', input_amount_available, config.input_asset.raw_short_name())
if skip_first > 0:
skip_first -= 1
logger.info('Skipping this round')
if initial_rounds_to_skip > 0:
initial_rounds_to_skip -= 1
logger.info('skipping this round')
elif input_amount_available > 0:
amount_to_sell = sample_from_range(rng, config.input_amount_range)
amount_to_sell = min(input_amount_available, amount_to_sell)

View File

@ -58,9 +58,15 @@ def setup_logging():
CLI_DESCRIPTION = """
Sells financial assets from an online account.
Script to automatically and with little effort sell financial assets from
online accounts.
""".strip()
CLI_EPILOG = """
Author : Jon Michael Aanes (jonjmaa@gmail.com)
Website : https://gitfub.space/Jmaa/crypto-seller
License : MIT License (see website for full text)
""".strip()
def load_config(config_path: Path) -> AutoSellConfig:
logger.info('Loading configuration')
@ -96,9 +102,14 @@ def load_config(config_path: Path) -> AutoSellConfig:
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('--skip-first', action='store_true', dest='skip_first')
parser = argparse.ArgumentParser(prog='crypto_seller',
description=CLI_DESCRIPTION,
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=CLI_EPILOG)
parser.add_argument('--config', type=Path, dest='config_file',
required=True, help='Trading configuration file')
parser.add_argument('--wait-before-first', action='store_true', dest='wait_before_first',
help='Skip the first sell-off round, and wait for the next.')
return parser.parse_args()
@ -116,7 +127,7 @@ def main():
log_estimates(auto_sell_config)
# Run auto sell
results = run_auto_sell(auto_sell_config, skip_first=args.skip_first and 1 or 0)
results = run_auto_sell(auto_sell_config, initial_rounds_to_skip=args.wait_before_first and 1 or 0)
# Display results
logging.info('Sell-offs complete')