<?php
include 'session.php';


// Initialize variables
$pairs = [];
$selected_pair = 0;

// Get active trading pairs
$pair_query = $conn->query("SELECT id, pair_name FROM trading_pairs WHERE status = 'active'");
if (!$pair_query) {
    die("<script>alert('Database error loading trading pairs.'); window.location.href = 'trading.php';</script>");
}
while ($row = $pair_query->fetch_assoc()) {
    $pairs[$row['id']] = $row['pair_name'];
}

if ($_SERVER['REQUEST_METHOD'] == "POST") {
    try {

        
        // Validate btc_bal_demo is set
        if (!isset($btc_usdt_demo)) {
            throw new Exception("User btc_bal_demo not available");
        }
        
        // Sanitize input data
        $pair = (int)($_POST['trading_pair'] ?? 0);
        $trade_time = (int)($_POST['trade_time'] ?? 1);
        $leverage = (float)($_POST['leverage'] ?? 1);
        
        // Determine trade type and get amount
        if (isset($_POST['market_buy'])) {
            $type = 'buy';
            $order_type = 'market';
            $amount_input = $_POST['market_buy_price'] ?? '';
        } elseif (isset($_POST['market_sell'])) {
            $type = 'sell';
            $order_type = 'market';
            $amount_input = $_POST['market_sell_price'] ?? '';
        } elseif (isset($_POST['limit_buy'])) {
            $type = 'buy';
            $order_type = 'limit';
            $amount_input = $_POST['limit_buy_price'] ?? '';
        } elseif (isset($_POST['limit_sell'])) {
            $type = 'sell';
            $order_type = 'limit';
            $amount_input = $_POST['limit_sell_price'] ?? '';
        } else {
            throw new Exception("Invalid trade type submitted");
        }

        // Validate and clean amount
        $cleaned_amount = preg_replace('/[^0-9.]/', '', $amount_input);
        $amount = (float)$cleaned_amount;

        if ($amount <= 0 || !is_numeric($cleaned_amount) || $amount_input === '') {
            throw new Exception("Invalid amount: " . htmlspecialchars($amount_input));
        }

        if (!array_key_exists($pair, $pairs)) {
            throw new Exception("Invalid trading pair selected: $pair");
        }

        if ($btc_usdt_demo < $amount) {
            throw new Exception("Insufficient btc_bal_demo. Available: $btc_usdt_demo, Needed: $amount");
        }

        // Get TP/SL values
        $take_profit = (float)($_POST['tp'] ?? 0);
        $stop_loss = (float)($_POST['sl'] ?? 0);

        $mode = 'live';
        $earnings = $amount * $leverage * 0.1;
        $expires_at = date('Y-m-d H:i:s', strtotime("+{$trade_time} hours"));

        $conn->begin_transaction();

        // Escape all values for SQL query
        $escaped_user_id = $conn->real_escape_string($user_id);
        $escaped_pair = $conn->real_escape_string($pair);
        $escaped_type = $conn->real_escape_string($type);
        $escaped_order_type = $conn->real_escape_string($order_type);
        $escaped_amount = $conn->real_escape_string($amount);
        $escaped_leverage = $conn->real_escape_string($leverage);
        $escaped_take_profit = $conn->real_escape_string($take_profit);
        $escaped_stop_loss = $conn->real_escape_string($stop_loss);
        $escaped_mode = $conn->real_escape_string($mode);
        $escaped_earnings = $conn->real_escape_string($earnings);
        $escaped_expires_at = $conn->real_escape_string($expires_at);

        // Build and execute SQL query
        $sql = "INSERT INTO orders (user_id, pair_id, `type`, order_type, amount, leverage, take_profit, stop_loss, mode, status, amount_end, created_at, expires_at) 
                VALUES (
                    '$escaped_user_id',
                    '$escaped_pair',
                    '$escaped_type',
                    '$escaped_order_type',
                    '$escaped_amount',
                    '$escaped_leverage',
                    '$escaped_take_profit',
                    '$escaped_stop_loss',
                    '$escaped_mode',
                    'open',
                    '$escaped_earnings',
                    NOW(),
                    '$escaped_expires_at'
                )";
        
        if (!$conn->query($sql)) {
            throw new Exception("Execute failed: " . $conn->error);
        }

        // Update user btc_bal_demo
        $new_btc_bal_demo = $btc_usdt_demo - $amount;
        $escaped_new_btc_bal_demo = $conn->real_escape_string($new_btc_bal_demo);
        $escaped_user_id = $conn->real_escape_string($user_id);
        
        $update_sql = "UPDATE users SET btc_bal_demo = '$escaped_new_btc_bal_demo' WHERE id = '$escaped_user_id'";
        if (!$conn->query($update_sql)) {
            throw new Exception("btc_bal_demo update failed: " . $conn->error);
        }

        $conn->commit();
       
        
        // Success
        die("<script>alert('Trade placed successfully!'); window.location.href = 'trading.php';</script>");
        
    } catch (Exception $e) {
        // Rollback transaction if active
        if (isset($conn) && $conn instanceof mysqli && $conn->thread_id) {
            $conn->rollback();
        }
        
        // Log detailed error
        error_log("TRADE ERROR [" . date('Y-m-d H:i:s') . "] " . $e->getMessage() . "\n" . $e->getTraceAsString());
        
        // User-friendly message
        $error_message = "Error placing trade: " . $e->getMessage();
        die("<script>alert('".addslashes($error_message)."'); window.location.href = 'trading.php';</script>");
    }
}
?>
<!DOCTYPE html>
<html lang="en">

<head class="crypt-dark">

    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title> Trade BTC/USDT |
        <?php echo $sitename ?>
    </title>


    <link rel="stylesheet" href="trading/bootstrap.min.css">
    <link rel="stylesheet" href="trading/style.css">
    <link rel="stylesheet" href="trading/icons.css">
    <link rel="stylesheet" href="trading/ui.css">
</head>

<body class="crypt-dark" id="body">
      <header>
        <div class="container-full-width">
            <div class="crypt-header">
                <div class="row">
                    <div class="col-xl-4 col-lg-4 col-md-4 col-sm-5">
                        <div class="row">
                            <div class="col-xs-2">
                                <div class="crypt-logo"><img
                                        src="image/logo-rec.png"
                                        alt=""></div>
                            </div>
                            <div class="col-xs-2">
                                <div class="crypt-mega-dropdown-menu"> <a href=""
                                        class="crypt-mega-dropdown-toggle">BTC/USDT <span
                                            style="background-color: red; padding: 5px; font-size: 11px; border-radius: 10px 0px 10px 0px">demo</span></a>

                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-xl-8 col-lg-8 col-md-8 d-none d-md-block d-lg-block">
                        <ul class="crypt-heading-menu fright">
                            <li><a href="dashboard.php">Dashboard</a></li>


                        </ul>
                    </div><i class="menu-toggle pe-7s-menu d-xs-block d-sm-block d-md-none d-sm-none"></i>
                </div>
            </div>
        </div>
        <div class="crypt-mobile-menu">
            <ul class="crypt-heading-menu">
                <li><a href="dashboard.php">Dashboard</a></li>

            </ul>

        </div>
    </header>
    <div class="container-fluid">
        <div class="row sm-gutters">
            <div class="col-md-6 col-lg-6 col-xl-3 col-xxl-2">
                <div class="crypt-market-status mt-4">
                    <div>

                        <ul class="nav nav-tabs">

                            <div>
                                <input type="text" name="" id="filter-input" class="form-control"
                                    placeholder="Search Pair">
                            </div>

                        </ul>
                        <div class="tab-content crypt-tab-content" style="max-height: 900px;overflow-y: scroll"
                            id="filter-div">
                            <div role="tabpanel" class="tab-pane active" id="usdt">
                                <table class="table table-striped" id="usdt-table">
                                    <thead>
                                        <tr>
                                            <th scope="col">Coin</th>
                                            <th scope="col">Price</th>
                                            <th scope="col">Change</th>
                                        </tr>
                                    </thead>
                                    <tbody class="crypt-table-hover">
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/btc.svg" width="15">
                                                <a href="trading.php">BTC/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    107491.56
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="9">
                                                <span class=" crypt-down ">
                                                    -0.0133%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/dash.svg" width="15">
                                                <a href="#">DASH/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    23.06
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="4">
                                                <span class=" crypt-down ">
                                                    -0.0141%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/ltc.svg" width="15">
                                                <a href="#">LTC/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    94.251
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="18">
                                                <span class=" crypt-down ">
                                                    -0.0231%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/xlm.svg" width="15">
                                                <a href="#">XLM/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.2828
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="1">
                                                <span class=" crypt-down ">
                                                    -0.0136%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/xmr.svg" width="15">
                                                <a href="#">XMR/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    413.16
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="11">
                                                <span class=" crypt-up ">
                                                    0.036%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/xrp.svg" width="15">
                                                <a href="#">XRP/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    2.3021
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="8">
                                                <span class=" crypt-down ">
                                                    -0.0188%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/eth.svg" width="15">
                                                <a href="#">ETH/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    2517.74
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="10">
                                                <span class=" crypt-down ">
                                                    -0.0132%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/etc.svg" width="15">
                                                <a href="#">ETC/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    18.029
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="2">
                                                <span class=" crypt-down ">
                                                    -0.0266%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/zec.svg" width="15">
                                                <a href="#">ZEC/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    42
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="13">
                                                <span class=" crypt-up ">
                                                    0.0267%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/eos.svg" width="15">
                                                <a href="#">EOS/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.7469
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="10">
                                                <span class=" crypt-up ">
                                                    0.017%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/bat.svg" width="15">
                                                <a href="#">BAT/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.1415
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="7">
                                                <span class=" crypt-down ">
                                                    -0.007%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/doge.svg" width="15">
                                                <a href="#">DOGE/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.219348
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="7">
                                                <span class=" crypt-down ">
                                                    -0.0346%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/lsk.svg" width="15">
                                                <a href="#">LSK/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.4876
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="6">
                                                <span class=" crypt-down ">
                                                    -0.0574%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/sc.svg" width="15">
                                                <a href="#">SC/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.003395
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="9">
                                                <span class=" crypt-down ">
                                                    -0.0289%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="/public/assets/imgs/crypto-svg-icons/zrx.svg" width="15">
                                                <a href="#">ZRX/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.2532
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="17">
                                                <span class=" crypt-down ">
                                                    -0.0328%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/qtum.svg" width="15">
                                                <a href="#">QTUM/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    2.182
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="9">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/mana.svg" width="15">
                                                <a href="#">MANA/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.307
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="14">
                                                <span class=" crypt-down ">
                                                    -0.0245%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/atom.svg" width="15">
                                                <a href="#">ATOM/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    4.715
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="15">
                                                <span class=" crypt-down ">
                                                    -0.0076%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/trx.svg" width="15">
                                                <a href="#">TRX/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.27067
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="7">
                                                <span class=" crypt-down ">
                                                    -0.0005%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/btt.svg" width="15">
                                                <a href="#">BTT/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0000007179
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="1">
                                                <span class=" crypt-down ">
                                                    -0.0072%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/xtz.svg" width="15">
                                                <a href="#">XTZ/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.6
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="11">
                                                <span class=" crypt-down ">
                                                    -0.0244%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/snx.svg" width="15">
                                                <a href="#">SNX/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.757
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="17">
                                                <span class=" crypt-down ">
                                                    -0.0723%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/mkr.svg" width="15">
                                                <a href="#">MKR/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    1631.69
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="1">
                                                <span class=" crypt-down ">
                                                    -0.0188%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/dai.svg" width="15">
                                                <a href="#">DAI/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.989
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="6">
                                                <span class=" crypt-up ">
                                                    0.001%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/neo.svg" width="15">
                                                <a href="#">NEO/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    6.46
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="11">
                                                <span class=" crypt-down ">
                                                    -0.0444%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/steem.svg"
                                                    width="15">
                                                <a href="#">STEEM/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.14356
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="14">
                                                <span class=" crypt-down ">
                                                    -0.0388%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/link.svg" width="15">
                                                <a href="#">LINK/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    15.0971
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="15">
                                                <span class=" crypt-down ">
                                                    -0.0229%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/bnb.svg" width="15">
                                                <a href="#">BNB/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    667.79
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="2">
                                                <span class=" crypt-down ">
                                                    -0.0102%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/comp.svg" width="15">
                                                <a href="#">COMP/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    47.82
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="18">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/ren.svg" width="15">
                                                <a href="#">REN/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0125
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="4">
                                                <span class=" crypt-up ">
                                                    0.0504%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/lrc.svg" width="15">
                                                <a href="#">LRC/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.1012
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="3">
                                                <span class=" crypt-down ">
                                                    -0.0269%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/bal.svg" width="15">
                                                <a href="#">BAL/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    1.155
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="10">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/yfi.svg" width="15">
                                                <a href="#">YFI/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    5365.78
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="5">
                                                <span class=" crypt-down ">
                                                    -0.0126%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/uma.svg" width="15">
                                                <a href="#">UMA/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    1.098
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="11">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/band.svg" width="15">
                                                <a href="#">BAND/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.8246
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="19">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/crv.svg" width="15">
                                                <a href="#">CRV/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.7599
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="8">
                                                <span class=" crypt-down ">
                                                    -0.0341%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/dot.svg" width="15">
                                                <a href="#">DOT/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    4.429
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="11">
                                                <span class=" crypt-down ">
                                                    -0.034%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/sushi.svg"
                                                    width="15">
                                                <a href="#">SUSHI/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.7079
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="19">
                                                <span class=" crypt-down ">
                                                    -0.0863%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/uni.svg" width="15">
                                                <a href="#">UNI/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    6.0204
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="5">
                                                <span class=" crypt-down ">
                                                    -0.0252%
                                                </span>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/sand.svg" width="15">
                                                <a href="#">SAND/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.2994
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="1">
                                                <span class=" crypt-down ">
                                                    -0.0254%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/aave.svg" width="15">
                                                <a href="#">AAVE/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    262.14
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="3">
                                                <span class=" crypt-down ">
                                                    -0.0075%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/bch.svg" width="15">
                                                <a href="#">BCH/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    413.72
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="3">
                                                <span class=" crypt-down ">
                                                    -0.0262%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/grt.svg" width="15">
                                                <a href="#">GRT/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.1053
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="6">
                                                <span class=" crypt-down ">
                                                    -0.0357%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star" src="image/tusd.svg" width="15">
                                                <a href="#">TUSD/USDT</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.9978
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="10">
                                                <span class=" crypt-up ">
                                                    0.0003%
                                                </span>
                                            </td>
                                        </tr>


                                    </tbody>
                                </table>
                            </div>
                            <div role="tabpanel" class="tab-pane" id="btc">
                                <table class="table table-striped" id="btc-table">
                                    <thead>
                                        <tr>
                                            <th scope="col">Coin</th>
                                            <th scope="col">Price</th>
                                            <th scope="col">Change</th>
                                        </tr>
                                    </thead>
                                    <tbody class="crypt-table-hover">
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/dash.svg" width="15">
                                                <a href="#">DASH/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000214
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="11">
                                                <span class=" crypt-down ">
                                                    -0.0047%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/doge.svg" width="15">
                                                <a href="#">DOGE/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000002041
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="17">
                                                <span class=" crypt-down ">
                                                    -0.0202%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/ltc.svg" width="15">
                                                <a href="#">LTC/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000879
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="17">
                                                <span class=" crypt-down ">
                                                    -0.0068%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/xlm.svg" width="15">
                                                <a href="#">XLM/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000002631
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="16">
                                                <span class=" crypt-down ">
                                                    -0.0338%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/xem.svg" width="15">
                                                <a href="#">XEM/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000000092
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="1">
                                                <span class=" crypt-down ">
                                                    -0.1068%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/xmr.svg" width="15">
                                                <a href="#">XMR/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.00384
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="16">
                                                <span class=" crypt-up ">
                                                    0.0353%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/xrp.svg" width="15">
                                                <a href="#">XRP/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.00002141
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="4">
                                                <span class=" crypt-down ">
                                                    -0.0065%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/eth.svg" width="15">
                                                <a href="#">ETH/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0234
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="8">
                                                <span class=" crypt-down ">
                                                    -0.003%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/sc.svg" width="15">
                                                <a href="#">SC/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0000000321
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="19">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/dcr.svg" width="15">
                                                <a href="#">DCR/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000109
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="14">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/steem.svg" width="15">
                                                <a href="#">STEEM/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.00000134
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="17">
                                                <span class=" crypt-down ">
                                                    -0.0074%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/etc.svg" width="15">
                                                <a href="#">ETC/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000168
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="10">
                                                <span class=" crypt-down ">
                                                    -0.0175%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/ardr.svg" width="15">
                                                <a href="#">ARDR/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0000009
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="10">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/zec.svg" width="15">
                                                <a href="#">ZEC/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000383
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="4">
                                                <span class=" crypt-up ">
                                                    0.0052%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/cvc.svg" width="15">
                                                <a href="#">CVC/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000000969
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="11">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/gas.svg" width="15">
                                                <a href="#">GAS/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0000189
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="11">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/eos.svg" width="15">
                                                <a href="#">EOS/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.00000699
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="6">
                                                <span class=" crypt-up ">
                                                    0.0295%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/bat.svg" width="15">
                                                <a href="#">BAT/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.00000145
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="15">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/qtum.svg" width="15">
                                                <a href="#">QTUM/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0000213
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="11">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/mana.svg" width="15">
                                                <a href="#">MANA/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.00000283
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="7">
                                                <span class=" crypt-down ">
                                                    -0.0374%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/poly.svg" width="15">
                                                <a href="#">POLY/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000001001
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="1">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/atom.svg" width="15">
                                                <a href="#">ATOM/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0000438
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="20">
                                                <span class=" crypt-down ">
                                                    -0.0023%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/trx.svg" width="15">
                                                <a href="#">TRX/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000002506
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="6">
                                                <span class=" crypt-down ">
                                                    -0.004%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/link.svg" width="15">
                                                <a href="#">LINK/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0001403
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="6">
                                                <span class=" crypt-down ">
                                                    -0.0141%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/mkr.svg" width="15">
                                                <a href="#">MKR/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.01503
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="8">
                                                <span class=" crypt-down ">
                                                    -0.0046%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/neo.svg" width="15">
                                                <a href="#">NEO/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0000602
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="15">
                                                <span class=" crypt-down ">
                                                    -0.0275%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/amp.svg" width="15">
                                                <a href="#">AMP/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0000000342
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="16">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/sand.svg" width="15">
                                                <a href="#">SAND/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.00000276
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="10">
                                                <span class=" crypt-down ">
                                                    -0.045%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/aave.svg" width="15">
                                                <a href="#">AAVE/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.002396
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="6">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/bch.svg" width="15">
                                                <a href="#">BCH/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.003862
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="12">
                                                <span class=" crypt-down ">
                                                    -0.0168%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/dot.svg" width="15">
                                                <a href="#">DOT/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0000412
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="20">
                                                <span class=" crypt-down ">
                                                    -0.0167%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/fil.svg" width="15">
                                                <a href="#">FIL/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0000287
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="5">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/avax.svg" width="15">
                                                <a href="#">AVAX/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000208
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="12">
                                                <span class=" crypt-down ">
                                                    -0.0142%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/sol.svg" width="15">
                                                <a href="#">SOL/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.001599
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="14">
                                                <span class=" crypt-down ">
                                                    -0.019%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/ada.svg" width="15">
                                                <a href="#">ADA/BTC</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.00000695
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="13">
                                                <span class=" crypt-up ">
                                                    0.0058%
                                                </span>
                                            </td>
                                        </tr>

                                    </tbody>
                                </table>
                            </div>
                            <div role="tabpanel" class="tab-pane" id="eth">
                                <table class="table table-striped" id="eth-table">
                                    <thead>
                                        <tr>
                                            <th scope="col">Coin</th>
                                            <th scope="col">Price</th>
                                            <th scope="col">Change</th>
                                        </tr>
                                    </thead>
                                    <tbody class="crypt-table-hover">
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/etc.svg" width="15">
                                                <a href="#">ETC/ETH</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.00712
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="6">
                                                <span class=" crypt-down ">
                                                    -0.0247%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/zec.svg" width="15">
                                                <a href="#">ZEC/ETH</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.01594
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="16">
                                                <span class=" crypt-down ">
                                                    -0.0298%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/zrx.svg" width="15">
                                                <a href="#">ZRX/ETH</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.0001014
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="14">
                                                <span class=" crypt-down ">
                                                    -0.0203%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/comp.svg" width="15">
                                                <a href="#">COMP/ETH</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.01844
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="5">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>

                                    </tbody>
                                </table>
                            </div>

                            <div role="tabpanel" class="tab-pane" id="trx">
                                <table class="table table-striped" id="trx-table">
                                    <thead>
                                        <tr>
                                            <th scope="col">Coin</th>
                                            <th scope="col">Price</th>
                                            <th scope="col">Change</th>
                                        </tr>
                                    </thead>
                                    <tbody class="crypt-table-hover">
                                        <tr>
                                            <td class="align-middle">

                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/eth.svg" width="15">
                                                <a href="#">ETH/TRX</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    9204.6
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="10">
                                                <span class=" crypt-down ">
                                                    -0.0147%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">

                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/xrp.svg" width="15">
                                                <a href="#">XRP/TRX</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    8.487
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="8">
                                                <span class=" crypt-down ">
                                                    -0.0255%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">

                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/btt.svg" width="15">
                                                <a href="#">BTT/TRX</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.00000264
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="19">
                                                <span class=" crypt-down ">
                                                    -0.0038%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">

                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/steem.svg" width="15">
                                                <a href="#">STEEM/TRX</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.522
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="17">
                                                <span class=" crypt-down ">
                                                    -0.0188%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">

                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/link.svg" width="15">
                                                <a href="#">LINK/TRX</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    51.25
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="5">
                                                <span class=" crypt-down ">
                                                    -0.1227%
                                                </span>
                                            </td>
                                        </tr>

                                    </tbody>
                                </table>
                            </div>

                            <div role="tabpanel" class="tab-pane" id="usdd">
                                <table class="table table-striped" id="usdd-table">
                                    <thead>
                                        <tr>
                                            <th scope="col">Coin</th>
                                            <th scope="col">Price</th>
                                            <th scope="col">Change</th>
                                        </tr>
                                    </thead>
                                    <tbody class="crypt-table-hover">
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/btc.svg" width="15">
                                                <a href="#">BTC/USDD</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    106875.3
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="9">
                                                <span class=" crypt-down ">
                                                    -0.0104%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/eth.svg" width="15">
                                                <a href="#">ETH/USDD</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    2480.01
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="9">
                                                <span class=" crypt-down ">
                                                    -0.008%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/trx.svg" width="15">
                                                <a href="#">TRX/USDD</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.276
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="5">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/btt.svg" width="15">
                                                <a href="#">BTT/USDD</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    0.000000706
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="13">
                                                <span class=" crypt-down ">
                                                    -0.0245%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/xrp.svg" width="15">
                                                <a href="#">XRP/USDD</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    2.2977
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="1">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/ltc.svg" width="15">
                                                <a href="#">LTC/USDD</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    93.95
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="11">
                                                <span class=" crypt-down ">
                                                    -0.0111%
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="align-middle">
                                                <img class="crypt-star pr-1" alt="star"
                                                    src="tradingimgs/crypto-svg-icons/dot.svg" width="15">
                                                <a href="#">DOT/USDD</a>
                                            </td>
                                            <td>
                                                <span class="d-block">
                                                    4.896
                                                </span>
                                            </td>

                                            <td class="flash" data-flash="18">
                                                <span class=" crypt-up ">
                                                    0.00%
                                                </span>
                                            </td>
                                        </tr>

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-6 col-lg-6 col-xl-6 col-xxl-8">
                <div class="crypt-gross-market-cap mt-4">
                    <div class="row">
                        <div class="col-3 col-sm-6 col-md-6 col-lg-6">
                            <div class="row">
                                <div class="col-sm-6 col-md-6 col-lg-6">
                                    <p>Last Price USDT</p>
                                    <p id="last-price">107491.59</p>
                                </div>
                                <div class="col-sm-6 col-md-6 col-lg-6">
                                    <p>Change USDT</p>
                                    <p class=" crypt-down ">
                                        -0.0133%</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-3 col-sm-2 col-md-3 col-lg-2">
                            <p>High USDT</p>
                            <p class="crypt-up">109000</p>
                        </div>
                        <div class="col-3 col-sm-2 col-md-3 col-lg-2">
                            <p>Low USDT</p>
                            <p class="crypt-down">109000</p>
                        </div>
                        <div class="col-3 col-sm-2 col-md-3 col-lg-2">
                            <p>Volume 24Hr</p>
                            <p class=" crypt-down ">
                                155752</p>
                        </div>
                    </div>
                </div>
                <div class="tradingview-widget-container mb-3">
                    <div id="crypt-candle-chart"></div>
                </div>
                <div class="crypt-dark-segment">
                    <div class="">
                        <div class="crypt-boxed-area">
                            <h6 class="crypt-bg-head">
                                <b class="crypt-up">BUY</b> / <b class="crypt-down">SELL</b>
                            </h6>

                            <!-- Display messages -->
                            <?php if ($error): ?>
                            <div class="alert alert-danger">
                                <?php echo $error; ?>
                            </div>
                            <?php endif; ?>
                            <?php if ($success): ?>
                            <div class="alert alert-success">
                                <?php echo $success; ?>
                            </div>
                            <?php endif; ?>

                            <ul class="nav nav-tabs">
                                <li role="presentation"><a href="#limit" data-toggle="tab" class="active">Limit</a></li>
                                <li role="presentation"><a href="#market" data-toggle="tab">Market</a></li>
                            </ul>

                                        <form method="post">
                <div class="tab-content">
                    
                    <div class="form-group">
                        <select name="trading_pair" id="trading_pair" class="form-control" required>
                            <?php foreach ($pairs as $id => $name): ?>
                            <option value="<?php echo $id; ?>" <?php echo $selected_pair == $id ? 'selected' : ''; ?>>
                                <?php echo htmlspecialchars($name); ?>
                            </option>
                            <?php endforeach; ?>
                        </select>
                    </div>

                    <!-- Trade Time Selection -->
                    <div class="form-group">
                        <select name="trade_time" id="trade_time" class="form-control" required>
                            <option value="1">1 Hour</option>
                            <option value="24">24 Hours</option>
                            <option value="48">48 Hours</option>
                        </select>
                    </div>

                    <!-- Market Tab -->
                    <div role="tabpanel" class="tab-pane" id="market">
                        <div class="row no-gutters">
                            <!-- Market Buy -->
                            <div class="col-md-6">
                                <div class="crypt-buy-sell-form">
                                    <p>Buy <span class="crypt-up">USDT</span> <span
                                            class="fright">Available: <b class="crypt-up">
                                                <?php echo number_format($btc_usdt_demo, 2); ?> USDT
                                            </b></span></p>
                                    <div class="crypt-buy">
                                        <div class="input-group mb-3">
                                            <div class="input-group-prepend"><span
                                                    class="input-group-text">Price</span></div>
                                            <input type="text" value="20" name="market_buy_price"
                                                class="form-control">
                                            <div class="input-group-append"><span
                                                    class="input-group-text">USDT</span></div>
                                        </div>
                                        
                                        

                                        <div class="input-group mb-3">
                                            <div class="input-group-prepend">
                                                <span class="input-group-text">
                                                    <span>Leverage: &nbsp;</span>
                                                    <span id="market-buy-range">25%</span>
                                                </span>
                                            </div>
                                            <div class="input-group-prepend">
                                                <input type="range" name="leverage" min="1" max="100"
                                                    value="25" class="range-input"
                                                    data-target="market-buy-range">
                                            </div>
                                        </div>

                                        <div class="input-group mb-3">
                                            <span class="input-group-text">
                                                <input type="checkbox" class="toggle-tp" checked
                                                    data-toggle="market-buy-tp">TP/SL
                                            </span>
                                        </div>

                                        <div id="market-buy-tp" class="">
                                            <div class="input-group mb-3">
                                                <div class="input-group-prepend"><span
                                                        class="input-group-text">Take Profit</span>
                                                </div>
                                                <input type="number" name="tp" step="any"
                                                    class="form-control tp">
                                            </div>
                                            <div class="input-group mb-3">
                                                <div class="input-group-prepend"><span
                                                        class="input-group-text">Stop Loss</span></div>
                                                <input type="number" name="sl" step="any"
                                                    class="form-control sl">
                                            </div>
                                        </div>

                                        <div class="menu-green order-button" data-order="market"
                                            data-type="buy">
                                            <button name="market_buy" class="crypt-button-green-full"
                                                type="submit">Buy/Long</button>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <!-- Market Sell -->
                            <div class="col-md-6">
                                <div class="crypt-buy-sell-form">
                                    <p>Sell <span class="crypt-down">USDT</span> <span
                                            class="fright">Available: <b class="crypt-down">
                                                <?php echo number_format($btc_usdt_demo, 2); ?> USDT
                                            </b></span></p>
                                    <div class="crypt-sell">
                                        <div class="input-group mb-3">
                                            <div class="input-group-prepend"><span
                                                    class="input-group-text">Price</span></div>
                                            <input type="text" name="market_sell_price"
                                                class="form-control">
                                            <div class="input-group-append"><span
                                                    class="input-group-text">USDT</span></div>
                                        </div>

                                        <div class="input-group mb-3">
                                            <div class="input-group-prepend">
                                                <span class="input-group-text">
                                                    <span>Leverage: &nbsp;</span>
                                                    <span id="market-sell-range">25%</span>
                                                </span>
                                            </div>
                                            <div class="input-group-prepend">
                                                <input type="range" name="leverage" min="1" max="100"
                                                    value="25" class="range-input"
                                                    data-target="market-sell-range">
                                            </div>
                                        </div>

                                        <div class="input-group mb-3">
                                            <span class="input-group-text">
                                                <input type="checkbox" class="toggle-tp" checked
                                                    data-toggle="market-sell-tp">TP/SL
                                            </span>
                                        </div>

                                        <div id="market-sell-tp" class="">
                                            <div class="input-group mb-3">
                                                <div class="input-group-prepend"><span
                                                        class="input-group-text">Take Profit</span>
                                                </div>
                                                <input type="number" name="tp" step="any"
                                                    class="form-control tp">
                                            </div>
                                            <div class="input-group mb-3">
                                                <div class="input-group-prepend"><span
                                                        class="input-group-text">Stop Loss</span></div>
                                                <input type="number" name="sl" step="any"
                                                    class="form-control sl">
                                            </div>
                                        </div>

                                        <div class="order-button" data-order="market" data-type="sell">
                                            <button name="market_sell" class="crypt-button-red-full"
                                                type="submit">Sell/Short</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Limit Tab -->
                    <div role="tabpanel" class="tab-pane active" id="limit">
                        <div class="row no-gutters">
                            <!-- Limit Buy -->
                            <div class="col-md-6">
                                <div class="crypt-buy-sell-form">
                                    <p>Buy <span class="crypt-up">USDT</span> <span
                                            class="fright">Available: <b class="crypt-up">
                                                <?php echo number_format($btc_usdt_demo, 2); ?> USDT
                                            </b></span></p>
                                    <div class="crypt-buy">
                                        <div class="input-group mb-3">
                                            <div class="input-group-prepend"><span
                                                    class="input-group-text">Price</span></div>
                                            <input type="text" name="limit_buy_price"
                                                class="form-control">
                                            <div class="input-group-append"><span
                                                    class="input-group-text">USDT</span></div>
                                        </div>

                                        <div class="order-button" data-order="limit" data-type="buy">
                                            <button name="limit_buy" class="crypt-button-green-full"
                                                type="submit">Buy</button>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <!-- Limit Sell -->
                            <div class="col-md-6">
                                <div class="crypt-buy-sell-form">
                                    <p>Sell <span class="crypt-down">USDT</span> <span
                                            class="fright">Available: <b class="crypt-down">
                                                <?php echo number_format($btc_usdt_demo, 8); ?> USDT
                                            </b></span></p>
                                    <div class="crypt-sell">
                                        <div class="input-group mb-3">
                                            <div class="input-group-prepend"><span
                                                    class="input-group-text">Price</span></div>
                                            <input type="text" name="limit_sell_price"
                                                class="form-control">
                                            <div class="input-group-append"><span
                                                    class="input-group-text">USDT</span></div>
                                        </div>

                                        <div class="order-button" data-order="limit" data-type="sell">
                                            <button name="limit_sell" class="crypt-button-red-full"
                                                type="submit">Sell</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-6 col-lg-6 col-xl-3 col-xxl-2">
                <div class="crypt-market-status mt-4">
                    <div>
                        <ul class="nav nav-tabs">
                            <li role="presentation"><a href="#history" class="active" data-toggle="tab">history</a>
                            </li>
                            <li role="presentation"><a href="#market-trading" data-toggle="tab">market trading</a>
                            </li>
                        </ul>
                        <div class="tab-content">
                            <div role="tabpanel" class="tab-pane active" id="history">
                                <table class="table table-striped" id="history-table">
                                    <thead>
                                        <tr>
                                            <th scope="col">Time</th>
                                            <th scope="col">Price</th>
                                            <th scope="col">Volume</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>15:20:00</td>
                                            <td class="flash  crypt-up " data-flash="11">206196.52</td>
                                            <td>102225.95</td>
                                        </tr>
                                        <tr>
                                            <td>08:00:00</td>
                                            <td class="flash  crypt-up " data-flash="9">162057.81</td>
                                            <td>87344.03</td>
                                        </tr>
                                        <tr>
                                            <td>00:40:00</td>
                                            <td class="flash  crypt-up " data-flash="2">184939.18</td>
                                            <td>86581.86</td>
                                        </tr>
                                        <tr>
                                            <td>17:20:00</td>
                                            <td class="flash  crypt-up " data-flash="5">187689.79</td>
                                            <td>96523.46</td>
                                        </tr>
                                        <tr>
                                            <td>10:00:00</td>
                                            <td class="flash  crypt-up " data-flash="12">187227.35</td>
                                            <td>105143.49</td>
                                        </tr>
                                        <tr>
                                            <td>02:40:00</td>
                                            <td class="flash  crypt-up " data-flash="1">175730.61</td>
                                            <td>88793.59</td>
                                        </tr>
                                        <tr>
                                            <td>19:20:00</td>
                                            <td class="flash  crypt-up " data-flash="13">194852.35</td>
                                            <td>122358.07</td>
                                        </tr>
                                        <tr>
                                            <td>12:00:00</td>
                                            <td class="flash  crypt-up " data-flash="4">200847.77</td>
                                            <td>110246.49</td>
                                        </tr>
                                        <tr>
                                            <td>04:40:00</td>
                                            <td class="flash  crypt-up " data-flash="10">179609.07</td>
                                            <td>104569.06</td>
                                        </tr>
                                        <tr>
                                            <td>21:20:00</td>
                                            <td class="flash  crypt-up " data-flash="11">206193.01</td>
                                            <td>97014.84</td>
                                        </tr>
                                        <tr>
                                            <td>14:00:00</td>
                                            <td class="flash  crypt-up " data-flash="17">210049.8</td>
                                            <td>125062.58</td>
                                        </tr>
                                        <tr>
                                            <td>06:40:00</td>
                                            <td class="flash  crypt-up " data-flash="12">161217.59</td>
                                            <td>83323.4</td>
                                        </tr>
                                        <tr>
                                            <td>23:20:00</td>
                                            <td class="flash  crypt-up " data-flash="9">185225.24</td>
                                            <td>85590.05</td>
                                        </tr>
                                        <tr>
                                            <td>16:00:00</td>
                                            <td class="flash  crypt-up " data-flash="18">184336.1</td>
                                            <td>86706.7</td>
                                        </tr>
                                        <tr>
                                            <td>08:40:00</td>
                                            <td class="flash  crypt-up " data-flash="11">179937</td>
                                            <td>86507.85</td>
                                        </tr>
                                        <tr>
                                            <td>01:20:00</td>
                                            <td class="flash  crypt-up " data-flash="5">184147.27</td>
                                            <td>111325.12</td>
                                        </tr>
                                        <tr>
                                            <td>18:00:00</td>
                                            <td class="flash  crypt-up " data-flash="10">182984.37</td>
                                            <td>111904.63</td>
                                        </tr>
                                        <tr>
                                            <td>10:40:00</td>
                                            <td class="flash  crypt-up " data-flash="15">158986.95</td>
                                            <td>63094.03</td>
                                        </tr>
                                        <tr>
                                            <td>03:20:00</td>
                                            <td class="flash  crypt-up " data-flash="18">181758.66</td>
                                            <td>115441.02</td>
                                        </tr>
                                        <tr>
                                            <td>20:00:00</td>
                                            <td class="flash  crypt-up " data-flash="1">130558.51</td>
                                            <td>72009.39</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            <div role="tabpanel" class="tab-pane" id="market-trading">
                                <table class="table table-striped" id="market-trading-table">
                                    <thead>
                                        <tr>
                                            <th scope="col">Time</th>
                                            <th scope="col">Amount</th>
                                            <th scope="col">Volume</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>09:19:03</td>
                                            <td class="flash  crypt-up " data-flash="13">107491.62</td>
                                            <td>1920.23029968</td>

                                        </tr>
                                        <tr>
                                            <td>09:19:01</td>
                                            <td class="flash  crypt-up " data-flash="7">107491.62</td>
                                            <td>1222.7171775</td>

                                        </tr>
                                        <tr>
                                            <td>08:57:48</td>
                                            <td class="flash  crypt-down " data-flash="8">107491.59</td>
                                            <td>1884.11258952</td>

                                        </tr>
                                        <tr>
                                            <td>08:36:33</td>
                                            <td class="flash  crypt-down " data-flash="14">107491.59</td>
                                            <td>1076.52827385</td>

                                        </tr>
                                        <tr>
                                            <td>08:36:33</td>
                                            <td class="flash  crypt-down " data-flash="14">107491.59</td>
                                            <td>756.41831883</td>

                                        </tr>
                                        <tr>
                                            <td>08:36:32</td>
                                            <td class="flash  crypt-down " data-flash="8">107491.59</td>
                                            <td>1076.52827385</td>

                                        </tr>
                                        <tr>
                                            <td>08:19:05</td>
                                            <td class="flash  crypt-down " data-flash="7">107492.25</td>
                                            <td>686.0155395</td>

                                        </tr>
                                        <tr>
                                            <td>08:19:05</td>
                                            <td class="flash  crypt-up " data-flash="3">107492.25</td>
                                            <td>1158.44397825</td>

                                        </tr>
                                        <tr>
                                            <td>08:19:05</td>
                                            <td class="flash  crypt-up " data-flash="7">107492.25</td>
                                            <td>686.0155395</td>

                                        </tr>
                                        <tr>
                                            <td>08:18:12</td>
                                            <td class="flash  crypt-up " data-flash="12">107493.31</td>
                                            <td>19.13380918</td>

                                        </tr>
                                        <tr>
                                            <td>08:12:19</td>
                                            <td class="flash  crypt-up " data-flash="7">107493.31</td>
                                            <td>0.21498662</td>

                                        </tr>
                                        <tr>
                                            <td>08:12:19</td>
                                            <td class="flash  crypt-up " data-flash="8">107493.3</td>
                                            <td>35.3652957</td>

                                        </tr>
                                        <tr>
                                            <td>08:04:28</td>
                                            <td class="flash  crypt-up " data-flash="13">107492.27</td>
                                            <td>1049.55452428</td>

                                        </tr>
                                        <tr>
                                            <td>08:04:28</td>
                                            <td class="flash  crypt-up " data-flash="14">107492.27</td>
                                            <td>836.39735287</td>

                                        </tr>
                                        <tr>
                                            <td>08:04:26</td>
                                            <td class="flash  crypt-down " data-flash="10">107492.27</td>
                                            <td>1049.55452428</td>

                                        </tr>
                                        <tr>
                                            <td>07:55:42</td>
                                            <td class="flash  crypt-down " data-flash="5">107492.2</td>
                                            <td>1911.1038238</td>

                                        </tr>
                                        <tr>
                                            <td>07:46:07</td>
                                            <td class="flash  crypt-down " data-flash="11">107492.26</td>
                                            <td>1174.24544824</td>

                                        </tr>
                                        <tr>
                                            <td>07:46:05</td>
                                            <td class="flash  crypt-down " data-flash="4">107492.26</td>
                                            <td>1830.48569554</td>

                                        </tr>
                                        <tr>
                                            <td>07:41:00</td>
                                            <td class="flash  crypt-up " data-flash="19">107494.46</td>
                                            <td>19.3490028</td>

                                        </tr>
                                        <tr>
                                            <td>07:24:45</td>
                                            <td class="flash  crypt-down " data-flash="7">107492.89</td>
                                            <td>1305.17867038</td>

                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="container-fluid">
        <div class="row sm-gutters">

            <div class="col-xl-12">
    <div>
        <div class="crypt-market-status">
            <div>
                <ul class="nav nav-tabs">
                    <li role="presentation"><a href="#active-orders" class="active" data-toggle="tab">Active Orders</a></li>
                    <li role="presentation"><a href="#closed-orders" data-toggle="tab">Closed Orders</a></li>
                </ul>
                <div class="tab-content">
                    <!-- Active Orders Tab -->
                    <div role="tabpanel" class="tab-pane active" id="active-orders">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th scope="col">Time</th>
                                    <th scope="col">Pair</th>
                                    <th scope="col">Buy/sell</th>
                                    <th scope="col">Price USDT</th>
                                    <th scope="col">Take Profit</th>
                                    <th scope="col">Stop Loss</th>
                                    <th scope="col">Leverage</th>
                                    <th scope="col">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                // First, get all trading pairs for reference
                                $pairs_query = "SELECT id, pair_name FROM trading_pairs";
                                $pairs_result = $conn->query($pairs_query);
                                $pair_names = [];
                                while ($pair = $pairs_result->fetch_assoc()) {
                                    $pair_names[$pair['id']] = $pair['pair_name'];
                                }

                                // Fetch active orders from database
                                $active_query = "SELECT * FROM orders WHERE user_id = ? AND status IN ('open', 'pending') AND mode = 'live' ORDER BY created_at DESC";
                                $stmt = $conn->prepare($active_query);
                                $stmt->bind_param("i", $user_id);
                                $stmt->execute();
                                $active_orders = $stmt->get_result();
                                
                                if ($active_orders->num_rows > 0) {
                                    while ($order = $active_orders->fetch_assoc()) {
                                        $order_time = date("H:i:s<br>d.m.Y", strtotime($order['created_at']));
                                        $direction_class = ($order['type'] == 'buy') ? 'crypt-up' : 'crypt-down';
                                        $direction_icon = ($order['type'] == 'buy') ? 
                                            '<svg class="w-6 h-6" fill="none" width="15" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"></path></svg>' : 
                                            '<svg class="w-6 h-6" fill="none" width="15" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 14l-7 7m0 0l-7-7m7 7V3"></path></svg>';
                                        $status_class = ($order['status'] == 'filled') ? 'btn-success' : 'btn-warning';
                                        $status_text = ($order['status'] == 'filled') ? 'win' : ucfirst($order['status']);
                                        $pair_name = $pair_names[$order['pair_id']] ?? 'UNKNOWN';
                                ?>
                                <tr>
                                    <td><?php echo $order_time; ?></td>
                                    <td><?php echo strtoupper($pair_name); ?></td>
                                    <td class="<?php echo $direction_class; ?>">
                                        <?php echo $direction_icon . $order['type']; ?>
                                    </td>
                                    <td><?php echo number_format($order['amount'], 2); ?></td>
                                    <td><?php echo $order['take_profit'] ? number_format($order['take_profit'], 2) : '0'; ?></td>
                                    <td><?php echo $order['stop_loss'] ? number_format($order['stop_loss'], 2) : '0'; ?></td>
                                    <td><?php echo $order['leverage']; ?>x</td>
                                    <td>
                                        <span class="btn <?php echo $status_class; ?> rounded p-1">
                                            <?php echo $status_text; ?>
                                        </span>
                                    </td>
                                </tr>
                                <?php
                                    }
                                } else {
                                ?>
                                <tr>
                                    <td colspan="8" class="text-center">
                                        <div class="no-orders">
                                            <img src="trading/images/empty.png" alt="no-orders">
                                            <p>No active orders found</p>
                                        </div>
                                    </td>
                                </tr>
                                <?php } ?>
                            </tbody>
                        </table>
                    </div>

                    <!-- Closed Orders Tab -->
                    <div role="tabpanel" class="tab-pane" id="closed-orders">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th scope="col">Time</th>
                                    <th scope="col">Pair</th>
                                    <th scope="col">Buy/sell</th>
                                    <th scope="col">Price USDT</th>
                                    <th scope="col">Take Profit</th>
                                    <th scope="col">Stop Loss</th>
                                    <th scope="col">Leverage</th>
                                    <th scope="col">Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                // Fetch closed orders from database

                                   $closed_query = "SELECT * FROM orders WHERE user_id = ? AND (status = 'won' OR status = 'loss') AND mode = 'demo' ORDER BY created_at DESC";
                                $stmt = $conn->prepare($closed_query);
                                $stmt->bind_param("i", $user_id);
                                $stmt->execute();
                                $closed_orders = $stmt->get_result();
                                
                                if ($closed_orders->num_rows > 0) {
                                    while ($order = $closed_orders->fetch_assoc()) {
                                        $order_time = date("H:i:s<br>d.m.Y", strtotime($order['created_at']));
                                        $direction_class = ($order['type'] == 'buy') ? 'crypt-up' : 'crypt-down';
                                        $direction_icon = ($order['type'] == 'buy') ? 
                                            '<svg class="w-6 h-6" fill="none" width="15" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"></path></svg>' : 
                                            '<svg class="w-6 h-6" fill="none" width="15" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 14l-7 7m0 0l-7-7m7 7V3"></path></svg>';
                                        $status_class = ($order['status'] == 'filled') ? 'btn-success' : 'btn-warning';
                                        $status_text = ($order['status'] == 'filled') ? 'win' : ucfirst($order['status']);
                                        $pair_name = $pair_names[$order['pair_id']] ?? 'UNKNOWN';
                                ?>
                                <tr>
                                    <td><?php echo $order_time; ?></td>
                                    <td><?php echo strtoupper($pair_name); ?></td>
                                    <td class="<?php echo $direction_class; ?>">
                                        <?php echo $direction_icon . $order['type']; ?>
                                    </td>
                                    <td><?php echo number_format($order['amount'], 2); ?></td>
                                    <td><?php echo $order['take_profit'] ? number_format($order['take_profit'], 2) : '0'; ?></td>
                                    <td><?php echo $order['stop_loss'] ? number_format($order['stop_loss'], 2) : '0'; ?></td>
                                    <td><?php echo $order['leverage']; ?>x</td>
                                    <td>
                                        <span class="btn <?php echo $status_class; ?> rounded p-1">
                                            <?php echo $status_text; ?>
                                        </span>
                                    </td>
                                </tr>
                                <?php
                                    }
                                } else {
                                ?>
                                <tr>
                                    <td colspan="8" class="text-center">
                                        <div class="no-orders">
                                            <img src="trading/images/empty.png" alt="no-orders">
                                            <p>No closed orders found</p>
                                        </div>
                                    </td>
                                </tr>
                                <?php } ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

        </div>
    </div>
    <footer>

    </footer>

    <script src="trading/amc/core.js"></script>
    <script src="trading/amc/charts.js"></script>
    <script src="trading/amc/dark.js"></script>
    <script src="trading/animated.js"></script>
    <script src="trading/jquery.js"></script>
    <script src="trading/popper.min.js"></script>
    <script src="trading/bootstrap.bundle.js"></script>
    <script src="trading/bootstrap.js"></script>
    <script src="trading/main.js"></script>
    <script src="trading/amc.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script src="https://s3.tradingview.com/tv.js"></script>



    <script>
        //flash starts


        //toggle  tp
        $('.toggle-tp').on('click', function () {
            var target_toggle = '#' + $(this).data('toggle');
            $(target_toggle).toggleClass('hidden');
        });

        //range input
        $('.range-input').on('input', function () {
            var target_range = '#' + $(this).data('target');
            var value = $(this).val() + '%';
            $(target_range).html(value);
        });


    </script>


    <script>
        if (document.getElementById('crypt-candle-chart')) {
            new TradingView.widget({
                "autosize": true,
                "symbol": "POLONIEX:" + "BTCUSDT",
                "interval": "1",
                "timezone": "Etc/UTC",
                "theme": "Dark",
                "style": "1",
                "locale": "en",
                "toolbar_bg": "rgba(0, 0, 0, 1)",
                "enable_publishing": false,
                "allow_symbol_change": true,
                "container_id": "crypt-candle-chart"
            });
        }
    </script>




    <style>
        input[type=checkbox] {
            accent-color: #49c279;
        }

        input[type=range] {
            accent-color: #f7614e;
        }

        progress {
            accent-color: black;
        }

        .hidden {
            display: none;
        }

        .error-border {
            border-color: red !important;
        }
    </style>

</body>

</html>