Quotex Demo To Real Code May 2026
client.connect() balance = client.get_balance() state.initial_balance = balance logging.info(f"Started with balance: $balance:.2f (client.account_type)")
import time import logging from quotexapi import Quotex ASSET = "EURUSD_otc" AMOUNT_PERCENT = 2 # % of balance per trade RSI_PERIOD = 14 RSI_OVERSOLD = 30 RSI_OVERBOUGHT = 70 MAX_DAILY_TRADES = 20 STOP_LOSS_DAILY = -5 # -5% stop ========= STATE ========= class TradingState: def init (self): self.daily_trades = 0 self.daily_pnl = 0.0 self.initial_balance = 0.0 quotex demo to real code
Write it as pseudo-code first:
# ---------- SWITCH THIS LINE ---------- client.account_type = "real" # ← "demo" or "real" # -------------------------------------- client
while True: # Risk checks if state.daily_trades >= MAX_DAILY_TRADES: logging.warning("Daily trade limit reached. Sleeping 1h.") time.sleep(3600) continue daily_pnl_percent = (state.daily_pnl / state.initial_balance) * 100 if daily_pnl_percent <= STOP_LOSS_DAILY: logging.error(f"Daily stop loss hit: daily_pnl_percent:.2f%. Stopping.") break # Get current price & history (simplified) prices = client.get_candles(ASSET, 60, 100) # 1-min candles, last 100 rsi = calculate_rsi(prices, RSI_PERIOD) signal = should_trade(rsi) if signal: # Position sizing balance = client.get_balance() amount = balance * (AMOUNT_PERCENT / 100) amount = round(amount, 2) # Place trade trade_id = client.buy(amount, ASSET, signal, 1) # 1 min expiry # Wait for result result = client.check_win(trade_id, timeout=90) # Update state state.daily_trades += 1 if result > 0: profit = amount * 0.80 # 80% payout typical state.daily_pnl += profit logging.info(f"WIN +$profit:.2f") else: state.daily_pnl -= amount logging.info(f"LOSS -$amount:.2f") # Cooldown between trades (avoid over-trading) time.sleep(30) else: time.sleep(10) # Wait for new candle if == " main ": logging.basicConfig(level=logging.INFO) run_live_bot() 4. Critical Changes for Live Code ✅ Add these before going live | Feature | Demo code | Live code | |---------|-----------|-----------| | Position sizing | Fixed $10 | % of balance (1–2%) | | Daily loss limit | None | Hard stop (-5%) | | Max daily trades | None | 20–30 max | | Slippage handling | Ignored | Add 0.5% buffer | | Reconnect logic | None | Exponential backoff | | Logging | Basic | Trade journal (CSV) | | Telegram alerts | No | Yes (for critical stops) | Example slippage adjustment # Live: adjust entry price entry_price = current_price + (0.0001 if signal == "CALL" else -0.0001) 5. Risk Management for Live (Non-negotiable) # Daily loss limit (in %) MAX_DAILY_LOSS_PERCENT = 5 Max consecutive losses MAX_CONSECUTIVE_LOSSES = 3 Max risk per trade (% of balance) RISK_PER_TRADE = 2 Max total risk per day (%) MAX_DAILY_RISK = 10 Critical Changes for Live Code ✅ Add these
state = TradingState() def calculate_rsi(prices, period=14): deltas = [prices[i] - prices[i-1] for i in range(1, len(prices))] gains = [d if d > 0 else 0 for d in deltas] losses = [-d if d < 0 else 0 for d in deltas]