Skip to content

yariks5s/analysis_telegram_bot

Repository files navigation

CryptoBot: Advanced Crypto Signal Telegram Bot

Overview

CryptoBot is an advanced Telegram bot for cryptocurrency traders, providing automated technical analysis, signal generation, and charting for any crypto pair. It leverages a suite of custom indicators and multi-timeframe analysis to deliver actionable trading signals, visualizations, and user-customizable preferences—all via Telegram.


Features

  • Automated Signal Generation: Multi-timeframe, probability-based bullish/bearish/neutral signals for any crypto pair.
  • Custom Technical Indicators: Includes Order Blocks, Fair Value Gaps (FVGs), Liquidity Levels, and Breaker Blocks.
  • Interactive Telegram Bot: Manage signals, select indicators, and receive charts directly in Telegram.
  • User Preferences: Per-user indicator selection, chart options (legend, volume), custom indicator parameters, and signal frequency.
  • Backtesting & Strategy Optimization: Built-in backtesting and training modules for strategy evaluation.
  • Database-Backed: User preferences and signal jobs are persisted in a local SQLite database.
  • Beautiful Charting: Candlestick charts with overlays for all supported indicators.
  • Rate Limiting & Abuse Prevention: Advanced protection against API abuse with per-user quotas and metadata-based fingerprinting.

Supported Indicators

  • Order Blocks: Detects key supply/demand zones based on price impulses and reversals.
  • Fair Value Gaps (FVGs): Identifies price gaps (inefficiencies) that may act as support/resistance.
  • Liquidity Levels: Finds significant support/resistance using ATR-based fractal pivots and clustering.
  • Breaker Blocks: Detects liquidity sweeps and reversals, highlighting potential breakout/reversal zones.

All indicators can be enabled/disabled per user.


Installation

  1. Clone the repository:

    git clone <your-repo-url>
    cd cryptoBot
  2. Install dependencies:

    pip install -r requirements.txt
  3. Set up environment variables:

    • Create a .env file in the root directory.
    • Add your Telegram bot token:
      API_TELEGRAM_KEY=your_telegram_bot_token_here
  4. (Optional) Run tests:

    pytest

Running the Bot

  1. Start the bot:

    pip install -r requirements.txt
    python main.py

    The bot will initialize the database (preferences.db) automatically if it does not exist.

  2. Add your bot to Telegram and start a chat.


Customer/User Instructions

Main Commands

  • /chart <symbol> <hours> <interval> <tolerance>

    • Get a candlestick chart with all enabled indicators.
    • Example: /chart BTCUSDT 48 1h 0.05
  • /text_result <symbol> <hours> <interval> <tolerance>

    • Get a text summary of all detected indicators.
    • Example: /text_result ETHUSDT 24 15m 0.03
  • /preferences

    • Interactive menu to select which indicators to use and chart options (legend, volume).
  • /create_signal <symbol> <minutes> [<is_with_chart>]

    • Start receiving auto-signals for a pair at a given frequency (in minutes).
    • Example: /create_signal BTCUSDT 60 true
  • /delete_signal <symbol>

    • Stop auto-signals for a pair.
    • Example: /delete_signal BTCUSDT
  • /manage_signals

    • Interactive menu to view, add, or delete your signal jobs.

Signal Jobs

  • Signals are sent automatically at your chosen frequency, with or without charts, based on your preferences.
  • You can have up to 10 active signal jobs per user.

Indicator Selection & Parameters

  • Use /preferences to enable/disable Order Blocks, FVGs, Liquidity Levels, Breaker Blocks, and chart options.
  • Customize indicator parameters through the Parameter Settings menu (ATR period, FVG minimum size).
  • Preferences are saved per user.

Charting & Visualization

  • Charts are generated using mplfinance and matplotlib.
  • Overlays include:
    • Order Blocks (bullish/bearish)
    • FVGs (highlighted gaps)
    • Liquidity Levels (horizontal lines)
    • Breaker Blocks (colored zones)
    • Optional legend and volume

Database

  • Uses SQLite (preferences.db) for user preferences and signal job persistence.
  • No manual setup required; tables are created automatically on first run.

Rate Limiting & Abuse Prevention

The bot implements advanced rate limiting and adaptive abuse prevention mechanisms to protect API resources


Backtesting & Strategy Training

  • The back_tester/ directory contains scripts for backtesting and optimizing signal logic.
  • See back_tester/strategy.py and back_tester/trainer.py for details.

Contributing & Testing

  • Contributions are welcome! Please add tests for new features.
  • Run all tests with:
    pytest

Requirements

All dependencies are listed in requirements.txt. Key packages:

  • python-telegram-bot
  • pandas, numpy, scikit-learn, scipy
  • matplotlib, mplfinance
  • python-dotenv
  • requests

Project Structure

The project follows a modular structure for better organization and maintainability:

/cryptoBot/
├── src/                           # Source code directory
│   ├── core/                      # Core functionality
│   │
│   ├── api/                       # API interactions
│   │
│   ├── database/                  # Database operations
│   │
│   ├── analysis/                  # Technical analysis 
│   │
│   ├── visualization/             # Visualization components
│   │
│   ├── telegram/                  # Telegram bot functionality
│   │
│   └── model_classes/             # Data models
├── back_tester/                   # Backtesting system
├── tests/                         # Test directory
├── main.py                        # Entry point
└── README.md                      # Documentation

License

TBD


Contact

For questions or support, open an issue or contact the maintainer (@yariks5s).

Contibutions

You also have a chance to contribute to this project. Please create a pull request containing your ideas or solutions. All contributions are welcome.

Todo list (can be extended by anyone):

  • Create the Breaker Block indicator [Maybe other indicators will be useful]
  • Create every indicator output as classes
  • Create a possibility to return non-visual (numeric) data
  • Add tests for this
  • Create a possibility to enable/disable indicators
  • Connect the bot to database (probably local), to store the user_ids and their preferences
  • Possibility to calculate indicators only on demand
  • Add tests for this
  • Create a logic to find predictable movements, based on the created indicators
  • Tune this logic properly
  • Add tests for this
  • Don't count very small FVGs
  • Impove handling the cases where some indicators are not shown (Covered FVGs in text representation)
  • Tune order block detection - Important
  • Keep previous 1000 candles in history and send signal based on the extended analysis (probably multi-frame) - done in another way (merging requests responses)
  • Create a logic regarding pinging users about signals
  • Add tests for this
  • Check if a requested cryptocurrency pair exists on a Bybit (suggest the correct name using Levenstein distance) - not important
  • Refactor obsolete function for 1k candles, put the logic into the basic function
  • Create a signal finding pipeline
  • Tune the signal finding logic
  • Create an adequate UI for managing signals
  • Prevent from creating a multiple signal queries for the same currency
  • Possibility to choose whether we need a chart along with the signal using query setting
  • Clarify the exception message for this use-case: '/create_signal ARBUSDT 1 2'
  • Possibility to apply only chosen indicators to signals
  • Limit frequency of signals and amount of signals to not violate the API limits
  • Testing system (backtesting)
  • Abilty to toggle legend
  • Ability to toggle volumes
  • Optimize the process of normalizing the liquidity levels if no settings are specified
  • Add a test for the task above (automatically create the right amount of liquidity levels if setting is not specified)
  • Logging system
  • Disable info logging for training
  • Liquidity pools implementation
  • Tests for liquidity pools
  • Ability to show historical (not real-time) data
  • Proper exceptions for client
  • Fix this: '/history BTCUSDT 48 1h 0.05 17000000000'
  • Possibility to open multiple signal management windows
  • Disclaimer in /help about temporary debugging commands
  • Shell script to launch ClickHouse from proper directory
  • Implement testing for proper backtesting
  • Multi language support
  • Allow users to set custom indicator parameters (e.g., ATR period, FVG min size)
  • Add portfolio tracking: Let users track their holdings and PnL
  • Add a web dashboard for visualizing signals and statistics outside Telegram
  • Add a “strategy marketplace” where users can share and use custom signal strategies
  • Implement a notification system for major market events (e.g., high volatility, news)
  • Add onboarding/tutorial messages for new users
  • Provide inline help for each command (e.g., /help chart)
  • Add signal history for every user (single database with signals containing who requested the signal)
  • Allow users to export their signal history (CSV, Excel, etc.)
  • Add some optimizations techiques (if two users requested the same signal at the same time, calculate it only once)
  • Add dark/light mode for charts
  • Fix this: "You selected: ..., dark_mode"
  • Fix instrument markings for dark mode on the plot
  • Implement rate limiting and abuse prevention
  • Make the system that will set the right logic coefficients based on backtesting
  • If possible, make the bot to continue sending signals after it is restarted
  • Integrate a neural network to the predictions system
  • Prettify the bot and make it easy to use

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published