Why a basket drifts, and what bringing it back means
Say you want 40% of a basket in BTC, 30% in ETH, 20% in SOL and 10% in cash. The day you buy it, those are the real shares. A week later ETH has moved more than the others. Now ETH is a bigger slice than you asked for, and the rest are smaller. Nothing was traded. The mix changed because the prices did.
Rebalancing is the act of trading the mix back. The bot works out what each coin's slice should be worth at today's total, sells the coins sitting above that figure, and uses the proceeds to buy the coins sitting below it. Sells always go first, because they are what pay for the buys. After the pass, every share is close to its target again.