63 lines
2.5 KiB
PHP
63 lines
2.5 KiB
PHP
<?php
|
|
include 'header.php';
|
|
?>
|
|
<div class="container py-5">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2 class="text-white fw-bold">行情中心</h2>
|
|
<div class="input-group style="width: 300px;">
|
|
<input type="text" class="form-control bg-dark text-white border-secondary" placeholder="搜索币种...">
|
|
<span class="input-group-text bg-dark border-secondary text-secondary"><i class="bi bi-search"></i></span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="glass-card">
|
|
<table class="table table-dark table-hover align-middle mb-0">
|
|
<thead>
|
|
<tr class="text-secondary border-bottom border-secondary">
|
|
<th class="ps-4">币种</th>
|
|
<th>价格</th>
|
|
<th>24h 涨跌</th>
|
|
<th>24h 最高</th>
|
|
<th>24h 最低</th>
|
|
<th class="text-end pe-4">交易</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="full-market-tbody">
|
|
<tr><td colspan="6" class="text-center py-5"><div class="spinner-border text-warning"></div></td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
async function refreshMarket() {
|
|
const res = await fetch('api.php?action=market_data');
|
|
const data = await res.json();
|
|
let html = '';
|
|
data.forEach(coin => {
|
|
const changeClass = coin.change >= 0 ? 'text-success' : 'text-danger';
|
|
html += `
|
|
<tr onclick="location.href='trade.php?symbol=${coin.symbol}'" style="cursor:pointer">
|
|
<td class="ps-4 py-3">
|
|
<div class="d-flex align-items-center">
|
|
<img src="${coin.icon_url}" class="me-2" width="24">
|
|
<span class="fw-bold">${coin.symbol}</span>
|
|
</div>
|
|
</td>
|
|
<td class="fw-bold">${parseFloat(coin.price).toFixed(coin.price<1?4:2)}</td>
|
|
<td class="${changeClass} fw-bold">${coin.change >= 0 ? '+' : ''}${coin.change}%</td>
|
|
<td>${(coin.price * 1.05).toFixed(2)}</td>
|
|
<td>${(coin.price * 0.95).toFixed(2)}</td>
|
|
<td class="text-end pe-4">
|
|
<a href="trade.php?symbol=${coin.symbol}" class="btn btn-sm btn-warning">交易</a>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
document.getElementById('full-market-tbody').innerHTML = html;
|
|
}
|
|
refreshMarket();
|
|
setInterval(refreshMarket, 3000);
|
|
</script>
|
|
<?php include 'footer.php'; ?>
|