Broker Sync¶
Automatically import trades from your brokerage accounts via API instead of manual CSV uploads.
Overview¶
Broker Sync connects directly to your brokerage account and pulls in trade data automatically. This eliminates repetitive CSV exports and keeps your TradeTally dashboard current with minimal manual work.
Currently supported brokers:
- Interactive Brokers (IBKR) -- via Flex Query API
- Charles Schwab -- via OAuth API
- Trading 212 -- via API key and historical orders API
- TradeStation -- via OAuth API
- Alpaca -- via OAuth API for live and paper accounts
Navigate to Settings > Broker Sync to manage your connections.
Prerequisites¶
Before setting up any broker connection, configure this environment variable on your server:
| Variable | Purpose | How to generate |
|---|---|---|
BROKER_ENCRYPTION_KEY | Encrypts stored broker credentials at rest | openssl rand -hex 32 |
Warning
Without BROKER_ENCRYPTION_KEY, broker sync will not function.
Interactive Brokers (IBKR)¶
Setting Up a Flex Query¶
- Log in to the IBKR Client Portal.
- Navigate to Performance & Reports > Flex Queries.
- Create an Activity Flex Query that includes the Trades section.
- Save the query and copy the Query ID.
- Open Configure Flex Web Service and copy the Current Token.
Connecting IBKR to TradeTally¶
- Go to Settings > Broker Sync.
- Click the Interactive Brokers card.
- Enter:
- an optional account label
- your Flex Token
- your Flex Query ID
- optional auto-sync settings
- Click Connect.
Multiple IBKR Accounts¶
You can connect more than one IBKR account. Each connection keeps its own token, query ID, and sync schedule.
Charles Schwab¶
Required Environment Variables¶
| Variable | Purpose |
|---|---|
SCHWAB_CLIENT_ID | Your Schwab API application client ID |
SCHWAB_CLIENT_SECRET | Your Schwab API application client secret |
SCHWAB_REDIRECT_URI | OAuth callback URL, for example https://yourdomain.com/api/broker-sync/connections/schwab/callback |
Note
Schwab requires HTTPS for production callback URLs.
Connecting Schwab¶
- Go to Settings > Broker Sync.
- Click the Charles Schwab card.
- Approve the OAuth request at Schwab.
- Return to TradeTally and confirm the success message.
Only one Schwab connection is allowed per TradeTally account.
Schwab Limitations¶
Former TD Ameritrade Users
The Schwab API only returns trades made natively on Schwab. Historical TD Ameritrade trades are not available through the Schwab API.
Recommended workflow:
- Import a full Schwab CSV once for historical data.
- Use Broker Sync for ongoing native Schwab trades.
- Let duplicate detection skip already-imported rows.
Trading 212¶
Trading 212 connects with an API key pair generated in your Trading 212 account. No Trading 212 application credentials are required in the TradeTally server environment; only the shared BROKER_ENCRYPTION_KEY is needed to encrypt each user's key and secret.
Connecting Trading 212¶
- Open Trading 212 and go to your account settings.
- Create an API key pair with read access to account data and historical orders.
- In TradeTally, go to Settings > Broker Sync.
- Click the Trading 212 card.
- Choose Live account or Demo account to match the API key.
- Enter the API key, API secret, optional account label, sync range, and schedule.
- Click Connect.
You can connect one live account and one demo account. TradeTally validates the credentials against the selected environment before saving them.
Trading 212 Sync Behavior¶
TradeTally retrieves filled historical orders, follows Trading 212's cursor pagination, and matches buy and sell fills into completed or open positions. Fractional quantities are supported. Connection-specific account identifiers are attached to imported trades so the global account filter can distinguish accounts.
Trading 212 Limitations¶
Warning
The Trading 212 Public API is currently in beta and is available only for Invest and Stocks ISA accounts. CFD accounts cannot be synced.
- The historical-orders endpoint is rate limited. Large first-time imports can take several minutes; selecting a shorter initial sync range reduces the number of requests.
- API keys are environment-specific. A live key cannot connect to the demo environment, or vice versa.
- Trading 212 does not currently expose multi-currency accounts fully through the API; account and result values are reported in the primary account currency.
- TradeTally imports actual trade fills and ignores corporate-action history items such as stock splits and distributions.
See the Trading 212 Public API documentation for current availability and API-key instructions.
Sync Features¶
Manual Sync¶
Use Sync Now on any connected broker card to trigger an immediate sync.
Auto-Sync Scheduling¶
Available frequencies:
| Frequency | Description |
|---|---|
| Manual | Manual only |
| Hourly | Every hour |
| Every 4 hours | Four times per day |
| Every 6 hours | Three times per day |
| Every 12 hours | Twice per day |
| Daily | Once per day at your chosen time |
Troubleshooting¶
IBKR Validation Fails¶
- confirm the Flex Token is current
- confirm the Query ID belongs to an Activity Flex Query
- confirm the query includes the Trades section
Schwab OAuth Fails¶
- verify
SCHWAB_CLIENT_ID,SCHWAB_CLIENT_SECRET, andSCHWAB_REDIRECT_URI - verify the callback URL matches the Schwab developer app exactly
- try reconnecting after clearing cookies if you get an OAuth state error
Trading 212 Validation Fails¶
- confirm the key and secret were copied from the same Trading 212 key pair
- confirm Live account or Demo account matches where the key was created
- confirm the API key has account and historical-order read access
- if Trading 212 reports a rate limit, wait for the reset window and test again
Sync Imports Nothing¶
- check the duplicates count in Sync History
- verify the source account actually has trades in the requested period