Telegram bot subscription for Os Engine robots.

Telegram bot subscription for Os Engine robots.

The OsEngine logging service now includes the functionality to send messages to Telegram. Additionally, the service has been enhanced to receive and process commands from its own Telegram bot.

 

1. Creating a Telegram bot to receive messages.

We will need a bot on the Telegram messenger. To create one, we will use BotFather, the official Telegram bot that allows the creation and management of bots. 

Search for BotFather in Telegram:

Start a chat with BotFather by sending the "/start" command:

BotFather will provide a list of commands, use the "/newbot" command to create a new bot. Choose a name for the bot, for example, "newOSAbot".

Next, select a username ending in "bot", for example, "newOSAbot_bot".

This is what the bot creation dialogue looks like:

BotFather will inform you of the successful creation of the bot and provide a Token. Save this Token for future use. You can further customize your bot in BotFather, add descriptions, commands, set an avatar, etc.

Obtain your Telegram ID using a bot that provides this information: https://t.me/userinfobot

Launch the bot, and it will provide us with an ID in response, which we save alongside the Token.

This is how it looks:

To test your newly created bot, search for its name in Telegram and start a chat. Check message delivery by using the Token and ID in the browser address ("https://api.telegram.org/bot + Token + /sendMessage?chatid= + ID + &text=Hello!").

If set up correctly, you will receive a welcome message from your bot.

All notifications from the OsEngine robot will now be sent to this bot.

 

2. Example robot in OsEngine.

The example robot can be found here:

Link to the source code on GitHub: https://github.com/AlexWan/OsEngine

 

3. Connecting the robot.

Name the bot, select "ParabolicSarTrade", and click "Accept".

Open a separate window for the robot and double click on the bot log table.

A window will open.

On the Newsletter tab, configure the Telegram server as follows:

1. Select Regime - On;

2. Check the types of data we want to receive.

3. Click Configure Telegram.

4. 

a. Fill in the Bot token;

b. Fill in the Chat ID;

c. Check the box if we want to receive commands from the Telegram bot;

d. Click "Accept".

5. Click the "Accept" button from step 4 in the previous window.

For each bot, we perform the settings for received messages in the same way.

Below is an example of the bot working with commands enabled.

If the "Processing Command from Telegram" checkbox is unchecked, command buttons in the Telegram bot will not be displayed.

To process commands, subscribe to the TelegramCommandEvent event in your trading bot constructor.

The private field _lastRegime is used to remember the bot's state before disabling it.

The private method TelegramCommandHandler handles incoming commands. The current commands include StopAllBots, StartAllBots, CancelAllActiveOrders, and GetStatus.

You can define your own logic for handling commands. The example shows basic usage. Other message types remain standard in other parts.

 

4. Sending messages from Connectors.

Message sending from connection logs is configured in the same way.

Enable the message types you want to see in Telegram.

After that, the server log will be sent to Telegram.

Received the log in OsEngine:

Received the log in Telegram:

Error messages are highlighted for easy identification.

Good luck with your algorithms!

OsEngine Support.