2024-07-17 20:21:58 +00:00
|
|
|
import datetime
|
|
|
|
import logging
|
2024-07-21 12:56:57 +00:00
|
|
|
import logging.handlers
|
2024-07-22 12:53:48 +00:00
|
|
|
import argparse
|
2024-07-22 11:31:53 +00:00
|
|
|
import time
|
2024-07-22 11:36:52 +00:00
|
|
|
from decimal import Decimal
|
2024-07-17 20:21:58 +00:00
|
|
|
|
2024-07-21 12:56:57 +00:00
|
|
|
import fin_defs
|
2024-07-22 12:53:48 +00:00
|
|
|
import fin_depo
|
2024-07-17 20:21:58 +00:00
|
|
|
|
2024-07-22 12:12:05 +00:00
|
|
|
from . import PATH_LOG_FILE, AutoSellConfig, config, run_auto_sell, log_results
|
2024-07-21 12:56:57 +00:00
|
|
|
from . import logger as module_logger
|
2024-07-17 20:21:58 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
2024-07-21 12:56:57 +00:00
|
|
|
|
2024-07-22 11:36:52 +00:00
|
|
|
|
2024-07-22 11:21:41 +00:00
|
|
|
def setup_logging():
|
2024-07-22 12:53:48 +00:00
|
|
|
"""Enables logging for the terminal and to a log file."""
|
2024-07-21 12:56:57 +00:00
|
|
|
PATH_LOG_FILE.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
file_handler = logging.handlers.WatchedFileHandler(filename=PATH_LOG_FILE)
|
|
|
|
file_handler.setFormatter(
|
|
|
|
logging.Formatter(
|
2024-07-22 11:36:52 +00:00
|
|
|
'%(levelname)s:%(asctime)s: %(message)s',
|
|
|
|
datefmt='%Y-%m-%d %H:%M:%S',
|
2024-07-21 12:56:57 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
logging.basicConfig(handlers=[logging.StreamHandler(), file_handler])
|
|
|
|
|
|
|
|
logger.setLevel('INFO')
|
|
|
|
module_logger.setLevel('INFO')
|
|
|
|
|
2024-07-22 12:53:48 +00:00
|
|
|
CLI_DESCRIPTION = """
|
|
|
|
Sells financial assets from an online account.
|
|
|
|
""".strip()
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser('crypto_seller', description = CLI_DESCRIPTION)
|
|
|
|
return parser.parse_args()
|
2024-07-22 11:36:52 +00:00
|
|
|
|
2024-07-22 11:21:41 +00:00
|
|
|
def main():
|
2024-07-22 12:53:48 +00:00
|
|
|
"""Initializes the program."""
|
2024-07-22 11:21:41 +00:00
|
|
|
setup_logging()
|
2024-07-22 12:53:48 +00:00
|
|
|
|
|
|
|
args = parse_args()
|
|
|
|
|
2024-07-17 20:21:58 +00:00
|
|
|
logger.info('Initializing crypto_seller')
|
2024-07-21 12:56:57 +00:00
|
|
|
|
2024-07-22 11:21:41 +00:00
|
|
|
seller_backend = fin_depo.defi_kucoin.KucoinDepoFetcher(
|
|
|
|
kucoin_secret=config.KUCOIN_SECRET,
|
|
|
|
kucoin_key=config.KUCOIN_KEY,
|
|
|
|
kucoin_pass=config.KUCOIN_PASS,
|
|
|
|
)
|
|
|
|
|
|
|
|
auto_sell_config = AutoSellConfig(
|
2024-07-21 12:56:57 +00:00
|
|
|
input_amount_range=(Decimal('0.5'), Decimal('1')),
|
|
|
|
interval_range=(datetime.timedelta(seconds=2), datetime.timedelta(seconds=6)),
|
|
|
|
input_asset=fin_defs.MPC,
|
|
|
|
output_asset=fin_defs.USDT,
|
|
|
|
exit_when_empty=True,
|
2024-07-22 11:36:52 +00:00
|
|
|
seller=seller_backend,
|
|
|
|
sleep=time.sleep,
|
2024-07-17 20:21:58 +00:00
|
|
|
)
|
2024-07-22 12:12:05 +00:00
|
|
|
results = run_auto_sell(auto_sell_config)
|
|
|
|
logging.info('Sell-offs complete')
|
|
|
|
log_results(results)
|
2024-07-17 20:21:58 +00:00
|
|
|
|
2024-07-21 12:56:57 +00:00
|
|
|
|
2024-07-17 20:21:58 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|