1
0

Output and secrets are now configurable
All checks were successful
Test Python / Test (push) Successful in 27s

This commit is contained in:
Jon Michael Aanes 2024-09-04 20:02:54 +02:00
parent 48a821a8d4
commit 92c7f3e541
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
5 changed files with 30 additions and 16 deletions

View File

@ -239,7 +239,9 @@ def run_auto_sell(
rounding=ROUND_DOWN,
)
logger.info(
'Attempting to sell %s %s', amount_to_sell, config.input_asset,
'Attempting to sell %s %s',
amount_to_sell,
config.input_asset,
)
order_details = config.seller.place_market_order(

View File

@ -25,18 +25,18 @@ logger = logging.getLogger(__name__)
################################################################################
# Constants #
PATH_OUTPUT = Path('./output').absolute()
PATH_LOG_FILE = PATH_OUTPUT / 'log.txt'
PATH_TRADES_FILE = PATH_OUTPUT / 'trades.csv'
PATH_FILE_LOG = 'log.txt'
PATH_FILE_TRADES = 'trades.csv'
################################################################################
# Application Setup #
def setup_logging():
def setup_logging(output_directory: 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 = output_directory / PATH_FILE_LOG
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',
@ -70,7 +70,7 @@ License : MIT License (see website for full text)
""".strip()
def load_config(config_path: Path) -> AutoSellConfig:
def load_config(config_path: Path, output_directory: Path) -> AutoSellConfig:
logger.info('Loading configuration')
from . import secrets_config
@ -99,7 +99,7 @@ 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(output_directory / PATH_FILE_TRADES),
)
@ -117,6 +117,13 @@ def parse_args():
required=True,
help='Trading configuration file',
)
parser.add_argument(
'--output',
type=Path,
dest='output_directory',
required=True,
help='Directory for outputing logs and trades list',
)
parser.add_argument(
'--wait-before-first',
action='store_true',
@ -128,13 +135,17 @@ def parse_args():
def main():
"""Initializes the program."""
setup_logging()
logger.info('Initializing crypto_seller')
args = parse_args()
setup_logging(output_directory=args.output_directory)
logger.info('Initializing crypto_seller')
# Load config
auto_sell_config = load_config(args.config_file)
auto_sell_config = load_config(
args.config_file,
output_directory=args.output_directory,
)
# Display estimates
try:

View File

@ -4,7 +4,7 @@ from secret_loader import SecretLoader
__all__ = ['KUCOIN_KEY', 'KUCOIN_SECRET', 'KUCOIN_PASS']
secret_loader = SecretLoader()
secret_loader = SecretLoader(ENV_KEY_PREFIX='CS')
KUCOIN_KEY = secret_loader.load_or_fail('KUCOIN_KEY')
KUCOIN_SECRET = secret_loader.load_or_fail('KUCOIN_SECRET')

1
requirements_test.txt Normal file
View File

@ -0,0 +1 @@
pytest

View File

@ -65,7 +65,7 @@ def test_auto_run():
exit_when_empty=True,
seller=seller_mock,
log_order_to_csv=crypto_seller.order_csv.CsvFileLogger(
Path('output/test-trades.csv'),
Path('test/output/test-trades.csv'),
),
sleep=sleep_mock,
)
@ -82,4 +82,4 @@ def test_auto_run():
# Check mocks agree
assert seller_mock.amount_left == 0
assert sleep_mock.time_slept == 1000 + 23
assert sleep_mock.time_slept == 1000 + 17.2