def make_transfer(bot, update, args):
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    if not len(args) == 3:
        bot.send_message(
            chat_id=update.message.chat_id,
            text=
            "/make_transfer <sender_name> <reciever_name> <amount(positive)>")

    else:
        try:
            backup_db(max_backup=int(
                read_from_config_file(CONFIG_FILE, 'creds', 'num_backup_dbs')))
            prt_id = read_from_config_file(CONFIG_FILE, 'creds',
                                           'portfolio_id')
            alg = Algorithm(current_sql_file(), prt_id)
            alg.make_transfer(sender_name=args[0],
                              reciever_name=args[1],
                              amount=float(args[2]))
            alg.chart_portfolio_acounts()

            bot.send_photo(chat_id=update.message.chat_id,
                           photo=open(f'media/portfolio-{prt_id}-accounts.png',
                                      'rb'))
        except Exception as ex:
            print(ex)
Ejemplo n.º 2
0
def edit_account(bot, update, args):
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    if len(args) < 2 or len(args) > 6:
        bot.send_message(
            chat_id=update.message.chat_id,
            text=
            "/edit_account <id> name:<name> fee:<fee> risk:<risk> profit:<profit> password:<password>"
        )

    else:
        try:
            backup_db(max_backup=int(
                read_from_config_file(CONFIG_FILE, 'creds', 'num_backup_dbs')))
            acc = Account(current_sql_file())
            params = dict()
            for arg in args[1:]:
                param = arg.split(':')
                params[param[0]] = param[1]

            account = acc.update_id(id=args[0], **params)
            reply_str = str()
            reply_str += f'ID: *{account[0]}*' + '\n'
            reply_str += f'NAME: *{account[1]}*' + '\n'
            reply_str += f'PERCENTAGE: *{account[2]*100}*' + '\n'
            reply_str += f'FEE: *{account[4]}*' + '\n'
            reply_str += f'RISK: *{account[5]*100}*' + '\n'
            reply_str += f'PROFIT: *{account[6]*100}*' + '\n'
            reply_str += f'TIMESTAMP: {account[3]}' + '\n'

            bot.send_message(chat_id=update.message.chat_id,
                             text=reply_str,
                             parse_mode=ParseMode.MARKDOWN)
        except Exception as ex:
            print(ex)
def set_main(bot, update, args):
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    if not len(args) == 1:
        bot.send_message(chat_id=update.message.chat_id,
                         text="/set_main <account_id>")

    else:
        try:
            backup_db(max_backup=int(
                read_from_config_file(CONFIG_FILE, 'creds', 'num_backup_dbs')))
            prt = Portfolio(current_sql_file())
            prt_id = read_from_config_file(CONFIG_FILE, 'creds',
                                           'portfolio_id')
            prt.update_id(prt_id, main_account=int(args[0]))
            prt = prt.retrieve_id(prt_id)

            reply_str = str()
            reply_str += f'ID: *{prt[0]}*' + '\n'
            reply_str += f'MAIN\_ACCOUNT\_FK: *{prt[1]}*'

            bot.send_message(chat_id=update.message.chat_id,
                             text=reply_str,
                             parse_mode=ParseMode.MARKDOWN)
        except Exception as ex:
            print(ex)
def pay_fees(bot, update):
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    try:
        backup_db(max_backup=int(
            read_from_config_file(CONFIG_FILE, 'creds', 'num_backup_dbs')))
        prt_id = read_from_config_file(CONFIG_FILE, 'creds', 'portfolio_id')
        alg = Algorithm(current_sql_file(), prt_id)
        alg.pay_fees()

        alg.chart_portfolio_acounts()

        bot.send_photo(chat_id=update.message.chat_id,
                       photo=open(f'media/portfolio-{prt_id}-accounts.png',
                                  'rb'))
    except Exception as ex:
        print(ex)
def remove_main(bot, update):
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    try:
        backup_db(max_backup=int(
            read_from_config_file(CONFIG_FILE, 'creds', 'num_backup_dbs')))
        alg = Algorithm(
            current_sql_file(),
            read_from_config_file(CONFIG_FILE, 'creds', 'portfolio_id'))
        prt = alg.remove_main()

        reply_str = str()
        reply_str += f'ID: *{prt[0]}*' + '\n'
        reply_str += f'MAIN\_ACCOUNT\_FK: *{prt[1]}*'

        bot.send_message(chat_id=update.message.chat_id,
                         text=reply_str,
                         parse_mode=ParseMode.MARKDOWN)
    except Exception as ex:
        print(ex)
def list_account_transactions(bot, update, args):
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    if not len(args) == 1:
        bot.send_message(chat_id=update.message.chat_id,
                         text="/list_account_transactions <name>")

    else:
        try:
            alg = Algorithm(
                current_sql_file(),
                read_from_config_file(CONFIG_FILE, 'creds', 'portfolio_id'))
            transaction_list = alg.list_account_transactions(name=args[0])

            bot.send_message(chat_id=update.message.chat_id,
                             text=transaction_list,
                             parse_mode=ParseMode.MARKDOWN)
            backup_db(max_backup=int(
                read_from_config_file(CONFIG_FILE, 'creds', 'num_backup_dbs')))
        except Exception as ex:
            print(ex)
Ejemplo n.º 7
0
def add_account(bot, update, args):
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    if len(args) < 5:
        bot.send_message(
            chat_id=update.message.chat_id,
            text=
            "/add_account <name> <fund> <fee> <risk> <profit> <is_main=False>")

    else:
        try:
            backup_db(max_backup=int(
                read_from_config_file(CONFIG_FILE, 'creds', 'num_backup_dbs')))
            alg = Algorithm(
                current_sql_file(),
                read_from_config_file(CONFIG_FILE, 'creds', 'portfolio_id'))
            accounts = alg.add_account(
                name=args[0],
                fund=float(args[1]),
                fee=float(args[2]),
                risk=float(args[3]),
                profit=float(args[4]),
                is_main=bool(args[5]) if len(args) == 6 else False)
            reply_str = str()
            for account in accounts:
                if account[1] == args[0]:
                    reply_str += f'ID: *{account[0]}*' + '\n'
                    reply_str += f'NAME: *{account[1]}*' + '\n'
                    reply_str += f'PERCENTAGE: *{account[2]*100}*' + '\n'
                    reply_str += f'FEE: *{account[4]}*' + '\n'
                    reply_str += f'RISK: *{account[5]*100}*' + '\n'
                    reply_str += f'PROFIT: *{account[6]*100}*' + '\n'
                    reply_str += f'TIMESTAMP: {account[3]}' + '\n'

            bot.send_message(chat_id=update.message.chat_id,
                             text=reply_str,
                             parse_mode=ParseMode.MARKDOWN)
        except Exception as ex:
            print(ex)
def update_total_fund(bot, update, args):
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    if not len(args) == 1:
        bot.send_message(chat_id=update.message.chat_id,
                         text="/update_total_fund <current_amount>")

    else:
        try:
            backup_db(max_backup=int(
                read_from_config_file(CONFIG_FILE, 'creds', 'num_backup_dbs')))
            alg = Algorithm(
                current_sql_file(),
                read_from_config_file(CONFIG_FILE, 'creds', 'portfolio_id'))
            alg.update_total_fund(new_fund=float(args[0]))
            alg.chart_portfolio_funds()

            prt = read_from_config_file(CONFIG_FILE, 'creds', 'portfolio_id')
            bot.send_photo(chat_id=update.message.chat_id,
                           photo=open(f'media/portfolio-{prt}-funds.png',
                                      'rb'))
        except Exception as ex:
            print(ex)