107 lines
4.6 KiB
PHP
107 lines
4.6 KiB
PHP
<?php
|
|
include_once 'config.php';
|
|
check_auth();
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
$account = get_account($user_id);
|
|
$symbol = $_GET['symbol'] ?? 'BTCUSDT';
|
|
$trade_type = $_GET['type'] ?? 'SPOT';
|
|
$base_symbol = str_replace('USDT', '', $symbol);
|
|
|
|
include 'header.php';
|
|
?>
|
|
<div class="container-fluid px-2 py-2" style="background-color: #0b0e11; min-height: 90vh;">
|
|
<div class="row g-2">
|
|
<!-- Sidebar -->
|
|
<div class="col-lg-2 d-none d-lg-block">
|
|
<div class="glass-card h-100 p-2 bg-dark">
|
|
<input type="text" id="coin-search" class="form-control form-control-sm bg-dark text-white border-secondary mb-2" placeholder="搜索币种">
|
|
<div id="left-coin-list"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Main -->
|
|
<div class="col-lg-7">
|
|
<div class="glass-card mb-2 p-2 d-flex align-items-center justify-content-between bg-dark">
|
|
<div class="d-flex align-items-center">
|
|
<span class="text-warning fw-bold fs-5 me-4"><?php echo $symbol; ?></span>
|
|
<div class="me-4">
|
|
<div class="fw-bold fs-5 text-success" id="header-price">--</div>
|
|
</div>
|
|
</div>
|
|
<div class="d-flex gap-1 bg-dark p-1">
|
|
<a href="?type=SPOT&symbol=<?php echo $symbol; ?>" class="btn btn-sm <?php echo $trade_type=='SPOT'?'btn-warning':'text-secondary'; ?>">现货</a>
|
|
<a href="?type=CONTRACT&symbol=<?php echo $symbol; ?>" class="btn btn-sm <?php echo $trade_type=='CONTRACT'?'btn-warning':'text-secondary'; ?>">合约</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="glass-card mb-2" style="height: 400px;">
|
|
<div id="tradingview_widget" style="height: 100%;"></div>
|
|
</div>
|
|
|
|
<!-- Form -->
|
|
<div class="glass-card p-3 bg-dark">
|
|
<div class="row">
|
|
<div class="col-md-6 border-end border-secondary">
|
|
<h6 class="text-success mb-3">买入 / 做多</h6>
|
|
<input type="number" id="buy-amount" class="form-control bg-dark text-white border-secondary mb-3" placeholder="数量">
|
|
<div class="d-flex justify-content-between small text-secondary mb-3">
|
|
<span>可用: <?php echo number_format($account['balance'], 2); ?> USDT</span>
|
|
</div>
|
|
<button class="btn btn-success w-100" onclick="submitOrder('BUY')">买入</button>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<h6 class="text-danger mb-3">卖出 / 做空</h6>
|
|
<input type="number" id="sell-amount" class="form-control bg-dark text-white border-secondary mb-3" placeholder="数量">
|
|
<button class="btn btn-danger w-100" onclick="submitOrder('SELL')">卖出</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Order Book -->
|
|
<div class="col-lg-3 d-none d-lg-block">
|
|
<div class="glass-card h-100 p-2 bg-dark">
|
|
<h6 class="text-secondary small">订单簿</h6>
|
|
<div id="order-book"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
|
|
<script>
|
|
const symbol = '<?php echo $symbol; ?>';
|
|
const tradeType = '<?php echo $trade_type; ?>';
|
|
|
|
new TradingView.widget({
|
|
"width": "100%", "height": "100%", "symbol": "BINANCE:" + symbol,
|
|
"interval": "15", "theme": "dark", "style": "1", "locale": "zh_CN",
|
|
"container_id": "tradingview_widget"
|
|
});
|
|
|
|
async function tick() {
|
|
const r = await fetch('api.php?action=market_data');
|
|
const data = await r.json();
|
|
const coin = data.find(c => c.symbol === symbol);
|
|
if (coin) {
|
|
document.getElementById('header-price').textContent = parseFloat(coin.price).toLocaleString();
|
|
}
|
|
}
|
|
|
|
async function submitOrder(side) {
|
|
const amount = document.getElementById(side.toLowerCase() + '-amount').value;
|
|
const res = await fetch('api.php?action=submit_order', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ symbol, side, trade_type: tradeType, amount })
|
|
});
|
|
const json = await res.json();
|
|
if (json.status === 'success') { alert('下单成功'); location.reload(); }
|
|
else { alert('失败: ' + json.message); }
|
|
}
|
|
|
|
setInterval(tick, 2000);
|
|
tick();
|
|
</script>
|
|
<?php include 'footer.php'; ?>
|