def stop_bot(): logger.info("Stop bot button pressed.") message = "⚠ Binance Trade Bot is not running." if get_binance_trade_bot_process(): find_and_kill_binance_trade_bot_process() if not get_binance_trade_bot_process(): message = "✔ Successfully stopped the bot." else: message = ( "❌ Unable to stop Binance Trade Bot.\n\n" "If you are running the telegram bot on Windows make sure to run with administrator privileges." ) return message
def edit_user_cfg(): logger.info("Edit user configuration button pressed.") message = "⚠ Please stop Binance Trade Bot before editing user configuration file\." edit = False user_cfg_file_path = os.path.join(settings.ROOT_PATH, "user.cfg") if not get_binance_trade_bot_process(): if os.path.exists(user_cfg_file_path): with open(user_cfg_file_path) as f: message = ( f"Current configuration file is:\n\n" f"```\n" f"{f.read()}\n" f"```\n\n" f"_*Please reply with a message containing the updated configuration*_.\n\n" f"Write /stop to stop editing and exit without changes.".replace( ".", "\." ) ) edit = True else: message = f"❌ Unable to find user configuration file at `{user_cfg_file_path}`.".replace( ".", "\." ) return [message, edit]
def check_status(): logger.info("Check status button pressed.") message = "⚠ Binance Trade Bot is not running." if get_binance_trade_bot_process(): message = "✔ Binance Trade Bot is running." return message
def start_bot(): logger.info("Start bot button pressed.") message = "⚠ Binance Trade Bot is already running\." if not get_binance_trade_bot_process(): if os.path.exists(os.path.join(settings.ROOT_PATH, "binance_trade_bot/")): subprocess.call( f"cd {settings.ROOT_PATH} && $(which python3) -m binance_trade_bot &", shell=True, ) if get_binance_trade_bot_process(): message = "✔ Binance Trade Bot successfully started\." else: message = "❌ Unable to start Binance Trade Bot\." else: message = ( f"❌ Unable to find _Binance Trade Bot_ installation at {settings.ROOT_PATH}\.\n" f"Make sure the `binance-trade-bot` and `BTB-manager-telegram` are in the same parent directory\." ) return message
def export_db(): logger.info("Export database button pressed.") message = "⚠ Please stop Binance Trade Bot before exporting the database file\." db_file_path = os.path.join(settings.ROOT_PATH, "data/crypto_trading.db") fil = None if not get_binance_trade_bot_process(): if os.path.exists(db_file_path): with open(db_file_path, "rb") as db: fil = db.read() message = "Here is your database file:" else: message = "❌ Unable to Export the database file\." return [message, fil]
def delete_db(): logger.info("Delete database button pressed.") message = "⚠ Please stop Binance Trade Bot before deleting the database file\." delete = False db_file_path = os.path.join(settings.ROOT_PATH, "data/crypto_trading.db") if not get_binance_trade_bot_process(): if os.path.exists(db_file_path): message = "Are you sure you want to delete the database file?" delete = True else: message = f"⚠ Unable to find database file at `{db_file_path}`.".replace( ".", "\." ) return [message, delete]
def edit_coin(): logger.info("Edit coin list button pressed.") message = "⚠ Please stop Binance Trade Bot before editing the coin list\." edit = False coin_file_path = os.path.join(settings.ROOT_PATH, "supported_coin_list") if not get_binance_trade_bot_process(): if os.path.exists(coin_file_path): with open(coin_file_path) as f: message = ( f"Current coin list is:\n\n" f"```\n{f.read()}\n```\n\n" f"_*Please reply with a message containing the updated coin list*_.\n\n" f"Write /stop to stop editing and exit without changes.". replace(".", "\.")) edit = True else: message = f"❌ Unable to find coin list file at `{coin_file_path}`.".replace( ".", "\.") return [message, edit]