i Short answer
An API (application programming interface) lets your own software connect to a broker or data provider to fetch prices, place orders and manage positions automatically, for example from Python. Some brokers offer APIs, often alongside MetaTrader’s own automation. Code mistakes can be expensive, so build limits into the program: in the worked example, a script capped at 1% of R50,000 per trade and 3% per day cannot lose more than R1,500 in a day before it stops. Protect API keys like passwords.
📋 ON THIS PAGE
1. What can a trading API do?
| Function | Example use |
|---|---|
| Market data | Download prices for analysis |
| Order placement | Send orders from your own code |
| Account information | Read balances and positions |
| Order management | Modify or close positions automatically |
Automation more broadly is covered in trading bots, and hosting in VPS hosting.
2. How should an automated system limit risk? A worked example
Assumptions (hypothetical example): a R50,000 account traded by a script with a 1% per-trade limit and a 3% daily loss limit, after which it stops trading for the day.
| Limit | Working | Rand amount |
|---|---|---|
| Per trade | R50,000 × 1% | R500 |
| Daily stop | R50,000 × 3% | R1,500 |
| Trades before stopping on losses | R1,500 ÷ R500 | 3 |
Hard limits in code stop a bug or a bad day from spiralling. Daily limits are covered by the maximum daily loss calculator.

⬇ Download this summary (PNG) · Free to share with the credit “Source: TradeAnswers” (CC BY 4.0).
3. How do you keep API trading safe?
- Store keys securely, never in shared code
- Give keys only the permissions needed; disable withdrawals
- Test on a demo environment first
- Log every order the program sends
- Add hard risk limits and a kill switch
Account security is covered in protecting your trading account, and testing in backtesting.
4. Are there regulatory limits?
Using an API for your own account with an FSCA-authorised broker is allowed (FSCA FSP search); running other people’s money through your code may require authorisation. Check brokers on the FSCA FSP search, and see trading on behalf of someone else (CME Group, technical analysis course).
The kinds of trading API you may meet
| Type | What it is | Who it suits |
|---|---|---|
| MetaTrader (MQL4 or MQL5) | Code that runs inside the trading platform | Retail traders automating on an MT4 or MT5 account |
| Broker REST or WebSocket API | Web-style connection your own program calls | Programmers building their own tools, where the broker offers it |
| FIX protocol | Industry standard for institutional order routing | Funds and professional firms; rarely offered to retail accounts |
Whichever you use, test on a demo account first, and keep the risk limits in the code, not only in your head.
Testing an automated system before it trades live
- Run it on a demo account for long enough to see it handle a range of market conditions.
- Build in a kill switch: a daily loss limit after which it stops and closes positions.
- Log every order it sends and every response from the broker.
- Start live at the smallest size and compare results with the demo period.
- Check what happens if the connection drops mid-trade.
Rate limits and error handling
Broker APIs usually limit how many requests a program can send in a period, and reject orders that break rules such as minimum size. A program that does not handle these responses can stall or retry in a loop. Read the broker’s API limits and make the code stop and alert you when an order is rejected, rather than retrying blindly.
★ Why It Matters
An API turns your trading rules into code that acts without hesitation, including when the code is wrong. Hard risk limits, restricted keys and demo testing are what make that safe.
✕ Common mistakes
- Running untested code live. Test on demo first.
- API keys with withdrawal rights. Restrict permissions.
- No daily loss limit in code. Add a kill switch.
- Sharing keys in code repositories. Store them securely.
Key Takeaways
- Create API keys with trading-only permissions.
- Store keys in environment variables, not code.
- Test on demo first.
- Add a kill switch to your script.
Frequently asked follow-up questions
What is a trading API?
An interface that lets your own software connect to a broker to fetch data and place, change or close orders.
Do South African brokers offer APIs?
Some do, usually alongside MetaTrader automation; ask the broker which interfaces it supports and on which account types.
Do I need to code to use an API?
Yes, or use a tool someone else has built on it. MetaTrader expert advisors are the most common way retail traders automate without a separate API.
Is API trading risky?
Code errors can place repeated or oversized orders quickly, so build in limits, test on demo and log everything the system does.
Can I manage others’ money through an API?
Trading other people’s money, by any means, is a financial service that may need FSCA authorisation.
