Modeling three markets (BR / US / Crypto) with one rebalancing engine
Part of a series on building Balance , a portfolio rebalancing app, as a solo developer. Balance started as a Brazilian-only app: B3 tickers, prices in reais, Brazilian income tax. Then came US stocks. Then crypto. The naïve path would have been three apps glued together — three price fetchers, three sets of forms, three rebalancing engines. Instead, the whole thing pivots on a single field:…
The Balance portfolio rebalancing app, developed by a single developer, unifies three distinct markets - Brazil, the US, and cryptocurrencies - using a single rebalancing engine. The app simplifies the development process by sharing most of its domain logic across all markets.
The core of the application lies in a single field: `market`. This field determines all market-specific variations. The rebalancing engine remains untouched, while price fetching, form validation, quantity precision, and display renderings adapt based on the selected market.
The three markets differ primarily in four areas: price source, currency symbol, tax rules, and quantity precision. The price fetching varies depending on the market, utilizing BRAPI, Yahoo, or Binance for cryptocurrency prices. Currency symbols are R$ for Brazil, $ for the US, and none for crypto. Tax rules and quantity precision differ between markets as well.
The rebalancing engine checks the market only when handling whole-share assumptions in cryptocurrency trading. The rest of the engine operates uniformly, ensuring that all markets share the same rebalancing logic.
In short, Balance's multi-market functionality arises from a single variable, `market`, which controls price routing, market-aware forms, quantity precision, and display rendering. The rebalancing engine, however, remains a consistent, shared component across all markets.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.