Python trading bot development for broker and exchange APIs
When MetaTrader is not enough: bots that trade through broker and exchange APIs, use data from anywhere, and run on your own server. Written in Python with risk limits, logging and alerts built in, and handed over as clean, documented source.
Mutual NDA before you share your strategy · reply within one working day
1# bot/risk.py: every order passes through here first2from dataclasses import dataclass3 4@dataclass5class RiskLimits:6 max_daily_loss_pct: float = 3.07 max_position_usd: float = 250008 max_open_orders: int = 49 10def allow(order, account, limits: RiskLimits) -> bool:11 day_pnl = account.pnl_today / account.equity_at_open * 10012 if day_pnl <= -limits.max_daily_loss_pct:13 log.warning("daily loss limit reached, order blocked: %s", order)14 return False15 if order.notional_usd > limits.max_position_usd:16 return False17 return len(account.open_orders) < limits.max_open_orders- Starting price
- $500
- Typical delivery
- 1–4 weeks
- Revisions
- 2 revision rounds
- Handover
- Full source code + report
What I build in Python.
- 01
Signal-to-execution bots
Your signal, whether indicator logic, a TradingView alert or a model’s output, turned into sized orders with stops, limits and reconciliation.
- 02
Portfolio and rebalancing bots
Scheduled rebalancing, DCA and allocation rules for stocks, ETFs and crypto, with drift thresholds and cost controls.
- 03
Research and backtesting pipelines
Clean data loading, vectorised or event-driven backtests, and reports you can rerun when the data updates.
- 04
Monitoring, alerts and dashboards
Daily P&L, exposure and error alerts by Telegram or email, and a small web dashboard if you want one.
Brokers and exchanges I work with.
If your broker has a documented API, it can usually be connected. These are the most common.
| Broker / exchange | Markets | Interface |
|---|---|---|
| OANDA | Forex, CFDs | REST v20 + streaming |
| Interactive Brokers | Stocks, futures, options, forex | TWS / Gateway API |
| Alpaca | US stocks, ETFs, crypto | REST + WebSocket |
| Binance, Bybit | Crypto spot and futures | REST + WebSocket |
| cTrader brokers | Forex, CFDs | cTrader Open API |
| MetaTrader 5 brokers | Forex, CFDs, futures | MetaTrader5 Python package |
| Indian brokers (Zerodha, Upstox, Angel One, Fyers, Dhan) | NSE/BSE equity, F&O | Broker APIs |
What separates a script from a bot you can leave running.
- 01
Reconnects and rate limits
Connections drop. The bot resubscribes, backs off when rate-limited, and never sends the same order twice.
- 02
Idempotent orders
Every order carries a client ID, so a retry after a timeout cannot open a second position.
- 03
Reconciliation on start
On every start the bot compares its state with the broker’s positions and orders, and trusts the broker.
- 04
A kill switch
One command, or one Telegram message, flattens positions and stops trading.
- 05
Paper first
Every bot runs against a paper or demo account before it touches live money.
Common questions
Which Python libraries do you use?
pandas and numpy for data, the broker’s official SDK or its REST/WebSocket API directly, asyncio for concurrency, and backtrader, vectorbt or a small custom engine for backtests. No obscure dependencies you will struggle to maintain.
Where does the bot run?
On your VPS or cloud server (DigitalOcean, AWS, Hetzner and similar), set up as a service that restarts on failure and writes logs. I can help you choose and set up the server.
Can a TradingView alert trigger the bot?
Yes. A small webhook receiver checks a secret in the alert, removes duplicates and places the order through your broker’s API. TradingView webhooks need a paid TradingView plan.
Can it use machine learning?
If you have a model, I can deploy it behind the same risk limits. If you want one researched, we treat it as a research project with out-of-sample validation, and I will tell you honestly if it does not beat a simple baseline.
Do you need my API keys?
Only paper or demo keys during development. Live keys stay in your server’s configuration, never in the code and never with me.
Related services.
Tell me the strategy. I’ll tell you what it takes.
Fifteen minutes, no pitch. Mutual NDA before you describe anything you care about. You get an honest view of feasibility, timeline and price, even if the answer is “don’t build this”.