{"id":6434,"date":"2025-08-11T06:42:10","date_gmt":"2025-08-11T06:42:10","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=6434"},"modified":"2025-10-14T14:47:56","modified_gmt":"2025-10-14T14:47:56","slug":"telegram-trading-bot-backtesting","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting","title":{"rendered":"Telegram Trading Bot &#8211; Backtesting"},"content":{"rendered":"\n<p>I&#8217;ve implemented the backtesting functionality in the Telegram trading bot. To achieve this, I had to change the underlying architecture. Previously, the bot used the synchronous version of the python-telegram-bot library, but it now requires the asynchronous version. I have updated all the code accordingly to support this change.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n\n\n\n<p>If you are installing the project for the first time, no additional steps are required. Installing the dependencies via requirements.txt using PIP will automatically retrieve the correct version. However, if you have previously installed an older version of the bot, you will need to upgrade. I have specified the required version explicitly within the requirements.txt file.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code\"><code class=\"\">python-telegram-bot==20.7\napscheduler==3.10.4\nnumpy==1.26.3<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>If you try to install the pinned libraries using PIP, it will not automatically upgrade existing versions. You need to include the -U option to ensure they are updated.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code\"><code class=\"\">EODHDAlerts % python3 -m pip install -r requirements.txt -U<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<h2 class=\"wp-block-heading\" id=\"h-recap\">Recap<\/h2>\n\n\n\n<p>Before we get into the coding, I thought it would be useful to provide a quick recap of where things currently stand.<\/p>\n\n\n\n<p>The bot is started like this&#8230;<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code\"><code class=\"\">EODHDAlerts % python3 .\/bot.py \nINFO:root:Bot Started: Type \/start in Telegram trading bot channel.\nBot Started: Type \/start in Telegram trading bot channel.\nINFO:apscheduler.scheduler:Adding job tentatively -- it will be properly scheduled when the scheduler starts\nINFO:apscheduler.scheduler:Added job \"analyse_market\" to job store \"default\"\nINFO:apscheduler.scheduler:Scheduler started<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>You will know it&#8217;s working if in your Telegram bot channel you see this when you send the \/start command.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"738\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.24.53-1024x738.png\" alt=\"\" class=\"wp-image-6435\" srcset=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.24.53-1024x738.png 1024w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.24.53-300x216.png 300w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.24.53-768x553.png 768w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.24.53-1536x1106.png 1536w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.24.53-60x43.png 60w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.24.53-150x108.png 150w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.24.53.png 1552w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>If you see &#8220;Welcome to the Trading Bot!&#8221;, it means that Python has successfully connected to Telegram, as that message is sent by the bot.<\/p>\n\n\n\n<p>The bot has two main components: the push, which involves sending market data signals to the channel, and the pull, which handles receiving commands from Telegram users.<\/p>\n\n\n\n<p>For the pull functionality, in bot.py you will see the following&#8230;<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code\"><code class=\"\">    # Register all command handlers\n    dp.add_handler(CommandHandler(\"start\", start))\n    dp.add_handler(CommandHandler(\"set_symbol\", set_symbol))\n    dp.add_handler(CommandHandler(\"set_interval\", set_interval))\n    dp.add_handler(CommandHandler(\"get_price\", get_price))\n    dp.add_handler(CommandHandler(\"list_strategies\", list_strategies))\n    dp.add_handler(CommandHandler(\"set_strategy\", set_strategy))\n    dp.add_handler(CommandHandler(\"current_strategy\", current_strategy))<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>These are the registered commands you can send to the bot from Telegram. They are all fairly self-explanatory, but I\u2019ll demonstrate how they work. I&#8217;ve already shown you \/start. Now let&#8217;s take a look at \/set_symbol.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"733\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.31.07-1024x733.png\" alt=\"\" class=\"wp-image-6436\" srcset=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.31.07-1024x733.png 1024w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.31.07-300x215.png 300w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.31.07-768x550.png 768w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.31.07-1536x1099.png 1536w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.31.07-60x43.png 60w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.31.07-150x107.png 150w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.31.07.png 1554w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>You can change the market to any of the EODHD API stock codes. Now let&#8217;s change the interval. I\u2019m going to set it to a low value so I can try to generate a buy or sell signal to demonstrate how it works.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"732\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.35.31-1024x732.png\" alt=\"\" class=\"wp-image-6438\" srcset=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.35.31-1024x732.png 1024w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.35.31-300x214.png 300w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.35.31-768x549.png 768w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.35.31-1536x1097.png 1536w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.35.31-60x43.png 60w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.35.31-150x107.png 150w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.35.31.png 1548w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The Python bot console will show you what is happening in the background. At the moment, we are retrieving the Apple (AAPL.US) 1-minute intraday OHLCV data.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"92\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.38.21-1024x92.png\" alt=\"\" class=\"wp-image-6439\" srcset=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.38.21-1024x92.png 1024w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.38.21-300x27.png 300w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.38.21-768x69.png 768w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.38.21-1536x139.png 1536w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.38.21-2048x185.png 2048w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.38.21-60x5.png 60w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/06\/Screenshot-2025-06-28-at-11.38.21-150x14.png 150w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>We are currently waiting for a market signal to trigger, but in the meantime, you can see the bot in action by requesting the current price for the selected symbol (market) using the \/get_price command.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"644\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-17.56.31-1024x644.png\" alt=\"\" class=\"wp-image-6463\" srcset=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-17.56.31-1024x644.png 1024w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-17.56.31-300x189.png 300w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-17.56.31-768x483.png 768w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-17.56.31-1536x966.png 1536w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-17.56.31-60x38.png 60w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-17.56.31-150x94.png 150w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-17.56.31.png 1666w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>It was a bit tricky to demonstrate the bot in action, as I usually work on this over the weekend when the markets are closed. However, I did manage to catch a sell signal to show you. I also wanted to give you better visibility into what\u2019s happening in the background, so I added a debug option. The command is called \/debug.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"716\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.02.14-1024x716.png\" alt=\"\" class=\"wp-image-6464\" srcset=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.02.14-1024x716.png 1024w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.02.14-300x210.png 300w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.02.14-768x537.png 768w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.02.14-1536x1074.png 1536w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.02.14-60x42.png 60w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.02.14-150x105.png 150w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.02.14.png 1664w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>If you look under the &#8220;Current price&#8221;, you\u2019ll see that the last trading candle on Friday (yesterday) was a sell signal. I then enabled debug mode, and you can observe that the bot continues to indicate a sell signal every minute. However, this is only because no new data is coming in. I didn\u2019t want the bot to be completely silent during this time, so with debug mode enabled, you can now see that although the last candle is still a sell, the bot recognises that it has already alerted you and therefore won\u2019t take any further action.<br><br>Now for the part I\u2019m excited to show you \u2014 the backtesting functionality.<br><br>I didn\u2019t just want it to backtest your current strategy. I wanted to make it more generic to work on any of the supported options. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-backtesting\">Backtesting<\/h2>\n\n\n\n<p>I\u2019m going to show you how to list the currently supported strategies, and then run a backtest on the BTC-USD market using all of the available options.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"964\" height=\"1024\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.21.16-964x1024.png\" alt=\"\" class=\"wp-image-6465\" style=\"width:840px;height:auto\" srcset=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.21.16-964x1024.png 964w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.21.16-282x300.png 282w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.21.16-768x816.png 768w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.21.16-1446x1536.png 1446w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.21.16-56x60.png 56w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.21.16-141x150.png 141w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.21.16.png 1674w\" sizes=\"auto, (max-width: 964px) 100vw, 964px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>It\u2019s worth mentioning that I wouldn\u2019t expect an SMA strategy on a 1-minute interval for Bitcoin to be profitable. This is purely to demonstrate the bot\u2019s mechanics, not to showcase a winning strategy. That was the &#8220;sma&#8221; option \u2014 now let\u2019s try the others.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"847\" height=\"1024\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.24.51-847x1024.png\" alt=\"\" class=\"wp-image-6466\" srcset=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.24.51-847x1024.png 847w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.24.51-248x300.png 248w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.24.51-768x928.png 768w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.24.51-1271x1536.png 1271w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.24.51-50x60.png 50w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.24.51-124x150.png 124w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.24.51.png 1660w\" sizes=\"auto, (max-width: 847px) 100vw, 847px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"848\" height=\"1024\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.26.29-848x1024.png\" alt=\"\" class=\"wp-image-6467\" srcset=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.26.29-848x1024.png 848w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.26.29-249x300.png 249w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.26.29-768x927.png 768w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.26.29-1272x1536.png 1272w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.26.29-50x60.png 50w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.26.29-124x150.png 124w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-02-at-18.26.29.png 1660w\" sizes=\"auto, (max-width: 848px) 100vw, 848px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Interestingly, I would have expected all the strategies to perform poorly using a 1-minute interval. However, the RSI14 strategy actually performed slightly better than a coin toss. It would be interesting to see whether applying this strategy to longer intervals might improve the win\/loss ratio \u2014 I\u2019ll leave that for you to experiment with.<\/p>\n\n\n\n<p>It\u2019s also worth pointing out that the bot does not currently factor in exchange fees. EODHD APIs are not tied to any specific exchange. A potential future enhancement could be to add a command allowing users to apply a buy and\/or sell fee. This would make the backtest results more realistic, as many strategies that seem marginally profitable would actually result in a net loss once fees are accounted for.<\/p>\n\n\n\n<p>The bot has been designed to be highly customisable. You can add any strategy, provided the dataset includes the required &#8220;position&#8221; and &#8220;signal&#8221; fields. More advanced logic can also be used to combine strategies, as long as the bot is able to interpret the resulting signals.<\/p>\n\n\n\n<p>Hopefully I\u2019ve made it clear how to add your own commands and handlers. If you think of any useful commands, you should find it straightforward to implement them.<\/p>\n\n\n\n<p>As for next steps, adding persistence to the configuration would be useful. It would allow the bot to remember the selected market, strategy, and interval, and use them as defaults when it restarts.<\/p>\n\n\n\n<p>Another potentially useful feature would be the ability to browse the markets supported by the EODHD API directly via Telegram. I\u2019ve demonstrated examples using AAPL.US and BTC-USD.CC, but there are many more available. Adding a command to list the available markets could be an interesting and helpful enhancement.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve implemented the backtesting functionality in the Telegram trading bot. To achieve this, I had to change the underlying architecture. Previously, the bot used the synchronous version of the python-telegram-bot library, but it now requires the asynchronous version. I have updated all the code accordingly to support this change. If you are installing the project [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":6469,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[65,64],"tags":[],"coding-language":[30],"ready-to-go-solution":[56],"qualification":[31],"financial-apis-category":[34,36],"financial-apis-manuals":[],"class_list":["post-6434","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-backtesting-strategies-examples","category-building-stocks-apps-examples","coding-language-python","ready-to-go-solution-eodhd-python-financial-library","qualification-experienced","financial-apis-category-crypto-market-prices","financial-apis-category-stock-market-prices","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.9 (Yoast SEO v26.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Telegram Trading Bot - Backtesting | EODHD APIs Academy<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Telegram Trading Bot - Backtesting\" \/>\n<meta property=\"og:description\" content=\"I&#8217;ve implemented the backtesting functionality in the Telegram trading bot. To achieve this, I had to change the underlying architecture. Previously, the bot used the synchronous version of the python-telegram-bot library, but it now requires the asynchronous version. I have updated all the code accordingly to support this change. If you are installing the project [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting\" \/>\n<meta property=\"og:site_name\" content=\"Financial Academy\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/eodhistoricaldata\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-11T06:42:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-14T14:47:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/AdobeStock_572066008-scaled.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1463\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Whittle\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:site\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Whittle\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting\"},\"author\":{\"name\":\"Michael Whittle\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/50784c270b6267df5969514d80d510ad\"},\"headline\":\"Telegram Trading Bot &#8211; Backtesting\",\"datePublished\":\"2025-08-11T06:42:10+00:00\",\"dateModified\":\"2025-10-14T14:47:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting\"},\"wordCount\":975,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/AdobeStock_572066008-scaled.jpeg\",\"articleSection\":[\"Backtesting Strategies Examples\",\"Building Stocks Apps Examples\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting\",\"name\":\"Telegram Trading Bot - Backtesting | EODHD APIs Academy\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/AdobeStock_572066008-scaled.jpeg\",\"datePublished\":\"2025-08-11T06:42:10+00:00\",\"dateModified\":\"2025-10-14T14:47:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#primaryimage\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/AdobeStock_572066008-scaled.jpeg\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/AdobeStock_572066008-scaled.jpeg\",\"width\":2560,\"height\":1463,\"caption\":\"Stock market Robot. Trading Bot. Neon charts. Isolated on a black background.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Telegram Trading Bot &#8211; Backtesting\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"name\":\"Financial APIs Academy | EODHD\",\"description\":\"Financial Stock Market Academy\",\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\",\"name\":\"EODHD (EOD Historical Data)\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"width\":159,\"height\":82,\"caption\":\"EODHD (EOD Historical Data)\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/eodhistoricaldata\",\"https:\/\/x.com\/EOD_data\",\"https:\/\/www.reddit.com\/r\/EODHistoricalData\/\",\"https:\/\/eod-historical-data.medium.com\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/50784c270b6267df5969514d80d510ad\",\"name\":\"Michael Whittle\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5076af85c7ee0445454257247cad4970ae8cf5d7d4940d2b32c521f51c0a0f5a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5076af85c7ee0445454257247cad4970ae8cf5d7d4940d2b32c521f51c0a0f5a?s=96&d=mm&r=g\",\"caption\":\"Michael Whittle\"},\"description\":\"Solution architect, developer, and analyst with over 20+ years experience (TOP author on Medium).\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/author\/michaelwhittle\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Telegram Trading Bot - Backtesting | EODHD APIs Academy","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting","og_locale":"en_US","og_type":"article","og_title":"Telegram Trading Bot - Backtesting","og_description":"I&#8217;ve implemented the backtesting functionality in the Telegram trading bot. To achieve this, I had to change the underlying architecture. Previously, the bot used the synchronous version of the python-telegram-bot library, but it now requires the asynchronous version. I have updated all the code accordingly to support this change. If you are installing the project [&hellip;]","og_url":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2025-08-11T06:42:10+00:00","article_modified_time":"2025-10-14T14:47:56+00:00","og_image":[{"width":2560,"height":1463,"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/AdobeStock_572066008-scaled.jpeg","type":"image\/jpeg"}],"author":"Michael Whittle","twitter_card":"summary_large_image","twitter_creator":"@EOD_data","twitter_site":"@EOD_data","twitter_misc":{"Written by":"Michael Whittle","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting"},"author":{"name":"Michael Whittle","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/50784c270b6267df5969514d80d510ad"},"headline":"Telegram Trading Bot &#8211; Backtesting","datePublished":"2025-08-11T06:42:10+00:00","dateModified":"2025-10-14T14:47:56+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting"},"wordCount":975,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/AdobeStock_572066008-scaled.jpeg","articleSection":["Backtesting Strategies Examples","Building Stocks Apps Examples"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting","url":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting","name":"Telegram Trading Bot - Backtesting | EODHD APIs Academy","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/AdobeStock_572066008-scaled.jpeg","datePublished":"2025-08-11T06:42:10+00:00","dateModified":"2025-10-14T14:47:56+00:00","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#primaryimage","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/AdobeStock_572066008-scaled.jpeg","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/AdobeStock_572066008-scaled.jpeg","width":2560,"height":1463,"caption":"Stock market Robot. Trading Bot. Neon charts. Isolated on a black background."},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/telegram-trading-bot-backtesting#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"Telegram Trading Bot &#8211; Backtesting"}]},{"@type":"WebSite","@id":"https:\/\/eodhd.com\/financial-academy\/#website","url":"https:\/\/eodhd.com\/financial-academy\/","name":"Financial APIs Academy | EODHD","description":"Financial Stock Market Academy","publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/eodhd.com\/financial-academy\/#organization","name":"EODHD (EOD Historical Data)","url":"https:\/\/eodhd.com\/financial-academy\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","width":159,"height":82,"caption":"EODHD (EOD Historical Data)"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/eodhistoricaldata","https:\/\/x.com\/EOD_data","https:\/\/www.reddit.com\/r\/EODHistoricalData\/","https:\/\/eod-historical-data.medium.com\/"]},{"@type":"Person","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/50784c270b6267df5969514d80d510ad","name":"Michael Whittle","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5076af85c7ee0445454257247cad4970ae8cf5d7d4940d2b32c521f51c0a0f5a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5076af85c7ee0445454257247cad4970ae8cf5d7d4940d2b32c521f51c0a0f5a?s=96&d=mm&r=g","caption":"Michael Whittle"},"description":"Solution architect, developer, and analyst with over 20+ years experience (TOP author on Medium).","url":"https:\/\/eodhd.com\/financial-academy\/author\/michaelwhittle"}]}},"jetpack_featured_media_url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2025\/08\/AdobeStock_572066008-scaled.jpeg","jetpack_shortlink":"https:\/\/wp.me\/pdOdVT-1FM","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/6434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/comments?post=6434"}],"version-history":[{"count":6,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/6434\/revisions"}],"predecessor-version":[{"id":6567,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/6434\/revisions\/6567"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media\/6469"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=6434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=6434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=6434"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=6434"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=6434"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=6434"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=6434"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=6434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}