The balanced strategy estimates a price for the two tokens relative to each other; that's the centerPrice. Anytime you place an order to sell with a spread, you are effectively selling at a better price (in the bot's favor) than what is estimated. Conversely, if you buy with a spread you are buying at a better price (in the bot's favor) than what is estimated.
However, when someone buys or sells to you it is an indicator of the market's relative demand for the two assets. Therefore, the act of having your order get converted to a trade reveals information by the market. The bot incorporates this new information by using the asset balances to estimate a new centerPrice.
The bot knows the maximum amount it can support to buy/sell w.r.t. it's knowledge of the current market demand. It does this by predicting the effect of a trade on the future centerPrice and factors that in to the maximum amount it can support. This is the amount at which if the market traded with the bot on both sides (buy followed by sell or sell followed by buy) then the bot would end up with a net 0 token gain (not accounting for negligible fees on the Stellar network).
Any amount lower than the maximum amount will result in a gain by the bot if the market were to both buy and sell. This gain comes from the
SPREAD and the
AMOUNT_SPREAD which allows you to define smaller amounts to trade compared to the maximum amount supported at each spread level. If the market were to consume a full order level placed by the bot then the bot has on average bought or sold at a price that is better by a percentage equal to
AMOUNT_SPREAD compared to it's estimate of the centerPrice (in the bot's favor).