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)
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)
Exemplo n.º 3
0
def chart_accounts(bot, update):
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)

    try:
        alg = Algorithm(
            current_sql_file(),
            read_from_config_file(CONFIG_FILE, 'creds', 'portfolio_id'))
        alg.chart_portfolio_acounts()

        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}-accounts.png', 'rb'))
    except Exception as ex:
        print(ex)
Exemplo n.º 4
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 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)
Exemplo n.º 8
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)
Exemplo n.º 10
0
def chart_account_funds(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="/chart_account_funds <name>")
    else:
        try:
            alg = Algorithm(
                current_sql_file(),
                read_from_config_file(CONFIG_FILE, 'creds', 'portfolio_id'))
            alg.chart_account_funds(name=args[0])

            bot.send_photo(chat_id=update.message.chat_id,
                           photo=open(f'media/{args[0]}-funds.png', 'rb'))
        except Exception as ex:
            print(ex)
Exemplo n.º 11
0
def list_accounts(bot, update):
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)

    try:
        acc = Account(current_sql_file())
        accounts = acc.retrieve_accounts_for_portfolio(
            read_from_config_file(CONFIG_FILE, 'creds', 'portfolio_id'))
        reply_str = '*ACCOUNTS*\n\n'
        for account in accounts:
            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\n'

        bot.send_message(chat_id=update.message.chat_id,
                         text=reply_str,
                         parse_mode=ParseMode.MARKDOWN)
    except Exception as ex:
        print(ex)
from telegram.ext import Updater
import logging
from variables_and_functions import CONFIG_FILE, read_from_config_file

from account_handlers import add_account_handler, list_accounts_handler, chart_accounts_handler, edit_account_handler, chart_account_funds_handler
from transaction_handlers import make_transaction_handler, make_transfer_handler, list_account_transactions_handler
from portfolio_handlers import update_total_fund_handler, chart_portfolio_funds_handler, remove_main_handler, set_main_handler, pay_fees_handler, list_portfolios_handler
from general_handlers import list_commands_handler, start_handler, undo_handler

logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    level=logging.INFO)

updater = Updater(read_from_config_file(CONFIG_FILE, 'creds', 'token'))

updater.dispatcher.add_handler(add_account_handler)
updater.dispatcher.add_handler(list_accounts_handler)
updater.dispatcher.add_handler(chart_accounts_handler)
updater.dispatcher.add_handler(edit_account_handler)
updater.dispatcher.add_handler(chart_account_funds_handler)

updater.dispatcher.add_handler(make_transaction_handler)
updater.dispatcher.add_handler(make_transfer_handler)
updater.dispatcher.add_handler(list_account_transactions_handler)

updater.dispatcher.add_handler(update_total_fund_handler)
updater.dispatcher.add_handler(chart_portfolio_funds_handler)
updater.dispatcher.add_handler(remove_main_handler)
updater.dispatcher.add_handler(set_main_handler)
updater.dispatcher.add_handler(pay_fees_handler)
updater.dispatcher.add_handler(list_portfolios_handler)