def chart_portfolio_funds(bot, update): bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING) try: prt = read_from_config_file(CONFIG_FILE, 'creds', 'portfolio_id') alg = Algorithm(current_sql_file(), prt) alg.chart_portfolio_funds() bot.send_photo(chat_id=update.message.chat_id, photo=open(f'media/portfolio-{prt}-funds.png', 'rb')) except Exception as ex: print(ex)
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)
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)
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 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 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 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)