Beispiel #1
0
 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}`")
Beispiel #2
0
 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}")
Beispiel #3
0
 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."
             )
Beispiel #4
0
 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.`")
Beispiel #5
0
 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)
Beispiel #6
0
 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.`")
Beispiel #7
0
 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.`")
Beispiel #8
0
 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.")
Beispiel #9
0
 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.")
Beispiel #10
0
    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
Beispiel #11
0
    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
Beispiel #12
0
 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)
Beispiel #13
0
 def is_enabled(config, associated_config=CONFIG_INTERFACES_TELEGRAM):
     return InterfaceBot.is_enabled(config,
                                    associated_config=associated_config)
Beispiel #14
0
 def enable(config,
            is_enabled,
            associated_config=CONFIG_INTERFACES_TELEGRAM):
     InterfaceBot.enable(config,
                         is_enabled,
                         associated_config=associated_config)
Beispiel #15
0
 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()
Beispiel #16
0
 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)
Beispiel #17
0
 def command_open_orders(_, update):
     if TelegramApp._is_valid_user(update):
         update.message.reply_text(InterfaceBot.get_command_open_orders())
Beispiel #18
0
 def command_trades_history(_, update):
     if TelegramApp._is_valid_user(update):
         update.message.reply_text(
             InterfaceBot.get_command_trades_history())
Beispiel #19
0
 def command_profitability(_, update):
     if TelegramApp._is_valid_user(update):
         update.message.reply_text(InterfaceBot.get_command_profitability())
Beispiel #20
0
 def command_portfolio(_, update):
     if TelegramApp._is_valid_user(update):
         update.message.reply_text(InterfaceBot.get_command_portfolio())
Beispiel #21
0
 def command_profitability(_, update):
     if TelegramApp._is_valid_user(update):
         TelegramApp._send_message(
             update, InterfaceBot.get_command_profitability(markdown=True))
Beispiel #22
0
 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()
Beispiel #23
0
 def command_portfolio(_, update):
     if TelegramApp._is_valid_user(update):
         TelegramApp._send_message(
             update, InterfaceBot.get_command_portfolio(markdown=True))
Beispiel #24
0
 def command_open_orders(_, update):
     if TelegramApp._is_valid_user(update):
         TelegramApp._send_message(
             update, InterfaceBot.get_command_open_orders(markdown=True))
Beispiel #25
0
 def command_trades_history(_, update):
     if TelegramApp._is_valid_user(update):
         TelegramApp._send_message(
             update, InterfaceBot.get_command_trades_history(markdown=True))