Skip to content

Repository files navigation

NexisQ — Smart analysis. Better trades.

NexisQ

AI-powered execution audit for crypto-perp trades — right inside Telegram.

Python aiogram License: MIT Code style: ruff CI

English · Русский


What is this

NexisQ doesn't try to predict the market. It audits the quality of execution of a trade idea you already have — timing, risk, structure, discipline.

You describe a trade in plain language ("BTC long 10x on 15m, market entry, no stop, risk 5%, deposit 1000"). The bot extracts a structured idea, asking follow-up questions with inline buttons for anything missing, pulls a live market snapshot from BingX, computes technical indicators across two timeframes, and runs it all through an LLM that returns a sober, plain-text breakdown: is the entry sane, where are the weak spots, is the risk adequate, is it too late to enter.

Access is gated behind a crypto subscription paid via Crypto Pay (@CryptoBot). The whole thing runs on long polling — no domain, no webhook, no TLS — so it deploys as a single Docker container.

Demo

NexisQ demo — from a trade idea to an AI verdict

Sped up · full flow: idea → follow-up questions → market snapshot → AI verdict

Features

  • 🧠 Execution audit, not signals — evaluates your idea instead of inventing one.
  • 💬 Natural-language input — an LLM parses a free-form message into a structured trade; missing fields are collected with inline keyboards.
  • 📊 Real market context — live BingX klines, funding rate, open interest and 24h ticker, with RSI / EMA / SMA / ATR / swing levels / volume trend computed on both the working and a higher timeframe.
  • 🔌 Pluggable LLM — Anthropic or OpenAI out of the box; any OpenAI-compatible gateway (e.g. OpenRouter) via a custom base URL.
  • 💳 Crypto subscriptions — Crypto Pay invoices with idempotent activation (background reconcile + a manual "I paid" button, no webhook needed).
  • ⚙️ Live-editable from the bot — texts, the AI instruction, price, currency, duration and model names are changed via /texts with no restart.
  • 🛟 Operational care — admin alerts on AI/exchange failures (anti-spam), a daily stats digest, throttling, a global error handler and graceful startup without an AI key.
  • 🧪 Tested core — pure indicator functions covered by unit tests; SQLite with WAL and file-based migrations.

How it works

flowchart TD
    A[User sends a trade idea<br/>as free-form text] --> B[LLM parses it into<br/>a structured TradeIdea]
    B --> C{All fields<br/>filled?}
    C -->|No| D[Ask the missing field<br/>via inline keyboard]
    D --> C
    C -->|Yes| E[Fetch BingX snapshot:<br/>klines · funding · OI · ticker]
    E --> F[Compute indicators on<br/>main + higher timeframe]
    F --> G[LLM analyses idea + snapshot]
    G --> H[Plain-text verdict + disclaimer<br/>sent to the user]
    H --> I[(Saved to<br/>analysis_history)]
Loading

Two LLM calls per analysis: a cheap model parses the idea from natural language, a stronger model analyses it. Both model names are configurable at runtime. For the full design rationale see docs/ARCHITECTURE.md.

Tech stack

Layer Choice
Language Python 3.12+
Bot framework aiogram 3.x (FSM, routers, middlewares)
LLM Anthropic / OpenAI (pluggable, OpenAI-compatible endpoints)
Market data BingX USDT-M perpetual swap public API
Payments Crypto Pay API (@CryptoBot)
Storage SQLite (aiosqlite, WAL, file-based migrations)
Scheduling APScheduler
Config pydantic-settings (.env)
HTTP httpx (async)
Deploy Docker + docker-compose

Project structure

app/
  main.py          — entrypoint (long polling + APScheduler)
  bot.py           — Bot/Dispatcher factory, middlewares, routers
  config.py        — Settings (pydantic-settings)
  handlers/        — start · subscription · analysis (FSM) · admin · errors
  middlewares/     — db session · subscription gate · throttling
  services/        — analysis pipeline · BingX · indicators · cryptopay · editable …
    ai/            — provider ABC, factory, Anthropic & OpenAI implementations
  db/              — aiosqlite + repositories + SQL migrations
  scheduler/       — background jobs
  utils/           — texts · keyboards · formatting
tests/             — indicator unit tests

A more detailed map lives in docs/ARCHITECTURE.md.

Quick start

Prerequisites

  • Python 3.12+
  • A Telegram bot token from @BotFather
  • A Crypto Pay token from @CryptoBot → Crypto Pay → Create App
  • An API key for your chosen LLM provider (Anthropic or OpenAI)

Run locally

git clone <your-repo-url> nexisq
cd nexisq

python -m venv .venv
# Windows:        .venv\Scripts\activate
# Linux / macOS:  source .venv/bin/activate

pip install -r requirements.txt

cp .env.example .env        # Windows: copy .env.example .env
# edit .env — set BOT_TOKEN, ADMIN_IDS, CRYPTOPAY_TOKEN and your AI key

python -m app.main

In Telegram: send /start, then /grant (admin-only, gives yourself a subscription for testing), then send a trade idea as text.

Run with Docker

docker compose up -d --build

docker-compose.yml reads the same .env and persists the SQLite database to a ./data volume.

Configuration

Configuration is read once from .env (.env.example documents every option). The essentials:

Variable Required Description
BOT_TOKEN Telegram bot token
ADMIN_IDS Comma-separated admin Telegram IDs (111,222)
CRYPTOPAY_TOKEN Crypto Pay API token
AI_PROVIDER anthropic or openai
ANTHROPIC_API_KEY / OPENAI_API_KEY ✅¹ Key for the selected provider
OPENAI_BASE_URL Custom OpenAI-compatible endpoint (e.g. OpenRouter)
SUB_PRICE / SUB_ASSET / SUB_DURATION_DAYS Subscription defaults (editable later in-bot)
BINGX_API_KEY / BINGX_API_SECRET Optional — BingX market data is public

¹ One key, matching AI_PROVIDER.

Subscription price/asset/duration, AI model names, all user-facing texts and the AI instruction itself are editable at runtime via /texts — no restart required. The .env values are just the starting defaults.

Crypto Pay: the token and CRYPTOPAY_BASE_URL must be on the same network. For testing use https://testnet-pay.crypt.bot/api/ with a token from @CryptoTestnetBot.

Bot commands

For users

Command Action
/start Intro, welcome animation, subscribe / greeting
(text) Send a trade idea in plain language to get it analysed

For admins

Command Action
/stats Users / subscriptions / revenue / analyses (all-time, today, 7d)
/grant [days] Give yourself a subscription without paying (testing)
/revoke Remove your own subscription (to test the paywall)
/texts Full editor for messages, the AI instruction and parameters

Tests

pip install -r requirements-dev.txt
pytest -q

The suite covers the pure indicator functions (SMA, EMA, RSI, ATR, swing levels, volume trend, percent change) and runs without any network access.

Disclaimer

NexisQ is an analysis tool, not financial advice. Crypto-perp trading carries substantial risk of loss. The bot evaluates the execution quality of an idea you provide — it does not predict prices and does not guarantee outcomes. Every decision is yours.

License

Released under the MIT License.

About

AI execution-audit Telegram bot for crypto-perp trades — aiogram 3.x, BingX, Crypto Pay, pluggable LLM (Anthropic/OpenAI)

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages