def command_real_traders_refresh(_, update): if TelegramApp._is_valid_user(update): result = "Refresh" try: InterfaceBot.set_command_real_traders_refresh() TelegramApp._send_message(update, f"`{result} successful`") except Exception as e: TelegramApp._send_message(update, f"`{result} failure: {e}`")
def command_real_traders_refresh(_, update): if TelegramApp._is_valid_user(update): result = "Refresh" try: InterfaceBot.set_command_real_traders_refresh() update.message.reply_text(result + " successful") except Exception as e: update.message.reply_text(f"{result} failure: {e}")
def command_risk(_, update): if TelegramApp._is_valid_user(update): try: InterfaceBot.set_command_risk( float(TelegramApp.get_command_param("/set_risk", update))) update.message.reply_text("New risk set successfully.") except Exception: update.message.reply_text( "Failed to set new risk, please provide a number between 0 and 1." )
def command_configuration(_, update): if TelegramApp._is_valid_user(update): try: TelegramApp._send_message(update, InterfaceBot.get_command_configuration(markdown=True)) except Exception: TelegramApp._send_message(update, "`I'm unfortunately currently unable to show you my configuration. " "Please wait for my initialization to complete.`")
def _send_message(update, message, markdown=True): messages = InterfaceBot._split_messages_if_too_long(message, MAX_MESSAGE_LENGTH, EOL) for m in messages: if markdown: update.message.reply_markdown(m) else: update.message.reply_text(m)
def command_market_status(_, update): if TelegramApp._is_valid_user(update): try: TelegramApp._send_message(update, InterfaceBot.get_command_market_status(markdown=True)) except Exception: TelegramApp._send_message(update, "`I'm unfortunately currently unable to show you my market " "evaluations, please retry in a few seconds.`")
def command_risk(_, update): if TelegramApp._is_valid_user(update): try: result_risk = InterfaceBot.set_command_risk(float(TelegramApp.get_command_param("/set_risk", update))) TelegramApp._send_message(update, f"`Risk successfully set to {result_risk}.`") except Exception: TelegramApp._send_message(update, "`Failed to set new risk, please provide a number between 0 and 1.`")
def command_configuration(_, update): if TelegramApp._is_valid_user(update): try: update.message.reply_text( InterfaceBot.get_command_configuration()) except Exception: update.message.reply_text( "I'm unfortunately currently unable to show you my configuration. " "Please wait for my initialization to complete.")
def command_market_status(_, update): if TelegramApp._is_valid_user(update): try: update.message.reply_text( InterfaceBot.get_command_market_status()) except Exception: update.message.reply_text( "I'm unfortunately currently unable to show you my market evaluations, " "please retry in a few seconds.")
def _is_valid_user(update, associated_config=CONFIG_INTERFACES_TELEGRAM): update_username = update.effective_chat["username"] is_valid, white_list = InterfaceBot._is_valid_user( update_username, associated_config=associated_config) if white_list and not is_valid: LOGGER.error( f"An unauthorized Telegram user is trying to talk to me: username: "******"{update_username}, first_name: {update.effective_chat['first_name']}, " f"text: {update.effective_message['text']}") return is_valid
def _is_valid_user(update, associated_config=CONFIG_INTERFACES_TELEGRAM): # only authorize users from a private chat if not TelegramApp._is_authorized_chat(update): return False update_username = update.effective_chat["username"] is_valid, white_list = InterfaceBot._is_valid_user(update_username, associated_config=associated_config) if white_list and not is_valid: TelegramApp.get_logger().error(f"An unauthorized Telegram user is trying to talk to me: username: "******"{update_username}, first_name: {update.effective_chat['first_name']}, " f"text: {update.effective_message['text']}") return is_valid
def command_start(_, update): if TelegramApp._is_valid_user(update): update.message.reply_text(InterfaceBot.get_command_start()) else: update.message.reply_text(UNAUTHORIZED_USER_MESSAGE)
def is_enabled(config, associated_config=CONFIG_INTERFACES_TELEGRAM): return InterfaceBot.is_enabled(config, associated_config=associated_config)
def enable(config, is_enabled, associated_config=CONFIG_INTERFACES_TELEGRAM): InterfaceBot.enable(config, is_enabled, associated_config=associated_config)
def command_stop(_, update): # TODO add confirmation if TelegramApp._is_valid_user(update): TelegramApp._send_message(update, "_I'm leaving this world..._") InterfaceBot.set_command_stop()
def command_start(_, update): if TelegramApp._is_valid_user(update): TelegramApp._send_message( update, InterfaceBot.get_command_start(markdown=True)) elif TelegramApp._is_authorized_chat(update): TelegramApp._send_message(update, UNAUTHORIZED_USER_MESSAGE)
def command_open_orders(_, update): if TelegramApp._is_valid_user(update): update.message.reply_text(InterfaceBot.get_command_open_orders())
def command_trades_history(_, update): if TelegramApp._is_valid_user(update): update.message.reply_text( InterfaceBot.get_command_trades_history())
def command_profitability(_, update): if TelegramApp._is_valid_user(update): update.message.reply_text(InterfaceBot.get_command_profitability())
def command_portfolio(_, update): if TelegramApp._is_valid_user(update): update.message.reply_text(InterfaceBot.get_command_portfolio())
def command_profitability(_, update): if TelegramApp._is_valid_user(update): TelegramApp._send_message( update, InterfaceBot.get_command_profitability(markdown=True))
def command_stop(_, update): # TODO add confirmation if TelegramApp._is_valid_user(update): update.message.reply_text("I'm leaving this world...") InterfaceBot.set_command_stop()
def command_portfolio(_, update): if TelegramApp._is_valid_user(update): TelegramApp._send_message( update, InterfaceBot.get_command_portfolio(markdown=True))
def command_open_orders(_, update): if TelegramApp._is_valid_user(update): TelegramApp._send_message( update, InterfaceBot.get_command_open_orders(markdown=True))
def command_trades_history(_, update): if TelegramApp._is_valid_user(update): TelegramApp._send_message( update, InterfaceBot.get_command_trades_history(markdown=True))