diff --git a/api.php b/api.php new file mode 100644 index 0000000..00256d4 --- /dev/null +++ b/api.php @@ -0,0 +1,91 @@ +query("SELECT * FROM cryptocurrencies WHERE is_active = 1"); + $coins = $stmt->fetchAll(); + + foreach ($coins as &$coin) { + // Simple mock: fluctuate price slightly + $variation = (mt_rand(-100, 100) / 10000); // +/- 1% + $coin['price'] = (float)$coin['current_price'] * (1 + $variation); + $coin['change'] = (float)$coin['change_24h']; + } + + header('Content-Type: application/json'); + echo json_encode($coins); + exit; +} + +if ($action === 'submit_order') { + check_auth(); + $data = json_decode(file_get_contents('php://input'), true); + + if (!$data) { + echo json_encode(['status' => 'error', 'message' => 'Invalid data']); + exit; + } + + $user_id = $_SESSION['user_id']; + $account = get_account($user_id); + + $symbol = $data['symbol'] ?? 'BTCUSDT'; + $side = $data['side'] ?? 'BUY'; + $trade_type = $data['trade_type'] ?? 'SPOT'; + $order_type = $data['order_type'] ?? 'LIMIT'; + $price = $data['price'] ?? null; + $amount = (float)($data['amount'] ?? 0); + $leverage = (int)($data['leverage'] ?? 1); + + // Basic validation + if ($amount <= 0) { + echo json_encode(['status' => 'error', 'message' => 'Invalid amount']); + exit; + } + + // Logic for SPOT / CONTRACT balance checks + // This is a simplified version + $total_cost = 0; + if ($trade_type === 'SPOT') { + if ($side === 'BUY') { + $exec_price = $price ?: 50000; // Mock price if market + $total_cost = $amount * $exec_price; + if ($account['balance'] < $total_cost) { + echo json_encode(['status' => 'error', 'message' => '余额不足']); + exit; + } + } + } else { + // Contract logic + $total_cost = ($amount * 100) / $leverage; + if ($account['balance'] < $total_cost) { + echo json_encode(['status' => 'error', 'message' => '保证金不足']); + exit; + } + } + + try { + $db = db(); + $db->beginTransaction(); + + // Deduct balance + $stmt = $db->prepare("UPDATE accounts SET balance = balance - ? WHERE id = ?"); + $stmt->execute([$total_cost, $account['id']]); + + // Insert order + $stmt = $db->prepare("INSERT INTO orders (account_id, symbol, trade_type, side, order_type, price, amount, leverage, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'PENDING')"); + $stmt->execute([$account['id'], $symbol, $trade_type, $side, $order_type, $price, $amount, $leverage]); + + $db->commit(); + echo json_encode(['status' => 'success']); + } catch (Exception $e) { + $db->rollBack(); + echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); + } + exit; +} +?> diff --git a/config.php b/config.php new file mode 100644 index 0000000..f01d0c6 --- /dev/null +++ b/config.php @@ -0,0 +1,28 @@ +prepare("SELECT * FROM accounts WHERE user_id = ?"); + $stmt->execute([$user_id]); + return $stmt->fetch(); +} + +// Helper: Get site settings +function get_site_settings() { + $stmt = db()->query("SELECT * FROM site_settings LIMIT 1"); + return $stmt->fetch(); +} +?> \ No newline at end of file diff --git a/footer.php b/footer.php new file mode 100644 index 0000000..991f958 --- /dev/null +++ b/footer.php @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + diff --git a/header.php b/header.php new file mode 100644 index 0000000..635ea9a --- /dev/null +++ b/header.php @@ -0,0 +1,122 @@ + + + + + + + <?php echo $project_name; ?> - 全球领先的数字资产交易平台 + + + + + + + +
diff --git a/index.php b/index.php new file mode 100644 index 0000000..bd9315f --- /dev/null +++ b/index.php @@ -0,0 +1,99 @@ + + + + + +
+
+
+
iOS 下载
+ +
+
+
安卓下载
+ +
+
+
+ + +
+
+
+

热门行情

+

实时获取全球顶级加密货币价格走势

+
+
+ +
+ + + + + + + + + + + + + + +
币种价格24h 涨跌操作
+
+
+
+
+ + + diff --git a/login.php b/login.php new file mode 100644 index 0000000..800220b --- /dev/null +++ b/login.php @@ -0,0 +1,101 @@ +prepare("SELECT * FROM users WHERE username = ?"); + $stmt->execute([$username]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['username'] = $user['username']; + header("Location: index.php"); + exit; + } else { + $error = '用户名或密码错误'; + } + } else { + $error = '请填写所有字段'; + } +} + +include 'header.php'; +?> +
+
+
+
+ +
+

欢迎登录

+

全球领先的加密资产交易平台

+
+ + +
+ + +
+
+ +
+ + + + +
+
+ +
+ +
+ + + + +
+
+ + +
+ +
+

还没有账户? 立即注册

+
+
+
+ + + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..4d4a3c4 --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ + diff --git a/profile.php b/profile.php new file mode 100644 index 0000000..d9e5b0d --- /dev/null +++ b/profile.php @@ -0,0 +1,69 @@ + +
+
+
+
+
+ +

+ UID: +
+
+
+ 信用分 + +
+
+ 实名状态 + +
+
+
+
+
+
资产概览
+
+
+
可用余额 (USDT)
+
+
+
+
冻结金额 (USDT)
+
+
+
+
+ +
+
最近交易
+
+ + + + + + + + + + + + + + + +
时间币种类型金额状态
暂无记录
+
+
+
+
+
+ diff --git a/register.php b/register.php new file mode 100644 index 0000000..8f0ee8b --- /dev/null +++ b/register.php @@ -0,0 +1,88 @@ +prepare("SELECT id FROM users WHERE username = ?"); + $stmt->execute([$username]); + if ($stmt->fetch()) { + $error = '用户名已存在'; + } else { + try { + $db->beginTransaction(); + + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $stmt = $db->prepare("INSERT INTO users (username, password) VALUES (?, ?)"); + $stmt->execute([$username, $hashed_password]); + $user_id = $db->lastInsertId(); + + $uid = str_pad(mt_rand(0, 999999), 6, '0', STR_PAD_LEFT); + $stmt = $db->prepare("INSERT INTO accounts (user_id, uid, balance) VALUES (?, ?, ?)"); + $stmt->execute([$user_id, $uid, 10000.00]); // Default 10000 USDT for simulated + + $db->commit(); + $success = '注册成功!正在跳转到登录页...'; + header("Refresh: 2; URL=login.php"); + } catch (Exception $e) { + $db->rollBack(); + $error = '注册失败: ' . $e->getMessage(); + } + } + } + } else { + $error = '请填写所有字段'; + } +} + +include 'header.php'; +?> +
+
+
+

创建账户

+

加入全球领先的交易社区

+
+ + +
+ + +
+ + +
+
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ +
+

已有账户? 立即登录

+
+
+
+ diff --git a/requirements.txt b/requirements.txt index e22994c..058e3c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,30 @@ +asgiref==3.10.0 +certifi==2022.9.24 +chardet==5.1.0 +charset-normalizer==3.0.1 +dbus-python==1.3.2 +distro-info==1.5+deb12u1 Django==5.2.7 +httplib2==0.20.4 +idna==3.3 +markdown-it-py==2.1.0 +mdurl==0.1.2 mysqlclient==2.2.7 +netifaces==0.11.0 +pycurl==7.45.2 +Pygments==2.14.0 +PyGObject==3.42.2 +pyparsing==3.0.9 +PySimpleSOAP==1.16.2 +python-apt==2.6.0 +python-debian==0.1.49 +python-debianbts==4.0.1 python-dotenv==1.1.1 +PyYAML==6.0 +reportbug==12.0.0 +requests==2.28.1 +rich==13.3.1 +six==1.16.0 +sqlparse==0.5.3 +unattended-upgrades==0.1 +urllib3==1.26.12 diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000..65595a8 --- /dev/null +++ b/schema.sql @@ -0,0 +1,101 @@ +CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(150) UNIQUE NOT NULL, + password VARCHAR(255) NOT NULL, + email VARCHAR(255), + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS accounts ( + id INT AUTO_INCREMENT PRIMARY KEY, + user_id INT NOT NULL, + uid VARCHAR(6) UNIQUE NOT NULL, + account_type ENUM('SIMULATED', 'REAL') DEFAULT 'SIMULATED', + balance DECIMAL(30, 8) DEFAULT 0, + frozen_balance DECIMAL(30, 8) DEFAULT 0, + credit_score INT DEFAULT 80, + kyc_status ENUM('UNVERIFIED', 'PENDING', 'VERIFIED', 'REJECTED') DEFAULT 'UNVERIFIED', + win_loss_control INT DEFAULT 0, + language VARCHAR(10) DEFAULT 'zh-hans', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS site_settings ( + id INT AUTO_INCREMENT PRIMARY KEY, + site_name VARCHAR(100) DEFAULT 'BitCrypto', + customer_service_url TEXT, + terms_content TEXT, + privacy_content TEXT, + is_pinning_active BOOLEAN DEFAULT FALSE +); + +CREATE TABLE IF NOT EXISTS cryptocurrencies ( + id INT AUTO_INCREMENT PRIMARY KEY, + symbol VARCHAR(20) UNIQUE NOT NULL, + name VARCHAR(100) NOT NULL, + icon_url TEXT, + current_price DECIMAL(30, 8) DEFAULT 0, + manual_price DECIMAL(30, 8), + change_24h DECIMAL(10, 2) DEFAULT 0, + is_active BOOLEAN DEFAULT TRUE +); + +CREATE TABLE IF NOT EXISTS assets ( + id INT AUTO_INCREMENT PRIMARY KEY, + account_id INT NOT NULL, + currency VARCHAR(10) NOT NULL, + balance DECIMAL(30, 8) DEFAULT 0, + frozen DECIMAL(30, 8) DEFAULT 0, + UNIQUE KEY account_currency (account_id, currency), + FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS orders ( + id INT AUTO_INCREMENT PRIMARY KEY, + account_id INT NOT NULL, + symbol VARCHAR(20) DEFAULT 'BTC-USDT', + trade_type ENUM('SPOT', 'CONTRACT') DEFAULT 'SPOT', + side ENUM('BUY', 'SELL') NOT NULL, + order_type ENUM('LIMIT', 'MARKET') NOT NULL, + price DECIMAL(30, 8), + amount DECIMAL(30, 8) NOT NULL, + total_usdt DECIMAL(30, 8), + leverage INT DEFAULT 1, + status ENUM('PENDING', 'PARTIALLY_FILLED', 'FILLED', 'CANCELED') DEFAULT 'PENDING', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS positions ( + id INT AUTO_INCREMENT PRIMARY KEY, + account_id INT NOT NULL, + symbol VARCHAR(20) NOT NULL, + side ENUM('LONG', 'SHORT') NOT NULL, + leverage INT DEFAULT 20, + entry_price DECIMAL(30, 8) NOT NULL, + lots DECIMAL(30, 8) NOT NULL, + margin DECIMAL(30, 8) NOT NULL, + is_active BOOLEAN DEFAULT TRUE, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS transactions ( + id INT AUTO_INCREMENT PRIMARY KEY, + account_id INT NOT NULL, + transaction_type ENUM('deposit', 'withdraw') NOT NULL, + currency VARCHAR(10) DEFAULT 'USDT', + amount DECIMAL(30, 8) DEFAULT 0, + tx_hash VARCHAR(255), + status ENUM('pending', 'completed', 'failed') DEFAULT 'pending', + timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE +); + +-- Seed initial data +INSERT INTO site_settings (site_name) VALUES ('BitCrypto'); +INSERT INTO cryptocurrencies (symbol, name, icon_url, current_price, change_24h) VALUES +('BTCUSDT', 'Bitcoin', 'https://cryptologos.cc/logos/bitcoin-btc-logo.png', 45000.00, 1.2), +('ETHUSDT', 'Ethereum', 'https://cryptologos.cc/logos/ethereum-eth-logo.png', 2500.00, -0.5), +('BNBUSDT', 'Binance Coin', 'https://cryptologos.cc/logos/binance-coin-bnb-logo.png', 300.00, 2.1); diff --git a/trade.php b/trade.php new file mode 100644 index 0000000..b2d0750 --- /dev/null +++ b/trade.php @@ -0,0 +1,106 @@ + +
+
+ +
+
+ +
+
+
+ + +
+
+
+ +
+
--
+
+
+
+ 现货 + 合约 +
+
+ +
+
+
+ + +
+
+
+
买入 / 做多
+ +
+ 可用: USDT +
+ +
+
+
卖出 / 做空
+ + +
+
+
+
+ + +
+
+
订单簿
+
+
+
+
+
+ + + +