Editando plataforma falso testes
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dados da Uniswap</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th,
td {
border: 1px solid #ddd;
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
.loading {
font-style: italic;
color: gray;
}
.error {
color: red;
}
</style>
</head>
<body>
<h1>Dados da Uniswap</h1>
<table id="uniswap-table">
<thead>
<tr>
<th>Preço (USD)</th>
<th>Preço (BRL)</th>
<th>Capitalização de Mercado (USD)</th>
<th>Volume em 24h (USD)</th>
<th>Última Atualização</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="5" class="loading">Carregando dados da Uniswap...</td>
</tr>
</tbody>
</table>
<h2>Correlação entre UNI e Outras Moedas</h2>
<table id="correlation-table">
<thead>
<tr>
<th>Moeda</th>
<th>Correlação com UNI</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2" class="loading">Carregando dados de correlação...</td>
</tr>
</tbody>
</table>
<script>
const mockUniswapData = {
"usd": 4.55,
"brl": 24.50,
"usd_market_cap": 1020000000,
"usd_24h_vol": 30000000,
"last_updated_at": 1620000000
};
const mockHistoricalData = {
"bitcoin": [58000, 59000, 60000, 61000, 62000],
"ethereum": [1800, 1850, 1900, 1950, 2000],
"tether": [1, 1, 1, 1, 1],
"binancecoin": [350, 360, 370, 380, 390],
"cardano": [1.2, 1.3, 1.4, 1.5, 1.6],
"uniswap": [4.5, 4.6, 4.7, 4.8, 4.9]
};
function fetchUniswapData() {
return new Promise((resolve) => {
console.log("Usando dados mockados da Uniswap.");
resolve(mockUniswapData);
});
}
function fetchHistoricalData() {
return new Promise((resolve) => {
console.log("Usando dados históricos mockados.");
resolve(mockHistoricalData);
});
}
function calculateCorrelation(prices1, prices2) {
const n = Math.min(prices1.length, prices2.length);
if (n < 2) return 0; // Garantir que haja dados suficientes
const mean1 = prices1.reduce((a, b) => a + b) / n;
const mean2 = prices2.reduce((a, b) => a + b) / n;
let numerator = 0;
let denominator1 = 0;
let denominator2 = 0;
for (let i = 0; i < n; i++) {
const diff1 = prices1[i] - mean1;
const diff2 = prices2[i] - mean2;
numerator += diff1 * diff2;
denominator1 += diff1 ** 2;
denominator2 += diff2 ** 2;
}
return denominator1 && denominator2 ? (numerator / Math.sqrt(denominator1 * denominator2)) : 0;
}
async function updateUniswapTable() {
const uniswapData = await fetchUniswapData();
if (uniswapData) {
const tableBody = document.querySelector('#uniswap-table tbody');
tableBody.innerHTML = `
<tr>
<td>${uniswapData.usd}</td>
<td>${uniswapData.brl}</td>
<td>${uniswapData.usd_market_cap}</td>
<td>${uniswapData.usd_24h_vol}</td>
<td>${new Date(uniswapData.last_updated_at * 1000).toLocaleString('pt-BR')}</td>
</tr>
`;
} else {
const tableBody = document.querySelector('#uniswap-table tbody');
tableBody.innerHTML = `
<tr>
<td colspan="5" class="error">Erro ao carregar dados da Uniswap.</td>
</tr>
`;
}
}
async function updateCorrelationTable() {
const historicalPrices = await fetchHistoricalData();
const correlationTableBody = document.querySelector('#correlation-table tbody');
correlationTableBody.innerHTML = '';
const uniPrices = historicalPrices['uniswap'];
for (const coin of ['bitcoin', 'ethereum', 'tether', 'binancecoin', 'cardano']) {
const prices = historicalPrices[coin];
const correlation = calculateCorrelation(uniPrices, prices);
correlationTableBody.innerHTML += `
<tr>
<td>${coin.charAt(0).toUpperCase() + coin.slice(1)}</td>
<td>${prices.length > 0 ? correlation.toFixed(2) : 'Dados insuficientes'}</td>
</tr>
`;
}
}
// Chamar as funções para buscar os dados mockados
updateUniswapTable().then(updateCorrelationTable);
</script>
</body>
</html>