Download examples/01_basic_candles.py from MandrakBr/qotex: direct link, hf CLI and curl.
- Browser
- Download file 2.92 kB
-
https://huggingface.co/spaces/MandrakBr/qotex/resolve/main/examples/01_basic_candles.py
- Command line
-
hf download hf://spaces/MandrakBr/qotex/examples/01_basic_candles.py
-
curl -L -o 01_basic_candles.py https://huggingface.co/spaces/MandrakBr/qotex/resolve/main/examples/01_basic_candles.py
2.92 kB
| """ | |
| examples/01_basic_candles.py | |
| Exemplo básico: conectar e buscar velas históricas. | |
| """ | |
| import os | |
| import sys | |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) | |
| from quotexpy import QuotexClient | |
| def main(): | |
| # ── Configurar credenciais ── | |
| # Via variáveis de ambiente (recomendado): | |
| # export QUOTEX_EMAIL=seu@email.com | |
| # export QUOTEX_PASSWORD=suasenha | |
| # Ou direto (não recomendado em produção): | |
| email = os.environ.get("QUOTEX_EMAIL", "") | |
| password = os.environ.get("QUOTEX_PASSWORD", "") | |
| if not email: | |
| print("❌ Configure QUOTEX_EMAIL e QUOTEX_PASSWORD como variáveis de ambiente") | |
| return | |
| # ── Criar cliente ── | |
| client = QuotexClient(is_demo=True) | |
| # ── Login ── | |
| print("🔐 Fazendo login...") | |
| ok, msg = client.login(email, password) | |
| if not ok: | |
| print(f"❌ Login falhou: {msg}") | |
| return | |
| print(f"✅ {msg}") | |
| # ── Conectar WebSocket ── | |
| print("🔌 Conectando WebSocket...") | |
| if not client.connect(timeout=15): | |
| print("❌ Falha na conexão WebSocket") | |
| return | |
| print("✅ Conectado!") | |
| # ── Buscar velas ── | |
| print("\n📊 Buscando 100 velas de BTCUSD_otc (1 minuto)...") | |
| candles = client.get_candles("BTCUSD_otc", period=60, count=100) | |
| if candles: | |
| print(f"✅ Recebidas {len(candles)} velas\n") | |
| print(f"{'Data/Hora':20} {'Open':>12} {'High':>12} {'Low':>12} {'Close':>12} {'Dir':>5}") | |
| print("─" * 75) | |
| for c in candles[-10:]: # Mostrar últimas 10 | |
| direction = "🟢" if c.is_bullish else "🔴" | |
| print(f"{str(c.dt):20} {c.open:>12.4f} {c.high:>12.4f} {c.low:>12.4f} {c.close:>12.4f} {direction:>5}") | |
| print(f"\n Último preço: ${candles[-1].close:,.4f}") | |
| else: | |
| print("⚠️ Nenhuma vela recebida") | |
| # ── Buscar ativos disponíveis ── | |
| print("\n📋 Buscando lista de ativos...") | |
| assets = client.get_asset_list(timeout=8) | |
| if assets: | |
| print(f"✅ {len(assets)} ativos disponíveis") | |
| otc = [a for a in assets if a.is_otc and a.open] | |
| print(f" OTC abertos: {len(otc)}") | |
| # Top 5 payout | |
| top5 = sorted(otc, key=lambda a: a.payout, reverse=True)[:5] | |
| print("\n Top 5 payout OTC:") | |
| for a in top5: | |
| print(f" {a.name:25} {a.payout*100:.1f}% {'🟢' if a.open else '🔴'}") | |
| # ── Informações da conta ── | |
| print("\n👤 Informações da conta:") | |
| info = client.get_account_info() | |
| print(f" ID: {info.user_id}") | |
| print(f" Email: {info.email}") | |
| print(f" Demo: ${info.balance_demo:,.2f}") | |
| print(f" Real: ${info.balance:,.2f}") | |
| print(f" Moeda: {info.currency}") | |
| # ── Encerrar ── | |
| client.disconnect() | |
| print("\n✅ Concluído!") | |
| if __name__ == "__main__": | |
| main() | |