← Back to Blog
TUTORIALS

DCA Bot in Python: Systematic Accumulation on LMEX Exchange

June 11, 2026 · 7 min read · LMEX.AI

Dollar cost averaging is the boring strategy that beats most active trading. Buy a fixed dollar amount on a fixed schedule, forever. The implementation is simple, the math is in your favour, and the psychological benefit might be bigger than the financial one.


This article walks through what DCA is, why it works, how to build a DCA bot for LMEX in Python, and the variants that are actually worth implementing.


Why DCA works


The textbook argument: buying a fixed dollar amount at varying prices means you buy more units when price is low and fewer when price is high. The average purchase price ends up below the time-averaged market price, because you're naturally weighted toward the lows.


This is mathematically true. It's also not the main reason DCA works.


The real reason: DCA removes timing decisions from the equation. The biggest source of underperformance for most retail traders isn't poor strategy — it's emotionally bad timing. Buying tops in greed, selling bottoms in fear, sitting in cash while the market grinds higher. DCA eliminates all of that. The bot buys on schedule regardless of how price feels.


For long-term accumulation of an asset you believe in, DCA outperforms 80%+ of attempts at active timing. Even for short-term traders, having a steady accumulation strategy alongside discretionary trading smooths the overall equity curve.


The basic DCA bot


The minimum viable DCA bot for LMEX:


import ccxt
import os
from datetime import datetime

exchange = ccxt.lmex({
    'apiKey': os.getenv('LMEX_API_KEY'),
    'secret': os.getenv('LMEX_API_SECRET'),
})

def execute_dca(symbol='BTC-PERP', usd_amount=100):
    ticker = exchange.fetch_ticker(symbol)
    current_price = ticker['last']
    
    qty = usd_amount / current_price
    qty = exchange.amount_to_precision(symbol, qty)
    
    order = exchange.create_order(symbol, 'market', 'buy', qty)
    
    print(f"{datetime.now().isoformat()} | Bought {qty} {symbol} @ {current_price}")
    return order

if __name__ == '__main__':
    execute_dca('BTC-PERP', 100)

Schedule this with cron to run weekly:


0 9 * * 1 cd /path/to/bot && /usr/local/bin/python3 dca_bot.py >> dca.log 2>&1

That's a complete DCA bot. Buys \$100 of BTC-PERP every Monday at 9am. Set it and forget it.


Variants worth considering


The basic bot works fine. Three variants add real value:


**Volatility-weighted DCA.** Buy more when volatility is elevated (signal of fear/opportunity), less when calm. The intuition: assets are more frequently mispriced during volatility spikes.


def execute_volatility_dca(symbol='BTC-PERP', base_amount=100):
    candles = exchange.fetch_ohlcv(symbol, '1d', limit=30)
    closes = [c[4] for c in candles]
    
    # Calculate 30-day realized vol
    returns = [(closes[i] - closes[i-1]) / closes[i-1] for i in range(1, len(closes))]
    avg_return = sum(returns) / len(returns)
    variance = sum((r - avg_return)**2 for r in returns) / len(returns)
    vol = variance ** 0.5
    
    # Recent week vol vs 30-day
    recent_returns = returns[-7:]
    recent_avg = sum(recent_returns) / len(recent_returns)
    recent_var = sum((r - recent_avg)**2 for r in recent_returns) / len(recent_returns)
    recent_vol = recent_var ** 0.5
    
    # Multiplier: more buy when recent vol > avg vol
    multiplier = min(2.0, max(0.5, recent_vol / vol))
    amount = base_amount * multiplier
    
    return execute_dca(symbol, amount)

This buys \$50-200 instead of always \$100, depending on conditions. Backtests on BTC suggest 15-25% improvement in average cost vs flat DCA.


**Indicator-gated DCA.** Skip the buy if some bearish signal is firing. Common gates: RSI above 80 (extreme overbought), price above 200-day MA by more than 30% (extreme stretch).


The skipped buys accumulate as cash and get deployed on the next eligible signal. This is a small modification but reduces drawdowns meaningfully during bubble tops.


**Layered DCA.** Run multiple DCA bots simultaneously on different time horizons — weekly, monthly, quarterly. Different cycles, smoother overall accumulation. The quarterly bot buys larger amounts less often; weekly buys small amounts more often. Combined, they average down through any market condition.


What goes wrong


DCA failure modes are different from active trading failures:


**Cancelling during drawdowns.** The whole point of DCA is to keep buying when scary. Traders who turn off the bot at the bottom defeat the strategy entirely. Build resistance to cancellation: hard-code the bot to run weekly without manual approval, separate the running of the bot from any decision-making about market conditions.


**Over-allocating to one asset.** A BTC DCA bot running for 3 years builds significant BTC exposure. If that's intended, fine. If not, set a hard cap on total accumulated position and pause when reached.


**Ignoring transaction costs.** On LMEX, market buy fees are ~0.06%. A \$100 buy costs ~\$0.06 in fees. Daily DCA at \$100 means \$22 in annual fees vs \$1.10 for weekly DCA. Weekly or monthly cadence is more cost-efficient.


**Treating it as a trading strategy.** DCA is an accumulation strategy. It doesn't tell you when to sell. Pair it with a separate exit strategy (target price, rebalancing rule) or accept that you're holding indefinitely.


Sizing and tuning


The right DCA amount depends on your overall financial picture, not market conditions. A common heuristic:


  • Total annual allocation to crypto: X% of disposable income
  • Split across N positions if running multiple DCAs
  • Per-position weekly amount: (X% × annual income) / 52 / N

  • For someone with \$50,000 disposable income, 10% crypto allocation, 3 DCA positions:

  • Annual crypto allocation: \$5,000
  • Weekly per position: \$5,000 / 52 / 3 ≈ \$32

  • That's small per transaction but compounds. \$32/week for 5 years = \$8,320 deployed, building meaningful exposure.


    Frequently Asked Questions


    Q: How often should the bot run?

    Weekly is the sweet spot for most use cases. Daily multiplies fees without meaningful accumulation benefit. Monthly is fine for very long-term holders. Quarterly works for tax-efficient strategies but misses smoothing benefits.


    Q: Does DCA work for perpetual futures?

    Yes, but watch out for funding rate costs. A long perp position pays funding when rates are positive (most of the time in bull markets). Over years, funding can eat 5-20% of returns. For pure accumulation, spot is preferable. For leveraged accumulation, perps make sense but factor funding into your sizing.


    Q: Should I DCA into multiple coins or just one?

    Concentrate based on conviction. BTC and ETH have multi-cycle track records; smaller alts have higher upside but more failure risk. A reasonable split: 60% BTC, 30% ETH, 10% across a few altcoins. Adjust based on your own thesis.


    Q: When do I stop DCA?

    Either at a hard time horizon (e.g., 10 years) or at a target allocation. Without a stopping rule, DCA can over-concentrate your portfolio in one asset as it appreciates. Set an explicit exit framework before starting.


    Related Articles


    → Kelly Criterion: Mathematically Optimal Position Sizing for LMEX Traders
    → Backtesting Your LMEX Trading Bot in Python: A Practical Guide
    → Portfolio Risk Management for Algorithmic Traders on LMEX
    ← All ArticlesBuild a Bot →