Open source · MIT Python 3.11+ Long & Short Self-hosted

Algorithmic crypto futures trading, with the safety rails built in.

CROT — CryptoRoboTrading — is an open-source Python bot for USDT-M perpetual futures. It keeps stop-losses on the exchange itself, enforces strict margin caps, and writes a complete audit trail of every decision. Free to use, configurable down to every threshold, and honest about the risks.

Trades on HTX today · built on CCXT, designed to grow across exchanges

Futures trading involves substantial risk of loss. This is software, not financial advice.

What it is

A standalone trading application — not another exchange template

If you have only used the bot constructors built into exchanges, think of this as the next level of control. Instead of picking a grid template and a few sliders, you run a full trading program on your own machine, connected to your exchange account (HTX today) through official API keys. Everything it does is visible: the source code, the configuration, and a line-by-line log of every trade decision.

Your infrastructure

Runs on your PC or a small VPS. Your API keys stay in a local file on your machine — they are never uploaded anywhere, never logged, and never committed to version control. Funds remain in your own exchange account at all times.

Your rules

Every threshold, filter, and safety limit is a named setting in one plain-text file — over 300 of them, each with a sensible default. Change the strategy's behavior without touching a line of code, separately for long and short sides if you want.

Your data

The bot writes a complete record of what it saw and why it acted: trade events, signal analytics, diagnostics, account PnL, macro context. Analysis scripts are included so you can evaluate the strategy on your own results — not on marketing claims.

How it compares to exchange bot constructors

Exchange constructors
(grid / DCA templates)
This bot
(standalone, open source)
Strategy logic Fixed templates, a few sliders Full multi-layer strategy: trend, pullback, trigger, quality gates, ranking
Tunable parameters Typically 5–15 300+ documented settings, all with working defaults
Source code Closed — you trust the exchange's black box Open source (MIT) — audit every line before you fund it
Stop-loss Varies; often software-side or absent Reduce-only hard stop placed on the exchange from entry — active even if your server dies
Exchange lock-in Total — the bot lives and dies with that exchange The strategy and risk engine are yours; HTX today, built on CCXT to add exchanges
Records & analytics Summary numbers in a dashboard Full CSV/JSONL audit trail plus included research scripts
Cost Often subscription or profit share Free. You pay only normal exchange fees
What you provide Nothing — it runs on their servers A machine that stays on (any PC or a ~$5/mo VPS) and basic terminal comfort

The last row is the honest trade-off: you host it yourself. In exchange, you get full control, full transparency, and zero recurring fees.

The strategy

A worked base strategy — built to evolve

The current base strategy is EMA Pullback: trade pullbacks in the direction of an established trend. The bot identifies the trend on slow charts, waits for the price to dip against it and start recovering on fast charts, and only then considers an entry. The engineering effort went into everything around that idea — the filters that keep it out of bad trades.

It is a living strategy, not a frozen formula: the bot measures the outcome of every signal, and the rules change when the recorded data says they should — the commit history includes features that were removed because the numbers didn't support them. What never changes is the engine around the strategy: the risk controls, the quality gates, and the audit trail.

Three timeframe layers

Signals are computed on closed candles only — the bot never reacts to a candle that is still forming, which removes a whole class of false signals.

LayerTimeframeEMAsRole
Macro trend1hEMA 48 / 120 Is there a real trend to trade?
Pullback5mEMA 24 / 72 Did price pull back and start recovering?
Trigger5mEMA 24 / 72 Is short-term momentum aligned right now?

The same logic runs symmetrically in both directions: the long profile buys pullbacks in uptrends, the short profile sells rallies in downtrends. Both run in one process, share market data, and never open opposite positions on the same coin.

Seven quality gates before any entry

An aligned trend is necessary but not sufficient. Before placing a single order, a candidate must clear a pipeline of independent checks:

  1. Choppiness filter — skips coins moving sideways in noise, where trend logic loses money.
  2. Volume confirmation — recent volume must support the move; suspicious single-candle spikes against the position block the entry.
  3. Volume profile — an adverse breakout through the value area is treated as reversal risk, not opportunity.
  4. Relative strength vs BTC — the coin must actually move on its own, not just drift with the market.
  5. BTC 30-minute filter — no longs while Bitcoin is falling hard, no shorts while it is squeezing up.
  6. Cross-exchange price check — if HTX is priced too far above the reference exchange, a long is blocked (and mirrored for shorts).
  7. Composite score ranking — surviving candidates are scored and ranked; only the strongest get capital, and negative indicators multiply the score down rather than being averaged away.

Patient entries

Entries use a ladder of post-only limit orders placed below the market (above, for shorts) — the bot waits for the price to come to it instead of chasing, and earns maker fees rather than paying taker fees.

Throttled by design

Hard limits cap how many new positions can open per signal and per hour. When too many coins signal at once — a classic sign of a market-wide move rather than genuine setups — crowded-market rules tighten every threshold automatically.

Strictly limited averaging

Adding to a losing position is the way most bots die. Here averaging is capped at two stages, requires a minimum drawdown scaled by volatility, a minimum time interval, a fresh recovery signal, and respect for all margin caps — or it simply doesn't happen.

Risk controls

Risk management is the core of the design, not an afterthought

Every layer of the exit and sizing logic assumes things will go wrong: the trade, the network, or the server. The protections below are on by default.

Stop-loss on the exchange itself

The moment a position opens, a reduce-only hard stop-loss order is placed on HTX, not in the bot's memory. If your server crashes, your internet drops, or the bot is stopped — the stop order is still there, enforced by the exchange. It can widen slightly with measured volatility (ATR), but never beyond a configured cap.

Hard margin caps

Position size is budgeted from equity (2% per position by default), each position's margin is capped at 3% of the account, and total margin across all positions at 50%. A minimum quote reserve is always kept untouched. No single trade — and no cluster of trades — can quietly take over the account.

Layered take-profit

Profits are taken through an adaptive reduce-only exit ladder rather than one all-or-nothing target. A trailing runner can let part of a winning position ride a strong trend, while the rest banks gains early.

Breakeven & time exits

A position that goes nowhere is a risk, not an asset. After a configured holding time the bot moves to exit at breakeven (fees included), and time-based exits prevent stale positions from accumulating indefinitely.

Macro regime awareness

A gold/BTC RSI overlay classifies the broad market regime. When crypto underperforms a defensive asset or a deleveraging phase is detected, the bot cuts budgets, disables averaging, and accelerates exits — automatically, before individual trades feel it.

Cross-exchange sanity check

A second exchange's order book (MEXC) serves as an independent price reference. Abnormal premiums, discounts, or one-minute divergences between exchanges block entries and can send a symbol into cooldown — cheap insurance against localized price anomalies.

Configuration

Over 300 parameters. Zero code changes.

The entire strategy is driven by one plain-text file. Every filter, threshold, cap, and timing value is a named setting with a working default — you can run the bot without changing anything, or reshape its behavior completely without opening the source code.

  • One file, human-readable. Settings live in .env — the same simple NAME=value format used across the industry, grouped and commented.
  • Different rules for long and short. Any setting can be overridden per side with a LONG_ or SHORT_ prefix — for example, a tighter budget for shorts than for longs.
  • No silent configuration. At every startup the bot writes its complete effective configuration — all 380+ resolved values — to a snapshot file, with API keys omitted. You always know exactly what the bot is running with.
  • Conservative out of the box. Defaults follow the launch checklist: small position budgets, strict margin caps, every safety filter enabled.
.env — a small excerpt
# Which sides to trade
BOT_PROFILES=long,short

# Sizing and hard caps
EMA_POSITION_BUDGET_FRACTION=0.02   # 2% of equity per position
EMA_MAX_POSITION_MARGIN_FRACTION=0.03
EMA_MAX_TOTAL_MARGIN_FRACTION=0.50

# Exchange-side protective stop
HARD_STOP_LOSS_PCT=0.02

# Entry quality gates
EMA_CHOP_FILTER_ENABLED=true
EMA_VOLUME_CONFIRMATION_ENABLED=true
ENTRY_MIN_SCORE=0.03

# Per-side override example
SHORT_EMA_POSITION_BUDGET_FRACTION=0.01
Transparency

The bot measures itself — and shows you the data

Most trading tools show you a PnL number and ask you to trust it. This bot records the full context of every decision and ships the tools to analyze that record with real statistical methods.

Complete audit trail

Each profile writes structured CSV/JSONL logs: every trade event, per-cycle statistics, per-signal analytics (scores, filters passed and failed), diagnostics, account PnL over time, macro regime history, and cross-exchange price data. Nothing is hidden in memory.

Built-in research tooling

Included analysis scripts evaluate the strategy on your own trading record: which entry filters actually predict outcomes (tested with Fama-MacBeth cross-sectional regressions), how risk/reward settings perform against realized win rates, and how signals resolve under a triple-barrier framework.

Tested, versioned, open

A pytest suite covers the exchange layer, indicators, exit logic, and configuration parsing — run it in one command before going live. The full history of the strategy's evolution is in the open git log, including the changes that removed features the data didn't support.

Getting started

From zero to a running bot

Four steps. Budget an evening for it: most of the time goes into reading the configuration comments and the launch checklist — which is exactly how it should be.

  1. 1

    Open an HTX futures account

    HTX is the exchange the bot supports today, so you need an HTX account with USDT-M futures enabled. If you don't have one yet, you can register with invite code 6hc25223 — a referral that supports this project at no cost to you. Set the account to cross margin, one-way position mode.

  2. 2

    Create API keys — trading only

    In HTX account settings, create an API key with futures trading permission and withdrawals disabled. The key goes into a local file on your machine and nowhere else.

  3. 3

    Install and configure

    Clone the repository, install dependencies into a virtual environment, and copy the example config:

    terminal
    git clone https://github.com/Lermont/HTX-crypto-bot.git
    cd HTX-crypto-bot
    python -m venv .venv && source .venv/bin/activate
    pip install -r requirements.txt
    cp .env.example .env   # then add your API keys and coin list
  4. 4

    Verify, then launch small

    Run the test suite, keep the default conservative caps, and start with budgets you are comfortable watching closely for the first days:

    terminal
    python -m pytest -q     # all tests should pass
    python bot.py           # runs both long and short profiles

    The repository includes a full pre-launch checklist covering leverage verification, margin mode, and safe first-run budgets. Read it.

FAQ

Straight answers

Will this bot make me money?

No one can promise that, and we won't. The strategy is built to control downside first — hard stop-losses, margin caps, throttled entries — and to document every decision it makes so you can judge it on real data. Markets change, and any strategy can have losing periods. Start with small budgets, review the logs, and scale only when the numbers earn your trust.

Do I need to know how to program?

Not to run it. The entire configuration lives in one plain-text file (.env) with commented, human-readable settings — no code changes are needed to adjust the strategy. You should be comfortable with basic terminal commands (copying a file, running python bot.py) and editing a text file. If you have ever set up a grid bot inside an exchange, the concepts here will feel familiar — just with far more control.

Where does the bot run?

On any machine you control with Python 3.11 or newer — your home PC, a mini-PC, or a small cloud VPS (a $5/month instance is plenty). Because it trades continuously, most users run it on an always-on server. A watchdog script is included to restart the bot if it ever stops. Critically, the hard stop-loss is placed on the exchange itself, so your downside protection stays active even if your server goes offline.

Are my funds and API keys safe?

Your funds never leave your own HTX account — the bot only sends signed trading orders through the official API. API keys are stored in a local .env file on your machine and are excluded from logs, config snapshots, and version control. Create API keys with trading permission only and withdrawals disabled: even in the worst case, a leaked key cannot move funds out of your account.

What does it cost?

Nothing. The bot is free and open-source under the MIT License — no subscription, no profit share, no license tier. Your only costs are the exchange's normal trading fees and whatever you pay for a server, if you use one.

Which exchanges does it support?

HTX is the supported exchange today, trading USDT-M perpetual futures. The bot is built on CCXT — the industry-standard exchange connectivity library — and already uses a second exchange (MEXC) as an independent price reference, so extending to additional exchanges is a planned evolution of the same engine, not a rewrite. That is also why the project is called CROT rather than anything exchange-specific.

Is the strategy set in stone?

No, and that is deliberate. EMA Pullback is the current base strategy, but the bot records the outcome of every signal and ships the analysis tools to test what actually works. The strategy evolves with that evidence — filters that measurably help are kept, features the data doesn't support get removed. What stays constant is the engine around it: the risk controls, the quality gates, and the audit trail.

How is this different from the bots built into exchanges?

Exchange bot constructors offer a handful of templates (grid, DCA) with a few sliders. This is a complete, standalone strategy engine: a multi-timeframe trend model, seven layers of entry quality gates, exchange-side stop-losses, macro regime detection, cross-exchange price checks, and over 300 documented parameters. And because the code is open, you can verify exactly what it does — nothing is a black box.

Can I test it before risking real money?

The project ships with a pytest suite covering the exchange layer, indicators, strategy exits, and configuration — run it before any live start. For a live trial, the recommended path is deliberately conservative defaults: 2% of equity per position budget, 3% margin cap per position, and a 50% total margin ceiling. You can lower all of these further and trade a small account first.

Why are the exchange links referral links?

Full disclosure: the HTX and MEXC links on this page carry a referral code. If you register through them, the project receives a commission from the exchange at no extra cost to you — it is the only monetization this free project has. You are, of course, free to register directly instead.

Read the code first. That's the point.

Everything described on this page is verifiable in the repository — the strategy document, the configuration reference, the test suite, and the full commit history. Start there.