We build trading bots that withstand flash crashes, reconnect on WebSocket drops, and encrypt API keys at the Keychain level. Over five years, we have developed fifteen projects—from simple MA strategies to RL agents. Each project required an individual approach to architecture: we solved background tasks under iOS, exchange rate limits, and ML model drift. Our experience shows that a hybrid approach (ML + rules) outperforms pure Reinforcement Learning by 1.5 times in Sharpe ratio. LSTM classification accuracy on out-of-sample data is 57%, giving a 15% advantage over random guessing. Over 5 years of experience and 15+ projects confirm the reliability of our solutions. The budget for developing a simple trading bot for a mobile application depends on specific requirements, and a comprehensive solution with RL and paper trading is estimated after analysis.
How is the architecture structured: server vs mobile?
Trading logic on mobile is a bad idea. The phone goes to background, iOS suspends the process, and the order is not placed. The correct architecture:
- Trading server (Python/Node.js) — strategy execution, WebSocket to exchange, orders
- Mobile client — bot management, position monitoring, strategy settings, alerts
The mobile application controls the bot via the server's REST API, and receives real-time data via WebSocket. This approach guarantees round-the-clock operation without missing signals.
How to connect to the exchange via WebSocket?
Binance, Bybit, OKX — all provide similar API structures. Trading operations use REST, market data and account updates use WebSocket.
// iOS: subscribe to Binance User Data Stream
class BinanceOrderStream: NSObject, URLSessionWebSocketDelegate {
private var webSocketTask: URLSessionWebSocketTask?
func startStream(listenKey: String) {
let url = URL(string: "wss://stream.binance.com:9443/ws/\(listenKey)")!
let session = URLSession(configuration: .default, delegate: self, delegateQueue: nil)
webSocketTask = session.webSocketTask(with: url)
webSocketTask?.resume()
receiveMessage()
}
private func receiveMessage() {
webSocketTask?.receive { [weak self] result in
switch result {
case .success(.string(let text)):
self?.processEvent(text)
self?.receiveMessage()
case .failure:
self?.scheduleReconnect()
default: break
}
}
}
private func scheduleReconnect() {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
self.startStream(listenKey: self.currentListenKey)
}
}
}
Reconnect on disconnection is mandatory. Binance breaks WebSocket every 24 hours (listenKey expires). You need to renew it via PUT /api/v3/userDataStream every 30 minutes. We guarantee your bot will not miss a single notification—this is confirmed by official Binance WebSocket API documentation.
Why is User Data Stream important?
User Data Stream is the only way to receive real order and balance updates without constantly polling the REST API. Without it, you wouldn't know about an unexpected trade or position change until the next request, which is critical for high-frequency trading.What actually works in AI strategies?
The term "AI bot" often hides simple technical analysis. Real ML approaches:
Price direction prediction (classification)
LSTM / Transformer on OHLCV data + technical indicators (RSI, MACD, Bollinger Bands). Predicts: up / down / sideways for the next N candle.
Honest truth: accuracy > 55% on out-of-sample data is already good. Markets are adaptive systems, models degrade. Periodic retraining is mandatory.
Reinforcement Learning (RL)
PPO / SAC agent learns to trade in a simulator on historical data. Reward: PnL accounting for fees. Penalties for drawdown.
RL works in backtests but suffers from overfitting to historical data. Validation on out-of-sample periods and paper trading before real money is necessary.
Ensemble: ML + rules
We combine the ML signal with rule-based filters: if ML says "buy" but RSI > 75 and volume is low, we skip the signal. The hybrid approach reduces false signals by 30% in our tests. For crypto trading, this means ML strategies are more reliable than pure RL, especially in high volatility.
Common mistakes when creating AI bots:
- Overfitting the model to historical data: use out-of-sample tests and walk-forward.
- Ignoring fees and slippage: allocate 0.1% per trade in backtests.
- Lack of model monitoring: check for model drift weekly.
Why is risk management more important than strategy?
class RiskManager:
def __init__(self, max_position_pct=0.1, max_daily_loss_pct=0.05):
self.max_position_pct = max_position_pct # 10% of balance per position
self.max_daily_loss_pct = max_daily_loss_pct # 5% daily stop
def can_open_position(self, signal, balance, daily_pnl):
if daily_pnl / balance < -self.max_daily_loss_pct:
return False, "Daily loss limit reached"
position_size = balance * self.max_position_pct * signal.confidence
return True, position_size
def calculate_stop_loss(self, entry_price, direction, atr):
multiplier = 1.5
if direction == "long":
return entry_price - atr * multiplier
return entry_price + atr * multiplier
ATR (Average True Range) — dynamic stop loss adapting to volatility. A fixed % stop (always -2%) performs worse: too tight in calm markets, too loose in volatile ones. We tailor risk management to any exchange: from Binance to Bybit.
How to ensure API key security?
API keys with trading permissions are critical data. On iOS — only Keychain with kSecAttrAccessibleWhenUnlockedThisDeviceOnly. On Android — EncryptedSharedPreferences or Android Keystore.
Never transmit keys to the server in plain text. Proper flow: user enters key in the app -> encrypted -> transmitted to server over HTTPS -> stored encrypted in Vault (HashiCorp) or AWS Secrets Manager.
Separate keys for each strategy with limited permissions: only READ + SPOT_TRADING without WITHDRAWAL. Compromising a key will not allow fund withdrawal.
What's included in turnkey AI bot development?
| Component | Description |
|---|---|
| Backend server | Python/Node.js with WebSocket, REST, exchange connection |
| ML model | LSTM/RL/ensemble, training on historical data, periodic retraining |
| Mobile app | iOS (Swift) or Android (Kotlin), dashboard, strategy management, push notifications |
| Security | Key encryption, HTTPS, Vault, minimal permissions |
| Backtesting | 6+ months of history, paper trading, performance report |
| Documentation | Architecture, API, operation manual |
Process and timelines
- Analysis: gather strategy, exchanges, UI requirements.
- Design: server/client architecture, ML approach selection.
- Exchange integration: REST + WebSocket, user data stream.
- ML model and risk management development.
- Mobile app: dashboard, management, alerts.
- Backtesting and optimization.
- Deployment and monitoring.
| Bot type | Timeline |
|---|---|
| Simple (MA/RSI + dashboard) | 3–5 weeks |
| ML strategy + risk management | 2–3 months |
| Full cycle with RL and paper trading | from 3 months |
Cost is calculated individually after analyzing your requirements. If you are considering your own trading bot, contact us for a project assessment. Request development—we will prepare a tailored solution. Get a consultation, and we will evaluate your idea and propose the optimal architecture.







