Unofficial Python API for Quotex broker - A modern, async-first library with comprehensive trading capabilities.
- β Login with email/password
- β Login with SSID (Session ID)
- β Automatic session management
- β Logout functionality
- β WebSocket connection with auto-reconnect
- β Connection state tracking
- β Configurable reconnection strategy
- β Exponential backoff for reconnections
- β Get active balance (Real/Demo)
- β Get all account balances
- β Switch between Real and Demo accounts
- β Real-time balance updates
- β List available binary option assets
- β Filter assets by type (Forex, Crypto, Commodities, etc.)
- β Get real-time payout percentages
- β Asset information and status
- β Place trades (CALL/PUT)
- β Configurable trade amount and expiry
- β Cancel trades before start (if supported)
- β Trade validation and error handling
- β Get list of open trades
- β Get trade history with pagination
- β Date range filtering for history
- β Async trade result tracking with countdown
- β Optional blocking wait for results
- β Real-time trade callbacks
git clone https://github.com/ChipaDevTeam/QuotexAPI.git
cd QuotexAPI
pip install -e .pip install -e ".[dev]"Before running any examples, test your SSID token:
# Get your SSID from browser (F12 > Application > Cookies > ssid)
python examples/test_ssid.pyThis validates your SSID and provides clear feedback if it's expired. See docs/GET_SSID.md for detailed instructions on obtaining your SSID.
import asyncio
from QuotexAPI import QuotexAPI, TradeDirection
async def main():
# Initialize API
api = QuotexAPI(
email="your-email@example.com",
password="your-password"
)
# Connect
profile = await api.connect()
print(f"Connected as: {profile.email}")
# Check balance
balance = await api.get_balance()
print(f"Balance: ${balance.amount}")
# Get available assets
assets = await api.get_assets()
print(f"Available assets: {len(assets)}")
# Place a trade
trade = await api.buy(
asset="EURUSD",
amount=10.0,
direction=TradeDirection.CALL,
expiry=300 # 5 minutes
)
print(f"Trade placed: {trade.order_id}")
# Wait for result
result = await api.wait_for_result(trade.order_id)
print(f"Result: {result.result}, Profit: ${result.profit}")
# Disconnect
await api.disconnect()
asyncio.run(main())from QuotexAPI import QuotexAPI, TradeDirection, AccountType
async def main():
# Automatic connection and disconnection
async with QuotexAPI(email="user@example.com", password="pass") as api:
# Switch to demo account
await api.switch_account(AccountType.DEMO)
# Place and track trade
trade = await api.buy("BTCUSD", 10.0, TradeDirection.PUT, 180)
result = await api.track_trade(trade.order_id)
print(f"Trade completed: {result.result}")
asyncio.run(main())Create a .env file in your project root:
QUOTEX_EMAIL=your-email@example.com
QUOTEX_PASSWORD=your-password
QUOTEX_SSID=your-session-id # Optional
# API Configuration
QUOTEX_API_URL=https://api.quotex.io
QUOTEX_WS_URL=wss://ws.quotex.io
# Connection Settings
QUOTEX_RECONNECT_ENABLED=true
QUOTEX_MAX_RECONNECT_ATTEMPTS=5
QUOTEX_RECONNECT_DELAY=5
# Logging
LOG_LEVEL=INFOfrom QuotexAPI import QuotexAPI, QuotexConfig
config = QuotexConfig(
email="user@example.com",
password="password",
reconnect_enabled=True,
max_reconnect_attempts=3,
log_level="DEBUG"
)
api = QuotexAPI(config=config)await api.connect() # Connect and authenticate
await api.logout() # Logout
api.is_connected # Check connection statusbalance = await api.get_balance() # Get active balance
balances = await api.get_all_balances() # Get all balances
await api.switch_account(AccountType.DEMO) # Switch account# Place trade
trade = await api.buy(
asset="EURUSD",
amount=10.0,
direction=TradeDirection.CALL, # or TradeDirection.PUT
expiry=300
)
# Cancel trade
await api.cancel_trade(order_id)# Get all assets
assets = await api.get_assets()
# Get assets by type
forex_assets = await api.get_assets(AssetType.FOREX)
# Get payout percentage
payout = await api.get_payout("EURUSD")# Get open trades
open_trades = await api.get_open_trades()
# Get trade history
history = await api.get_trade_history(limit=50, offset=0)
# Track trade with callback
async def on_update(order_id, remaining, trade):
print(f"Time remaining: {remaining}s")
result = await api.track_trade(order_id, callback=on_update)
# Wait for result (blocking)
result = await api.wait_for_result(order_id, timeout=600)All data is returned using Pydantic models for type safety:
UserProfile- User account informationBalance- Account balance detailsAsset- Asset/instrument informationTrade- Trade information and statusTradeRequest- Trade placement parameters
Type-safe enumerations:
AccountType.DEMO/AccountType.REALTradeDirection.CALL/TradeDirection.PUTTradeStatus.PENDING/ACTIVE/COMPLETED/CANCELLEDTradeResult.WIN/LOSS/DRAWAssetType.FOREX/CRYPTO/COMMODITIES/INDICES/STOCKSConnectionState.DISCONNECTED/CONNECTING/CONNECTED/RECONNECTING
See the examples directory for comprehensive examples:
basic_usage.py- Simple trading exampleadvanced_usage.py- Advanced features with callbacksmultiple_trades.py- Concurrent trading examplessid_auth.py- Session management example
The project follows clean architecture principles:
QuotexAPI/
βββ __init__.py # Main exports
βββ client.py # High-level API client
βββ config.py # Configuration management
βββ enums.py # Enumerations
βββ exceptions.py # Custom exceptions
βββ models.py # Pydantic models
βββ services/ # Service layer
β βββ base.py # Base service class
β βββ auth.py # Authentication service
β βββ connection.py # WebSocket connection
β βββ account.py # Account management
β βββ instrument.py # Instruments/assets
β βββ trading.py # Trading operations
β βββ data.py # Data and tracking
βββ utils/ # Utilities
βββ logger.py # Logging setup
- Service Layer Pattern: Each domain (auth, trading, etc.) has its own service
- Dependency Injection: Services receive configuration through constructors
- Async/Await: Fully asynchronous for non-blocking operations
- Type Safety: Pydantic models for runtime validation
- Error Handling: Custom exception hierarchy for specific errors
# Run tests
pytest
# Run with coverage
pytest --cov=QuotexAPI --cov-report=html
# Run specific test file
pytest tests/test_client.py# Clone repository
git clone https://github.com/ChipaDevTeam/QuotexAPI.git
cd QuotexAPI
# Install dev dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit installThe project uses:
- Black for code formatting
- isort for import sorting
- flake8 for linting
- mypy for type checking
# Format code
black QuotexAPI/
# Sort imports
isort QuotexAPI/
# Lint
flake8 QuotexAPI/
# Type check
mypy QuotexAPI/- This is an unofficial API and is not affiliated with Quotex
- Use at your own risk
- Always test with a Demo account first
- Be mindful of rate limits
- Keep your credentials secure
- This library is for educational purposes
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please ensure your code:
- Follows the existing code style
- Includes appropriate tests
- Updates documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- Thanks to all contributors
- Inspired by the need for a modern, well-architected Quotex API
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Implement actual API endpoints (currently uses mock data)
- Add WebSocket message parsing
- Add more asset types
- Implement signals/indicators
- Add backtesting capabilities
- Create comprehensive test suite
- Add more examples
- Improve documentation
If you find this project useful, please consider giving it a star!
Made with β€οΈ by ChipaDevTeam