diff --git a/api.php b/api.php index 35102ed..63f73d6 100644 --- a/api.php +++ b/api.php @@ -3,57 +3,100 @@ include_once 'config.php'; $action = $_GET['action'] ?? ''; -// Function to fetch prices with caching +/** + * Fetch prices from Binance with caching and high precision + */ function get_real_prices() { $cache_file = __DIR__ . '/db/price_cache.json'; $cache_time = 2; // Cache for 2 seconds + // Check cache if (file_exists($cache_file) && (time() - filemtime($cache_file) < $cache_time)) { - return json_decode(file_get_contents($cache_file), true); + $cache_data = json_decode(file_get_contents($cache_file), true); + if (!empty($cache_data)) return $cache_data; } - // Fetch active coins from DB to only ask for what we need - $stmt = db()->query("SELECT symbol FROM cryptocurrencies WHERE is_active = 1"); - $symbols = $stmt->fetchAll(PDO::FETCH_COLUMN); + // Fetch active coins from DB + try { + $stmt = db()->query("SELECT symbol FROM cryptocurrencies WHERE is_active = 1"); + $symbols = $stmt->fetchAll(PDO::FETCH_COLUMN); + } catch (Exception $e) { + $symbols = ['BTCUSDT', 'ETHUSDT', 'BNBUSDT', 'SOLUSDT', 'DOGEUSDT']; + } - if (empty($symbols)) return []; + if (empty($symbols)) $symbols = ['BTCUSDT']; - // Binance API - symbols parameter format: ["BTCUSDT","ETHUSDT"] - $symbols_encoded = urlencode(json_encode($symbols)); - $url = "https://api.binance.com/api/v3/ticker/24hr?symbols=" . $symbols_encoded; + // Use Binance 24hr ticker for comprehensive data + $symbols_json = json_encode($symbols); + $url = "https://api.binance.com/api/v3/ticker/24hr?symbols=" . urlencode($symbols_json); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 5); - curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'); + // Disable SSL verification if needed for some environments, but prefer keeping it + // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $response = curl_exec($ch); + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); - if (!$response) { - // If Binance fails, try to return expired cache if exists - if (file_exists($cache_file)) return json_decode(file_get_contents($cache_file), true); - return []; + $prices = []; + + if ($http_code == 200 && $response) { + $data = json_decode($response, true); + if (is_array($data)) { + foreach ($data as $item) { + if (isset($item['symbol'])) { + $prices[$item['symbol']] = [ + 'price' => $item['lastPrice'], + 'change' => $item['priceChangePercent'], + 'high' => $item['highPrice'], + 'low' => $item['lowPrice'], + 'volume' => $item['quoteVolume'], + 'ts' => time() + ]; + } + } + } } - $data = json_decode($response, true); - $prices = []; - if (is_array($data)) { - foreach ($data as $item) { - if (isset($item['symbol'])) { - $prices[$item['symbol']] = [ - 'price' => $item['lastPrice'], - 'change' => $item['priceChangePercent'], - 'high' => $item['highPrice'], - 'low' => $item['lowPrice'], - 'volume' => $item['quoteVolume'] - ]; + // Fallback: If 24hr fails, try simpler price-only endpoint + if (empty($prices)) { + $url_simple = "https://api.binance.com/api/v3/ticker/price"; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url_simple); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); + $resp_simple = curl_exec($ch); + curl_close($ch); + + if ($resp_simple) { + $data_simple = json_decode($resp_simple, true); + if (is_array($data_simple)) { + foreach ($data_simple as $item) { + if (in_array($item['symbol'], $symbols)) { + $prices[$item['symbol']] = [ + 'price' => $item['price'], + 'change' => '0.00', + 'high' => $item['price'], + 'low' => $item['price'], + 'volume' => '0', + 'ts' => time() + ]; + } + } } } } if (!empty($prices)) { - file_put_contents($cache_file, json_encode($prices)); + // Only update file if we have new data + @file_put_contents($cache_file, json_encode($prices)); + } else if (file_exists($cache_file)) { + // Last resort: return expired cache + return json_decode(file_get_contents($cache_file), true); } return $prices; @@ -61,34 +104,36 @@ function get_real_prices() { if ($action === 'market_data') { $real_prices = get_real_prices(); - $stmt = db()->query("SELECT * FROM cryptocurrencies WHERE is_active = 1 ORDER BY id ASC"); - $coins = $stmt->fetchAll(); + try { + $stmt = db()->query("SELECT * FROM cryptocurrencies WHERE is_active = 1 ORDER BY id ASC"); + $coins = $stmt->fetchAll(); + } catch (Exception $e) { + $coins = []; + } $updated_coins = []; foreach ($coins as $coin) { $symbol = $coin['symbol']; if (isset($real_prices[$symbol])) { - $coin['price'] = (float)$real_prices[$symbol]['price']; + $coin['price'] = (string)$real_prices[$symbol]['price']; // Keep as string for precision $coin['change'] = (float)$real_prices[$symbol]['change']; - $coin['high'] = (float)$real_prices[$symbol]['high']; - $coin['low'] = (float)$real_prices[$symbol]['low']; + $coin['high'] = (string)$real_prices[$symbol]['high']; + $coin['low'] = (string)$real_prices[$symbol]['low']; $coin['volume'] = (float)$real_prices[$symbol]['volume']; - // Apply manual price if set if ($coin['manual_price'] > 0) { - $coin['price'] = (float)$coin['manual_price']; + $coin['price'] = (string)$coin['manual_price']; } - // Periodically update DB (every few seconds to avoid overhead) - // We'll update the database to keep it relatively fresh for order submission + // Sync to DB occasionally (logic can be improved, but this is current) $upd = db()->prepare("UPDATE cryptocurrencies SET current_price = ?, change_24h = ? WHERE id = ?"); $upd->execute([$coin['price'], $coin['change'], $coin['id']]); } else { - $coin['price'] = (float)$coin['current_price']; + $coin['price'] = (string)$coin['current_price']; $coin['change'] = (float)$coin['change_24h']; - $coin['high'] = $coin['price'] * 1.02; // Fallback - $coin['low'] = $coin['price'] * 0.98; + $coin['high'] = (string)($coin['current_price'] * 1.01); + $coin['low'] = (string)($coin['current_price'] * 0.99); $coin['volume'] = 0; } $updated_coins[] = $coin; @@ -122,7 +167,6 @@ if ($action === 'submit_order') { exit; } - // IMPORTANT: Fetch FRESH price for order execution $real_prices = get_real_prices(); $stmt = db()->prepare("SELECT * FROM cryptocurrencies WHERE symbol = ?"); $stmt->execute([$symbol]); @@ -156,12 +200,9 @@ if ($action === 'submit_order') { if ($account['balance'] < $total_cost) { throw new Exception('余额不足 (需要 ' . number_format($total_cost, 2) . ' USDT)'); } - - // Deduct USDT $stmt = $db->prepare("UPDATE accounts SET balance = balance - ? WHERE id = ?"); $stmt->execute([$total_cost, $account['id']]); - // Add Asset $currency = str_replace('USDT', '', $symbol); $stmt = $db->prepare("INSERT INTO assets (account_id, currency, balance) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE balance = balance + ?"); $stmt->execute([$account['id'], $currency, $amount, $amount]); @@ -176,24 +217,19 @@ if ($action === 'submit_order') { throw new Exception('资产余额不足'); } - // Deduct Asset $stmt = $db->prepare("UPDATE assets SET balance = balance - ? WHERE account_id = ? AND currency = ?"); $stmt->execute([$amount, $account['id'], $currency]); - // Add USDT $total_gain = $amount * $current_price; $stmt = $db->prepare("UPDATE accounts SET balance = balance + ? WHERE id = ?"); $stmt->execute([$total_gain, $account['id']]); } - // Record Order as FILLED $stmt = $db->prepare("INSERT INTO orders (account_id, symbol, trade_type, side, order_type, price, amount, total_usdt, status) VALUES (?, ?, 'SPOT', ?, 'MARKET', ?, ?, ?, 'FILLED')"); $stmt->execute([$account['id'], $symbol, $side, $current_price, $amount, $amount * $current_price]); } else if ($trade_type === 'CONTRACT') { - // Contract Value per Lot is 100 USDT by default in trade.php - // but we use 'amount' as lots. - $contract_value = 100; // Standard value + $contract_value = 100; $total_value = $amount * $contract_value; $margin = $total_value / $leverage; @@ -201,15 +237,12 @@ if ($action === 'submit_order') { throw new Exception('保证金不足 (需要 ' . number_format($margin, 2) . ' USDT)'); } - // Deduct Margin $stmt = $db->prepare("UPDATE accounts SET balance = balance - ? WHERE id = ?"); $stmt->execute([$margin, $account['id']]); - // Create Position $stmt = $db->prepare("INSERT INTO positions (account_id, symbol, side, leverage, entry_price, lots, margin) VALUES (?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$account['id'], $symbol, ($side === 'BUY' ? 'LONG' : 'SHORT'), $leverage, $current_price, $amount, $margin]); - // Record Order $stmt = $db->prepare("INSERT INTO orders (account_id, symbol, trade_type, side, order_type, price, amount, leverage, status) VALUES (?, ?, 'CONTRACT', ?, 'MARKET', ?, ?, ?, 'FILLED')"); $stmt->execute([$account['id'], $symbol, $side, $current_price, $amount, $leverage]); } @@ -234,11 +267,8 @@ if ($action === 'positions') { $real_prices = get_real_prices(); - // Calculate PnL for each position foreach ($positions as &$pos) { $symbol = $pos['symbol']; - - // Use fresh price for PnL calculation $stmt = db()->prepare("SELECT manual_price, current_price FROM cryptocurrencies WHERE symbol = ?"); $stmt->execute([$symbol]); $coin = $stmt->fetch(); @@ -253,18 +283,16 @@ if ($action === 'positions') { $pos['current_price'] = $current_price; - // PnL Calculation: (PriceDiff / EntryPrice) * Margin * Leverage if ($pos['side'] === 'LONG') { $pos['pnl'] = (($current_price - $pos['entry_price']) / $pos['entry_price']) * $pos['margin'] * $pos['leverage']; } else { $pos['pnl'] = (($pos['entry_price'] - $current_price) / $pos['entry_price']) * $pos['margin'] * $pos['leverage']; } - // Apply Win/Loss Control (Display purpose) if ($account['win_loss_control'] == 1 && $pos['pnl'] < 0) { - $pos['pnl'] = abs($pos['pnl']) * 0.2; // Show small profit + $pos['pnl'] = abs($pos['pnl']) * 0.2; } else if ($account['win_loss_control'] == -1 && $pos['pnl'] > 0) { - $pos['pnl'] = -abs($pos['pnl']) * 1.5; // Show big loss + $pos['pnl'] = -abs($pos['pnl']) * 1.5; } } @@ -310,21 +338,18 @@ if ($action === 'close_position') { $pnl = (($pos['entry_price'] - $current_price) / $pos['entry_price']) * $pos['margin'] * $pos['leverage']; } - // Win/Loss Control Logic - if ($account['win_loss_control'] == 1) { // Always Win - if ($pnl < 0) $pnl = abs($pnl) * 0.1; // Force win - } else if ($account['win_loss_control'] == -1) { // Always Loss - if ($pnl > 0) $pnl = -abs($pnl) * 1.2; // Force loss + if ($account['win_loss_control'] == 1) { + if ($pnl < 0) $pnl = abs($pnl) * 0.1; + } else if ($account['win_loss_control'] == -1) { + if ($pnl > 0) $pnl = -abs($pnl) * 1.2; } - // Return Margin + PnL $payout = $pos['margin'] + $pnl; if ($payout < 0) $payout = 0; $stmt = $db->prepare("UPDATE accounts SET balance = balance + ? WHERE id = ?"); $stmt->execute([$payout, $account['id']]); - // Deactivate Position $stmt = $db->prepare("UPDATE positions SET is_active = 0 WHERE id = ?"); $stmt->execute([$pos_id]); diff --git a/assets/pasted-20260207-062921-01d39dbe.png b/assets/pasted-20260207-062921-01d39dbe.png new file mode 100644 index 0000000..6389485 Binary files /dev/null and b/assets/pasted-20260207-062921-01d39dbe.png differ diff --git a/deposit.php b/deposit.php index 69d288b..063d63d 100644 --- a/deposit.php +++ b/deposit.php @@ -1,18 +1,25 @@ 0 && $tx_hash) { - $stmt = db()->prepare("INSERT INTO transactions (account_id, transaction_type, amount, tx_hash, status) VALUES (?, 'deposit', ?, ?, 'pending')"); - $stmt->execute([$account['id'], $amount, $tx_hash]); - $success = "充值申请已提交,请等待管理员审核。"; + if ($amount < 10) { + $error = '最小充值金额为 10 USDT'; } else { - $error = "请填写完整信息。"; + $stmt = db()->prepare("INSERT INTO transactions (account_id, transaction_type, currency, pay_method, amount, tx_hash, status) VALUES (?, 'deposit', 'USDT', ?, ?, ?, 'pending')"); + $stmt->execute([$account['id'], $method, $amount, $tx_hash]); + $success = '充值申请已提交,请等待系统确认'; } } @@ -20,41 +27,135 @@ include 'header.php'; ?>
-
-
-

USDT 充值 (TRC20)

+
+
+

充值中心

-
-
+ +
+ + +
+ -
-
转账地址
-
TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
- + + +
+ +
+
+
+
+ QR +
+
扫描上方二维码获取地址
+
+
+
+ +
+ + + +
+
+
+ +
+ + +
+
+
+
+ +
+ +
+ + +
+
+ + +
+ +
+
+ + +
+
+ 法币充值按实时汇率折算,当前汇率: 1 USDT ≈ 7.25 CNY +
+ +
+
收款账户信息
+
+ 收款银行 + 工商银行 (ICBC) +
+
+ 收款人 + BitCrypto Technology Co. +
+
+ 银行账号 + 6222 0000 0000 0000 888 +
+
+ 开户支行 + 上海自贸区支行 +
+
+ +
+ +
+ + +
+
+ +
+ + CNY +
+
+
+ + +
+
+ + +
+ +
+
-
-
- - -
-
- - -
- -
- -
-

温馨提示:

-
    -
  • 请勿向上述地址充值任何非 USDT 资产,否则资产将不可找回。
  • -
  • 最低充值金额 10 USDT。
  • -
  • 转账完成后请务必填写 TxID。
  • +
    +
    充值说明:
    +
      +
    • 数字货币充值通常在 10-30 分钟内到账。
    • +
    • 法币充值需要人工审核,工作时间 (9:00-22:00) 约 30 分钟内到账。
    • +
    • 请务必在汇款备注中填写您的 UID:
- + \ No newline at end of file diff --git a/header.php b/header.php index 635ea9a..9536ef0 100644 --- a/header.php +++ b/header.php @@ -55,6 +55,18 @@ $project_name = $settings['site_name'] ?? 'BitCrypto'; border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 12px; } + .dropdown-menu-dark { + background-color: #1e2329; + border: 1px solid #3b4149; + } + .dropdown-item { + font-size: 14px; + padding: 10px 20px; + } + .dropdown-item:hover { + background-color: #2b3139; + color: var(--accent-color); + } .cs-float { position: fixed; right: 30px; @@ -84,8 +96,8 @@ $project_name = $settings['site_name'] ?? 'BitCrypto'; -
+
\ No newline at end of file diff --git a/index.php b/index.php index b236f86..256cb8a 100644 --- a/index.php +++ b/index.php @@ -3,23 +3,36 @@ include 'header.php'; ?> -
+
-

开启您的数字资产 交易之旅

-

全球信赖的加密资产交易平台,提供极速、安全、专业的数字资产交易服务。支持现货及永续合约交易。

-
+
#1 全球领先交易平台
+

简单、安全、
极速 交易加密货币

+

在 BitCrypto 开启您的交易之旅。支持 350+ 种加密货币,提供 100 倍杠杆合约及超低手续费现货交易。

+ +
+
资产安全保障
+
毫秒级撮合
+
7/24 在线支持
- Hero +
+ Hero +
+
BTC/USDT
+
--
+
+2.4%
+
+
@@ -27,23 +40,23 @@ include 'header.php';
-
+
-
+
24h 交易量
$76.2B
-
+
主流币种
350+
-
+
注册用户
120M+
-
+
最低费率
-
0.10%
+
0.02%
@@ -54,10 +67,10 @@ include 'header.php';
-

热门市场

-

实时行情,全球同步

+

热门币种

+

同步全球顶级交易所实时数据

- 查看行情中心 + 更多市场
@@ -65,10 +78,10 @@ include 'header.php'; 名称 - 最新价 (USDT) + 最新价 24h 涨跌 - 24h 最高 / 最低 - 操作 + 24h 最高 / 最低 + 交易 @@ -79,42 +92,45 @@ include 'header.php';
- -
+ +
-
-
-
- -

安全可靠

-

采用多重安全防护机制,冷热钱包分离,保障您的资产安全。符合国际最高合规标准。

+
+
+

随时随地 尽情交易

+

下载 BitCrypto 移动端 App,在手机上获取实时行情、管理资产、极速下单。

+
+ +
-
-
- -

极速撮合

-

自研高性能撮合引擎,支持百万级并发交易,告别卡顿延迟。平均响应时间小于10ms。

-
-
-
-
- -

专业支持

-

7*24小时多语种在线客服,随时解答您的任何疑问。为您提供保驾护航的交易环境。

-
+
+
+ + - + \ No newline at end of file diff --git a/market.php b/market.php index 8062f88..91176b4 100644 --- a/market.php +++ b/market.php @@ -2,37 +2,100 @@ include 'header.php'; ?>
-
-
-

行情中心

-

实时监测全球主流数字货币市场价格波动

+ +
+
+
+
+
今日涨幅榜
+ +
+
+
加载中...
+
+
-
- - +
+
+
+
新币上架
+ +
+
+
加载中...
+
+
+
+
+
+
+
成交热度榜
+ +
+
+
加载中...
+
+
-
+
+
+

行情中心

+

实时监测全球主流数字货币市场价格波动

+
+
+ + +
+
+ +
- + - - - + + - +
币种名称最新价格 (USDT)最新价格 24h 涨跌24h 最高24h 最低24h 成交额24h 最高/最低24h 成交额(USDT) 操作
+ + +
+

行业资讯

+
+
+
+ +
+ 快讯 +
以太坊坎昆升级顺利完成,Layer 2 费用大幅下降
+

此次升级引入了 Proto-Danksharding,为以太坊扩容迈出关键一步...

+
+
+
+
+
+ +
+ 深度 +
比特币减半后市场走势分析:机遇还是挑战?
+

历史数据显示,减半通常伴随着周期的转折,本次减半有何不同...

+
+
+
+
+