Ejemplo n.º 1
0
def update_btb(update: Update, _: CallbackContext) -> int:
    logger.info(f"Updating Binance Trade Bot. ({update.message.text})")

    keyboard = [["OK 👌"]]
    reply_markup = ReplyKeyboardMarkup(keyboard, resize_keyboard=True)

    if update.message.text != "Cancel update":
        message = ("The bot has been stopped and is now updating\.\n"
                   "Wait a few seconds, then restart manually\.")
        update.message.reply_text(message,
                                  reply_markup=reply_markup,
                                  parse_mode="MarkdownV2")
        try:
            find_and_kill_binance_trade_bot_process()
            subprocess.call(
                f"cd {settings.ROOT_PATH} && "
                f"git pull && "
                f"$(which python3) -m pip install -r requirements.txt --upgrade",
                shell=True,
            )
        except Exception as e:
            logger.error(f"Unable to update Binance Trade Bot: {e}")
            message = "Unable to update Binance Trade Bot"
            update.message.reply_text(message,
                                      reply_markup=reply_markup,
                                      parse_mode="MarkdownV2")
    else:
        message = "👌 Exited without changes\.\n" "Binance Trade Bot was *not* updated\."
        update.message.reply_text(message,
                                  reply_markup=reply_markup,
                                  parse_mode="MarkdownV2")

    return MENU
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
def panic(update: Update, _: CallbackContext) -> int:
    logger.info(f"Panic Button is doing its job. ({update.message.text})")

    keyboard = [["Great 👌"]]
    reply_markup = ReplyKeyboardMarkup(keyboard, resize_keyboard=True)
    if update.message.text != "Go back":
        find_and_kill_binance_trade_bot_process()

        # Get current coin pair
        db_file_path = os.path.join(settings.ROOT_PATH,
                                    "data/crypto_trading.db")
        con = sqlite3.connect(db_file_path)
        cur = con.cursor()

        # Get last trade
        cur.execute(
            """SELECT alt_coin_id, crypto_coin_id FROM trade_history ORDER BY datetime DESC LIMIT 1;"""
        )
        alt_coin_id, crypto_coin_id = cur.fetchone()

        # Get Binance api keys and tld
        user_cfg_file_path = os.path.join(settings.ROOT_PATH, "user.cfg")
        with open(user_cfg_file_path) as cfg:
            config = ConfigParser()
            config.read_file(cfg)
            api_key = config.get("binance_user_config", "api_key")
            api_secret_key = config.get("binance_user_config",
                                        "api_secret_key")
            tld = config.get("binance_user_config", "tld")

        if update.message.text != "⚠ Stop & sell at market price":
            params = {
                "symbol": f"{alt_coin_id}{crypto_coin_id}",
                "side": "SELL",
                "type": "MARKET",
            }
            message = send_signed_request(
                api_key,
                api_secret_key,
                f"https://api.binance.{tld}",
                "POST",
                "/api/v3/order",
                payload=params,
            )

        if update.message.text != "⚠ Stop & cancel order":
            params = {"symbol": f"{alt_coin_id}{crypto_coin_id}"}
            message = send_signed_request(
                api_key,
                api_secret_key,
                f"https://api.binance.{tld}",
                "DELETE",
                "/api/v3/openOrders",
                payload=params,
            )

        if update.message.text != "⚠ Stop the bot":
            message = "Killed _Binance Trade Bot_!"
    else:
        message = "👌 Exited without changes\.\n" "Binance Trade Bot was *not* updated\."

    update.message.reply_text(message,
                              reply_markup=reply_markup,
                              parse_mode="MarkdownV2")
    return MENU