脚本笔记8/27/2026

index.html

来源文件:index.html
已自动脱敏 0 处敏感信息。

html

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网格盈亏计算器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 20px;
        }

        .form-container {
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
            background-color: #f9f9f9;
        }

        .form-container input {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            border-radius: 4px;
            border: 1px solid #ccc;
        }

        .form-container button {
            width: 100%;
            padding: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
        }

        .form-container button:hover {
            background-color: #45a049;
        }

        .result {
            margin-top: 20px;
            padding: 10px;
            background-color: #f1f1f1;
            border-radius: 4px;
            border: 1px solid #ddd;
        }
    </style>
</head>

<body>
    <div class="form-container">
        <h2>网格盈亏计算器</h2>
        <label for="topPrice">网格顶部价格:</label>
        <input type="number" id="topPrice" placeholder="请输入网格顶部价格" value="2" required>

        <label for="bottomPrice">网格底部价格:</label>
        <input type="number" id="bottomPrice" placeholder="请输入网格底部价格" value="1" required>

        <label for="gridCount">网格数量:</label>
        <input type="number" id="gridCount" placeholder="请输入网格数量" value="100" required>

        <label for="investment">每格投入资金:</label>
        <input type="number" id="investment" placeholder="请输入每格投入资金" value="100" required>

        <label for="entryPrice">网格创建时的入场价:</label>
        <input type="number" id="entryPrice" placeholder="请输入网格创建时的入场价" value="1.66" required>

        <label for="currentPrice">当前价格:</label>
        <input type="number" id="currentPrice" placeholder="请输入当前价格" value="1.33" required>

        <button

        <div class="result" id="result"></div>
    </div>

    <script>
        function calculateLoss() {
            // 获取表单数据
            const topPrice = parseFloat(document.getElementById('topPrice').value);
            const bottomPrice = parseFloat(document.getElementById('bottomPrice').value);
            const gridCount = parseInt(document.getElementById('gridCount').value);
            const investment = parseFloat(document.getElementById('investment').value);
            const entryPrice = parseFloat(document.getElementById('entryPrice').value);
            const currentPrice = parseFloat(document.getElementById('currentPrice').value);

            // 输入验证
            if (isNaN(topPrice) || isNaN(bottomPrice) || isNaN(gridCount) || isNaN(investment) || isNaN(entryPrice) || isNaN(currentPrice) ||
                gridCount <= 0 || topPrice <= bottomPrice || investment <= 0 || entryPrice <= 0 || currentPrice <= 0) {
                document.getElementById('result').innerHTML = '请输入有效的数值。';
                return;
            }

            // 计算网格的价格间隔
            const priceInterval = (topPrice - bottomPrice) / (gridCount - 1);

            // 计算总亏损
            let totalLoss = 0;
            let gridLosses = [];
            let waitbuy = 0;
            // 从现价到网格顶部逐步买入
            for (let i = 0; i < gridCount; i++) {
                let currentGridPrice = bottomPrice + (i * priceInterval);
                //如果当前网格的购买价大于入场价
                if (currentGridPrice >= entryPrice) {
                    //当前价格除以建仓价
                    let loss = currentPrice > entryPrice ? ((i - waitbuy) * priceInterval / currentGridPrice) * investment : (currentPrice / entryPrice - 1) * investment;
                    totalLoss += loss;
                    gridLosses.push({
                        grid: i + 1,
                        price: entryPrice.toFixed(2),
                        loss: loss.toFixed(2)
                    });
                } else { //如果当前网格的购买价小于入场价
                    waitbuy++;
                    //如果当前网格的标记价格低于当前币价,则不统计盈亏,因为没有购买,所以不会产生盈亏
                    if(currentGridPrice<=currentPrice){
                        continue;
                    }
                    let loss = currentPrice > entryPrice ? 0 : (currentPrice / currentGridPrice - 1) * investment;
                    totalLoss += loss;
                    
                    gridLosses.push({
                        grid: i + 1,
                        price: currentGridPrice.toFixed(2),
                        loss: loss.toFixed(2)
                    });
                }
            }

            // 构建结果输出
            let resultHtml = `
                <p>网格间距: ${priceInterval} 元</p>
                <p>网格数量: ${gridCount}</p>
                <p>每格投入资金: ${investment} 元</p>
                <p>网格创建时的入场价: ${entryPrice} 元</p>
                <p>当前价格: ${currentPrice} 元</p>
                <h3>总赢损: ${totalLoss.toFixed(2)} 元</h3>
                <h4>每格赢亏情况:</h4>
                <ul>
            `;

            gridLosses.forEach(grid => {
                resultHtml += `
                    <li>网格 ${grid.grid}: 价格 ${grid.price} 元, 亏损 ${grid.loss} 元</li>
                `;
            });

            resultHtml += `</ul>`;

            document.getElementById('result').innerHTML = resultHtml;
        }
    </script>
</body>

</html>