Automated ETF Portfolio Rebalancing: How We Built a Bot for Tinkoff Invest
Automated portfolio rebalancing: the bot monitors target weights and trades for you.
Say you have a portfolio of four ETFs: TMOS, TBRU, TRUR, and cash in rubles. 25% each. The market moves — TMOS grows to 32%, TBRU drops to 18%. Classic theory says: sell what's up, buy what's down. Rebalancing.
The problem is doing it manually is painful. Especially with multiple accounts, margin strategies, and hourly rebalancing. We built a bot that does it automatically.
TIEBB (Tinkoff Invest ETF Balancer Bot) is an open-source TypeScript bot that connects to the Tinkoff Invest API and automatically maintains target portfolio allocation. Four balancing modes, margin trading, multi-account, dry-run for testing.
TL;DR
- Open-source (Apache 2.0) bot for automated ETF portfolio rebalancing
- 4 balancing modes: manual, market cap, AUM, decorrelation
- Margin trading up to 4x with risk management
- Multi-account: unlimited accounts with individual settings
- TypeScript + Bun — fast, typed, painless
- Dry-run mode — calculates orders without executing
Why Rebalancing Matters

The idea is simple: you define target weights for assets in your portfolio (e.g., 25% TMOS, 25% TBRU, 25% TRUR, 25% RUB). Over time, the market moves and actual weights drift from targets. Rebalancing means returning to target weights by selling winners and buying losers.
Why it matters:
- Risk control — if one asset grows to 60% of your portfolio, you're overexposed
- Systematic profit-taking — you automatically sell what's grown
- Buying dips — you automatically buy what's dropped
- Discipline — no emotions, just the algorithm
How the Bot Works
Main Loop
1. Check if MOEX is open
2. Fetch current positions and prices
3. Calculate desired allocation (4 modes)
4. Generate orders: sells first, then buys
5. Execute with market orders
6. Sleep for BALANCE_INTERVAL, repeat
Four Balancing Modes

1. Manual — fixed weights from config (e.g., 25/25/25/25)
2. Market Cap — weights proportional to each fund's market capitalization
3. AUM — weights proportional to Assets Under Management
4. Decorrelation — the most interesting one:
decorrelationPct = (marketCap - AUM) / AUM * 100
metric = max_decorrelationPct - individual_decorrelationPct
weight = metric / sum(metrics) * 100
Finds instruments where market cap differs from AUM and balances between these metrics.
Smart Order Generation
The bot sells first, then buys. This frees up capital for purchases — no need to keep a cash reserve. All instruments are traded in lots with proper rounding.
Advanced Features
- Margin trading up to 4x with auto-deleverage before market close
- Multi-account — unlimited accounts, each with its own strategy
- Min profit threshold — don't sell if profit is below threshold
- Dry-run mode — calculate everything, execute nothing
- Diff-based adjustment — weights adapt based on changes since last rebalance
Quick Start
git clone https://github.com/suenot/tinkoff-invest-etf-balancer-bot.git
cd tinkoff-invest-etf-balancer-bot
bun install
cp .env-example .env && cp CONFIG.example.json CONFIG.json
bun run start
Try It
- Source code: github.com/suenot/tinkoff-invest-etf-balancer-bot
- License: Apache 2.0
Links:
- GitHub: github.com/suenot/tinkoff-invest-etf-balancer-bot
- Tinkoff Invest API: invest-api.tinkoff.ru
Citation
@software{soloviov2026etfbalancer,
author = {Soloviov, Eugen},
title = {Automated ETF Portfolio Rebalancing Bot for Tinkoff Invest},
year = {2026},
url = {https://marketmaker.cc/en/blog/post/etf-balancer-bot-tinkoff},
description = {Open-source TypeScript bot for automated ETF portfolio rebalancing on Tinkoff Invest.}
}
MarketMaker.cc Team
Investigación Cuantitativa y Estrategia