olywwe commited on
Commit
b40745e
·
verified ·
1 Parent(s): 3af8019

Usar dados reais usando essa api import { CandleData } from '@/types/trading'; const API_BASE_URL = 'https://api.binance.com/api/v3'; export const fetchMarketData = async (symbol: string, timeframe: string): Promise<CandleData[]> => { try { console.log('Fetching market data for:', symbol); // Convert forex pair to Binance spot format const formattedSymbol = symbol === 'EURUSD' ? 'EURUSDT' : symbol; // Convert timeframe to interval format expected by Binance const interval = timeframe.replace('m', 'm').replace('h', 'h').replace('d', 'd'); // Get current timestamp const endTime = Date.now(); const startTime = endTime - (30 * 60 * 1000); // Last 30 minutes of data console.log('Making API request with:', { symbol: formattedSymbol, interval, startTime, endTime }); // Fetch real market data from Binance Spot API const response = await fetch( `${API_BASE_URL}/klines?symbol=${formattedSymbol}&interval=${interval}&startTime=${startTime}&endTime=${endTime}&limit=30` ); if (!response.ok) { const errorText = await response.text(); console.error('API Error Response:', errorText); throw new Error(`Failed to fetch market data: ${response.statusText}. ${errorText}`); } const data = await response.json(); // Transform Binance data to CandleData format const candles: CandleData[] = data.map((candle: any) => ({ timestamp: candle[0], open: parseFloat(candle[1]), high: parseFloat(candle[2]), low: parseFloat(candle[3]), close: parseFloat(candle[4]), volume: parseFloat(candle[5]) })); console.log('Processed market data:', candles); return candles; } catch (error) { console.error('Error fetching market data:', error); throw error; } }; - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +176 -44
index.html CHANGED
@@ -7,7 +7,8 @@
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
10
- <script>
 
11
  tailwind.config = {
12
  theme: {
13
  extend: {
@@ -22,6 +23,61 @@
22
  }
23
  }
24
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  </script>
26
  <style>
27
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
@@ -306,9 +362,31 @@
306
  <option>Últimas 24 horas</option>
307
  </select>
308
  </div>
309
- <canvas id="performanceChart" height="200"></canvas>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
  </div>
311
- </div>
312
 
313
  <!-- Painel Lateral -->
314
  <div>
@@ -510,55 +588,109 @@
510
  </div>
511
  </footer>
512
 
513
- <script>
514
- // Inicializar gráfico de performance
515
- const ctx = document.getElementById('performanceChart').getContext('2d');
516
- const performanceChart = new Chart(ctx, {
517
- type: 'line',
518
- data: {
519
- labels: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
520
- datasets: [{
521
- label: 'Taxa de Acerto (%)',
522
- data: [82, 85, 87, 89, 90, 91, 92, 91, 93, 92, 94, 92.7],
523
- borderColor: '#3b82f6',
524
- backgroundColor: 'rgba(59, 130, 246, 0.1)',
525
- borderWidth: 2,
526
- pointBackgroundColor: '#3b82f6',
527
- fill: true,
528
- tension: 0.3
529
- }]
530
- },
531
- options: {
532
- responsive: true,
533
- maintainAspectRatio: false,
534
- plugins: {
535
- legend: {
536
- display: false
537
- }
538
  },
539
- scales: {
540
- y: {
541
- beginAtZero: false,
542
- min: 80,
543
- max: 100,
544
- grid: {
545
- color: 'rgba(255, 255, 255, 0.1)'
546
- },
547
- ticks: {
548
- color: '#94a3b8'
549
  }
550
  },
551
- x: {
552
- grid: {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
553
  display: false
 
 
 
 
 
 
 
 
 
 
 
 
 
554
  },
555
- ticks: {
556
- color: '#94a3b8'
 
 
 
 
 
557
  }
558
  }
559
  }
560
- }
561
- });
562
 
563
  // Simular conexões na rede neural
564
  function drawNetworkConnections() {
 
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
10
+ <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
11
+ <script type="text/babel">
12
  tailwind.config = {
13
  theme: {
14
  extend: {
 
23
  }
24
  }
25
  }
26
+
27
+ // API functions
28
+ const API_BASE_URL = 'https://api.binance.com/api/v3';
29
+
30
+ const fetchMarketData = async (symbol, timeframe) => {
31
+ try {
32
+ console.log('Fetching market data for:', symbol);
33
+
34
+ // Convert forex pair to Binance spot format
35
+ const formattedSymbol = symbol === 'EURUSD' ? 'EURUSDT' : symbol;
36
+
37
+ // Convert timeframe to interval format expected by Binance
38
+ const interval = timeframe.replace('m', 'm').replace('h', 'h').replace('d', 'd');
39
+
40
+ // Get current timestamp
41
+ const endTime = Date.now();
42
+ const startTime = endTime - (30 * 60 * 1000); // Last 30 minutes of data
43
+
44
+ console.log('Making API request with:', {
45
+ symbol: formattedSymbol,
46
+ interval,
47
+ startTime,
48
+ endTime
49
+ });
50
+
51
+ // Fetch real market data from Binance Spot API
52
+ const response = await fetch(
53
+ `${API_BASE_URL}/klines?symbol=${formattedSymbol}&interval=${interval}&startTime=${startTime}&endTime=${endTime}&limit=30`
54
+ );
55
+
56
+ if (!response.ok) {
57
+ const errorText = await response.text();
58
+ console.error('API Error Response:', errorText);
59
+ throw new Error(`Failed to fetch market data: ${response.statusText}. ${errorText}`);
60
+ }
61
+
62
+ const data = await response.json();
63
+
64
+ // Transform Binance data to CandleData format
65
+ const candles = data.map(candle => ({
66
+ timestamp: candle[0],
67
+ open: parseFloat(candle[1]),
68
+ high: parseFloat(candle[2]),
69
+ low: parseFloat(candle[3]),
70
+ close: parseFloat(candle[4]),
71
+ volume: parseFloat(candle[5])
72
+ }));
73
+
74
+ console.log('Processed market data:', candles);
75
+ return candles;
76
+ } catch (error) {
77
+ console.error('Error fetching market data:', error);
78
+ throw error;
79
+ }
80
+ };
81
  </script>
82
  <style>
83
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
 
362
  <option>Últimas 24 horas</option>
363
  </select>
364
  </div>
365
+ <!-- Real-time Price Chart -->
366
+ <div class="stat-card p-6 mb-8">
367
+ <div class="flex justify-between items-center mb-6">
368
+ <h2 class="text-xl font-bold">EUR/USD em Tempo Real</h2>
369
+ <div class="flex items-center space-x-4">
370
+ <div class="text-2xl font-bold" id="latestPrice">1.08420</div>
371
+ <div class="text-sm font-medium" id="priceChange">+0.24%</div>
372
+ </div>
373
+ </div>
374
+ <canvas id="priceChart" height="200"></canvas>
375
+ </div>
376
+
377
+ <!-- Performance Chart -->
378
+ <div class="stat-card p-6">
379
+ <div class="flex justify-between items-center mb-6">
380
+ <h2 class="text-xl font-bold">Performance da Rede Neural</h2>
381
+ <select class="bg-secondary border border-gray-700 rounded-lg px-3 py-1 text-sm">
382
+ <option>Últimos 30 dias</option>
383
+ <option>Últimos 7 dias</option>
384
+ <option>Últimas 24 horas</option>
385
+ </select>
386
+ </div>
387
+ <canvas id="performanceChart" height="200"></canvas>
388
+ </div>
389
  </div>
 
390
 
391
  <!-- Painel Lateral -->
392
  <div>
 
588
  </div>
589
  </footer>
590
 
591
+ <script type="text/babel">
592
+ // Initialize charts
593
+ let priceChart;
594
+ let performanceChart;
595
+
596
+ // Initialize price chart
597
+ const initPriceChart = () => {
598
+ const ctx = document.getElementById('priceChart').getContext('2d');
599
+ priceChart = new Chart(ctx, {
600
+ type: 'line',
601
+ data: {
602
+ labels: [],
603
+ datasets: [{
604
+ label: 'EUR/USD Price',
605
+ data: [],
606
+ borderColor: '#3b82f6',
607
+ backgroundColor: 'rgba(59, 130, 246, 0.1)',
608
+ borderWidth: 2,
609
+ pointRadius: 0,
610
+ fill: true,
611
+ tension: 0.2
612
+ }]
 
 
 
613
  },
614
+ options: {
615
+ responsive: true,
616
+ maintainAspectRatio: false,
617
+ plugins: {
618
+ legend: {
619
+ display: false
 
 
 
 
620
  }
621
  },
622
+ scales: {
623
+ y: {
624
+ grid: {
625
+ color: 'rgba(255, 255, 255, 0.1)'
626
+ },
627
+ ticks: {
628
+ color: '#94a3b8'
629
+ }
630
+ },
631
+ x: {
632
+ grid: {
633
+ display: false
634
+ },
635
+ ticks: {
636
+ color: '#94a3b8'
637
+ }
638
+ }
639
+ }
640
+ }
641
+ });
642
+ };
643
+
644
+ // Initialize performance chart
645
+ const initPerformanceChart = () => {
646
+ const ctx = document.getElementById('performanceChart').getContext('2d');
647
+ performanceChart = new Chart(ctx, {
648
+ type: 'line',
649
+ data: {
650
+ labels: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
651
+ datasets: [{
652
+ label: 'Taxa de Acerto (%)',
653
+ data: [82, 85, 87, 89, 90, 91, 92, 91, 93, 92, 94, 92.7],
654
+ borderColor: '#3b82f6',
655
+ backgroundColor: 'rgba(59, 130, 246, 0.1)',
656
+ borderWidth: 2,
657
+ pointBackgroundColor: '#3b82f6',
658
+ fill: true,
659
+ tension: 0.3
660
+ }]
661
+ },
662
+ options: {
663
+ responsive: true,
664
+ maintainAspectRatio: false,
665
+ plugins: {
666
+ legend: {
667
  display: false
668
+ }
669
+ },
670
+ scales: {
671
+ y: {
672
+ beginAtZero: false,
673
+ min: 80,
674
+ max: 100,
675
+ grid: {
676
+ color: 'rgba(255, 255, 255, 0.1)'
677
+ },
678
+ ticks: {
679
+ color: '#94a3b8'
680
+ }
681
  },
682
+ x: {
683
+ grid: {
684
+ display: false
685
+ },
686
+ ticks: {
687
+ color: '#94a3b8'
688
+ }
689
  }
690
  }
691
  }
692
+ });
693
+ };
694
 
695
  // Simular conexões na rede neural
696
  function drawNetworkConnections() {