From 0e6e4a851010e951f25f056796782c97e5987e03 Mon Sep 17 00:00:00 2001 From: lorcalhost Date: Tue, 30 Mar 2021 11:09:52 +0200 Subject: [PATCH] Properly fix message too long error close #1 --- BTBManagerTelegram.py | 3 +- README.md | 173 +++++++++++++++++++++--------------------- 2 files changed, 89 insertions(+), 87 deletions(-) diff --git a/BTBManagerTelegram.py b/BTBManagerTelegram.py index 01ca010e..0480ef9c 100644 --- a/BTBManagerTelegram.py +++ b/BTBManagerTelegram.py @@ -329,7 +329,8 @@ def __btn_read_log(self): message = f'❌ Unable to find log file at `{log_file_path}`.'.replace('.', '\.') if os.path.exists(log_file_path): with open(log_file_path) as f: - message = f'Last *4096* characters in log file:\n\n```\n{f.read()[-4096:]}\n```'.replace('.', '\.') + file_content = f.read().replace('.', '\.')[-4000:] + message = f'Last *4000* characters in log file:\n\n```\n{file_content}\n```' return message def __cancel(self, update: Update, _: CallbackContext) -> int: diff --git a/README.md b/README.md index 484e54dc..59ba1846 100644 --- a/README.md +++ b/README.md @@ -1,86 +1,87 @@ -# Binance Trade Bot Manager Telegram -A Telegram bot for remotely managing [Binance Trade Bot]. - -**If you have feature requests please open an issue on this repo, developers are also welcome to contribute!** - -## About -I wanted to develop an easy way of managing [Binance Trade Bot] so that I wouldn't have to constantly ssh into the VPS and my non-techy friends could enjoy the benefits of the bot. - -As of now the bot is able to perform the following actions: -- Check bot status (running / not running) -- Start *Binance Trade Bot* -- Stop *Binance Trade Bot* -- Edit coin list (`supported_coin_list` file) -- Edit user configuration (`user.cfg` file) -- Delete database file (`crypto_trading.db` file) -- Display last 4096 characters of log file -- WIP Display gains / current ratios in the database - -The program's default behavior fetches Telegram `token` and `user_id` from [Binance Trade Bot]'s `apprise.yaml` file. -Only the Telegram user with `user_id` equal to the one set in the `apprise.yaml` file will be able to use the bot. - -⚠ The program is fully compatible with **Linux** and **Windows** through **[WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10)**, further compatibility testing needs to done for **native Windows** and **MacOS**. -## Installation -*Python 3* is required. -1. Install dependencies: -```console -# install required Python 3 modules -$ python3 -m pip install -r requirements.txt -``` -2. Move `BTBManagerTelegram.py` file into [Binance Trade Bot]'s installation folder (it should be in the same folder as `supported_coin_list` file) - -⚠ Make sure the correct `rwx` permissions are set and the program is run with correct privileges. - -## Usage -### **Method 1**: Run directly -**BTBManagerTelegram** can be run directly by executing the following command: -```console -# Run normally -$ python3 BTBManagerTelegram.py - -# If the bot is running on a server you may want to keep it running even after ssh connection is closed by using nohup -$ nohup python3 BTBManagerTelegram.py & -``` -Make sure [Binance Trade Bot]'s `apprise.yaml` file is correctly setup before running. -### **Method 2:** Import script -**BTBManagerTelegram** can be imported in your Python script and used in the following way: -```python -from BTBManagerTelegram import BTBManagerTelegram -BTBManagerTelegram() -``` -The `BTBManagerTelegram()` class takes the following ***optional*** initialization arguments: -- `root_path`: -*Default value*: `'./'` -*Description*: Current base directory, to be used in case the bot has not been put inside [Binance Trade Bot]'s installation folder. -- `from_yaml`: -*Default value*: `True` -*Description*: Set to `False` if you **don't** want *BTBManagerTelegram* to automatically fetch Telegram `token` and `user_id` from `apprise.yaml` file. -- `token`: -*Default value*: `None` -*Description*: If `from_yaml` is set to `False` this will be used as Telegram `token`. -- `user_id`: -*Default value*: `None` -*Description*: If `from_yaml` is set to `False` this will be used as Telegram `user_id`. - -## Interaction -Interaction with **BTBManagerTelegram** can be *started* by sending the command `/start` in the bot's Telegram chat. -## Disclaimer - -This project is for informational purposes only. You should not construe any -such information or other material as legal, tax, investment, financial, or -other advice. Nothing contained here constitutes a solicitation, recommendation, -endorsement, or offer by me or any third party service provider to buy or sell -any securities or other financial instruments in this or in any other -jurisdiction in which such solicitation or offer would be unlawful under the -securities laws of such jurisdiction. - -If you plan to use real money, USE AT YOUR OWN RISK. - -Under no circumstances will I be held responsible or liable in any way for any -claims, damages, losses, expenses, costs, or liabilities whatsoever, including, -without limitation, any direct or indirect damages for loss of profits. - -##### ⚙ Developed for the love of task automation by [Lorenzo Callegari](https://github.com/lorcalhost) - - -[Binance Trade Bot]: https://github.com/edeng23/binance-trade-bot +# Binance Trade Bot Manager Telegram +A Telegram bot for remotely managing [Binance Trade Bot]. + +**If you have feature requests please open an issue on this repo, developers are also welcome to contribute!** + +## About +I wanted to develop an easy way of managing [Binance Trade Bot] so that I wouldn't have to constantly ssh into the VPS and my non-techy friends could enjoy the benefits of the bot. + +As of now the bot is able to perform the following actions: +- Check bot status (running / not running) +- Start *Binance Trade Bot* +- Stop *Binance Trade Bot* +- Edit coin list (`supported_coin_list` file) +- Edit user configuration (`user.cfg` file) +- Delete database file (`crypto_trading.db` file) +- Display last 4096 characters of log file +- 👷🏻‍♂️ WIP Display gains / current ratios in the database + +The program's default behavior fetches Telegram `token` and `user_id` from [Binance Trade Bot]'s `apprise.yaml` file. +Only the Telegram user with `user_id` equal to the one set in the `apprise.yaml` file will be able to use the bot. + +⚠ The program is fully compatible with **Linux** and **Windows** through **[WSL]**, further compatibility testing needs to be done for **native Windows** and **MacOS**. +## Installation +*Python 3* is required. +1. Install dependencies: +```console +# install required Python 3 modules +$ python3 -m pip install -r requirements.txt +``` +2. Move `BTBManagerTelegram.py` file into [Binance Trade Bot]'s installation folder (it should be in the same folder as `supported_coin_list` file) + +⚠ Make sure the correct `rwx` permissions are set and the program is run with correct privileges. + +## Usage +### **Method 1**: Run directly +**BTBManagerTelegram** can be run directly by executing the following command: +```console +# Run normally +$ python3 BTBManagerTelegram.py + +# If the bot is running on a server you may want to keep it running even after ssh connection is closed by using nohup +$ nohup python3 BTBManagerTelegram.py & +``` +Make sure [Binance Trade Bot]'s `apprise.yaml` file is correctly setup before running. +### **Method 2:** Import script +**BTBManagerTelegram** can be imported in your Python script and used in the following way: +```python +from BTBManagerTelegram import BTBManagerTelegram +BTBManagerTelegram() +``` +The `BTBManagerTelegram()` class takes the following ***optional*** initialization arguments: +- `root_path`: +*Default value*: `'./'` +*Description*: Current base directory, to be used in case the bot has not been put inside [Binance Trade Bot]'s installation folder. +- `from_yaml`: +*Default value*: `True` +*Description*: Set to `False` if you **don't** want *BTBManagerTelegram* to automatically fetch Telegram `token` and `user_id` from `apprise.yaml` file. +- `token`: +*Default value*: `None` +*Description*: If `from_yaml` is set to `False` this will be used as Telegram `token`. +- `user_id`: +*Default value*: `None` +*Description*: If `from_yaml` is set to `False` this will be used as Telegram `user_id`. + +## Interaction +Interaction with **BTBManagerTelegram** can be *started* by sending the command `/start` in the bot's Telegram chat. +## Disclaimer + +This project is for informational purposes only. You should not construe any +such information or other material as legal, tax, investment, financial, or +other advice. Nothing contained here constitutes a solicitation, recommendation, +endorsement, or offer by me or any third party service provider to buy or sell +any securities or other financial instruments in this or in any other +jurisdiction in which such solicitation or offer would be unlawful under the +securities laws of such jurisdiction. + +If you plan to use real money, USE AT YOUR OWN RISK. + +Under no circumstances will I be held responsible or liable in any way for any +claims, damages, losses, expenses, costs, or liabilities whatsoever, including, +without limitation, any direct or indirect damages for loss of profits. + +##### ⚙ Developed for the love of task automation by [Lorenzo Callegari](https://github.com/lorcalhost) + + +[Binance Trade Bot]: https://github.com/edeng23/binance-trade-bot +[WSL]: https://docs.microsoft.com/en-us/windows/wsl/install-win10