<commit_before><?php

function show_mini_orderbook_table_cell($curr, $price, $have, $want, $depth)
{
    if ($curr == 'BTC') {
        list ($w, $r) = gmp_div_qr(gmp_mul($depth, $have), $want);
        $w = gmp_strval(gmp_cmp($r, 0) ? gmp_sub($w, 1) : $w);
        $h = gmp_strval($depth);
        $p = clean_sql_numstr(bcdiv($have, $want, 8));
    } else {
        list ($h, $r) = gmp_div_qr(gmp_mul($depth, $want), $have);
        $h = gmp_strval(gmp_cmp($r,0) ? gmp_add($h, 1) : $h);
        $w = gmp_strval($depth);
        $p = clean_sql_numstr(bcdiv($want, $have, 8));
    }

    active_table_cell(internal_to_numstr($depth, BTC_PRECISION), "?page=trade&in=$curr&have=$h&want=$w&rate=$p", 'right');
}

function show_mini_orderbook_table_row($curr, $price, $have, $want, $this_btc, $sum_btc)
{
    echo "<tr>";
    echo "<td class='right'>$price</td>";
    show_mini_orderbook_table_cell($curr, $price, $have, $want, $this_btc);
    show_mini_orderbook_table_cell($curr, $price, $have, $want, $sum_btc);
    echo "</tr>\n";
}

function show_mini_orderbook_table($bids)
{
    global $buy, $sell;

    echo "<table class='display_data'>";
    echo "<tr><th colspan=3 style='text-align: center;'>" .
        ($bids
         ? sprintf(_("People Buying BTC for %s"),   CURRENCY)
         : sprintf(_("People Selling BTC for %s" ), CURRENCY)) .
        "</th></tr>" .
        "<tr><th valign='bottom' class='right'>" .
        sprintf(_("Price<br/>(%s per BTC)"), CURRENCY) . "</th>" .
        "<th valign='bottom' class='right'>" . _("Depth<br/>(in BTC)") . "</th>" .
        "<th valign='bottom' class='right'>" . _("Cumulative<br/>Depth<br/>(in BTC)") . "</th>" .
        "</tr>";

    $limit = '';
    if ($bids) {
        $price = "amount/want_amount";
        $amount = "want_amount";
        $want_type = "BTC";
        $order = "DESC";
        if ($buy) $limit = "AND $price > " . $buy * (1 - ORDERBOOK_PRICE_RANGE_PERCENTAGE/100);
    } else {
        $price = "want_amount/amount";
        $amount = "amount";
        $want_type = CURRENCY;
        $order = "ASC";
        if ($sell) $limit = "AND $price < " . $sell * (1 + ORDERBOOK_PRICE_RANGE_PERCENTAGE/100);
    }

    $result = do_query("
        SELECT
            amount,
            want_amount
        FROM
            orderbook
        WHERE
            want_type = '$want_type' AND
            status='OPEN'
            $limit
        ORDER BY
            $price $order, timest ASC
    ");

    $last_price = $btc_amount_at_price = $total_btc_amount = "0";
    while ($row = mysql_fetch_array($result)) {
        $have_amount = $row['amount'];
        $want_amount = $row['want_amount'];

        if ($bids) {
            $btc_amount  = $want_amount;
            $fiat_amount = $have_amount;
        } else {
            $btc_amount  = $have_amount;
            $fiat_amount = $want_amount;
        }

        $price = fiat_and_btc_to_price($fiat_amount, $btc_amount, $bids ? 'down' : 'up');

        if ($price == $last_price)
            $btc_amount_at_price = gmp_add($btc_amount_at_price, $btc_amount);
        else {
            if ($last_price)
                show_mini_orderbook_table_row($want_type, $last_price, $last_have, $last_want, $btc_amount_at_price, $total_btc_amount);
                                              
            $last_price = $price;
            $btc_amount_at_price = $btc_amount;
        }

        $last_have = $have_amount;
        $last_want = $want_amount;
        $total_btc_amount = gmp_add($total_btc_amount, $btc_amount);
    }
    if ($last_price)
        show_mini_orderbook_table_row($want_type, $last_price, $last_have, $last_want, $btc_amount_at_price, $total_btc_amount);

    echo "</table>\n";
}

function show_mini_orderbook()
{
    echo "<table><tr><td>\n";
    show_mini_orderbook_table(true);
    echo "</td><td>";
    show_mini_orderbook_table(false);
    echo "</td></tr></table>";
    echo "<p>" . sprintf(_("Showing all orders within %s%% of the best price."), ORDERBOOK_PRICE_RANGE_PERCENTAGE) . "</p>\n";
}

    if (isset($_GET['have']))
        $in_amount = internal_to_numstr(get('have'));
    else
        $in_amount = '';

    if (isset($_GET['want']))
        $out_amount = internal_to_numstr(get('want'));<commit_msg>Show the user's own orders in bold type on the trade page.<commit_after><?php

function show_mini_orderbook_table_cell($curr, $price, $have, $want, $depth)
{
    if ($curr == 'BTC') {
        list ($w, $r) = gmp_div_qr(gmp_mul($depth, $have), $want);
        $w = gmp_strval(gmp_cmp($r, 0) ? gmp_sub($w, 1) : $w);
        $h = gmp_strval($depth);
        $p = clean_sql_numstr(bcdiv($have, $want, 8));
    } else {
        list ($h, $r) = gmp_div_qr(gmp_mul($depth, $want), $have);
        $h = gmp_strval(gmp_cmp($r,0) ? gmp_add($h, 1) : $h);
        $w = gmp_strval($depth);
        $p = clean_sql_numstr(bcdiv($want, $have, 8));
    }

    active_table_cell(internal_to_numstr($depth, BTC_PRECISION), "?page=trade&in=$curr&have=$h&want=$w&rate=$p", 'right');
}

function show_mini_orderbook_table_row($curr, $price, $have, $want, $this_btc, $sum_btc, $mine)
{
    if ($mine) {
        active_table_row("me", "?page=view_order&orderid=$mine");
        echo "<td class='right'>$price</td>";
        echo "<td class='right'>" . internal_to_numstr($this_btc, BTC_PRECISION) . "</td>\n";
        echo "<td class='right'>" . internal_to_numstr($sum_btc, BTC_PRECISION) . "</td>\n";
        echo "</tr>\n";
    } else {
        echo "<tr>";
        echo "<td class='right'>$price</td>";
        show_mini_orderbook_table_cell($curr, $price, $have, $want, $this_btc);
        show_mini_orderbook_table_cell($curr, $price, $have, $want, $sum_btc);
    }
    echo "</tr>\n";
}

function show_mini_orderbook_table($bids)
{
    global $buy, $sell, $is_logged_in;

    echo "<table class='display_data'>";
    echo "<tr><th colspan=3 style='text-align: center;'>" .
        ($bids
         ? sprintf(_("People Buying BTC for %s"),   CURRENCY)
         : sprintf(_("People Selling BTC for %s" ), CURRENCY)) .
        "</th></tr>" .
        "<tr><th valign='bottom' class='right'>" .
        sprintf(_("Price<br/>(%s per BTC)"), CURRENCY) . "</th>" .
        "<th valign='bottom' class='right'>" . _("Depth<br/>(in BTC)") . "</th>" .
        "<th valign='bottom' class='right'>" . _("Cumulative<br/>Depth<br/>(in BTC)") . "</th>" .
        "</tr>";

    $limit = '';
    if ($bids) {
        $price = "amount/want_amount";
        $amount = "want_amount";
        $want_type = "BTC";
        $order = "DESC";
        if ($buy) $limit = "AND $price > " . $buy * (1 - ORDERBOOK_PRICE_RANGE_PERCENTAGE/100);
    } else {
        $price = "want_amount/amount";
        $amount = "amount";
        $want_type = CURRENCY;
        $order = "ASC";
        if ($sell) $limit = "AND $price < " . $sell * (1 + ORDERBOOK_PRICE_RANGE_PERCENTAGE/100);
    }

    $result = do_query("
        SELECT
            uid = $is_logged_in as me,
            orderid,
            amount,
            want_amount
        FROM
            orderbook
        WHERE
            want_type = '$want_type' AND
            status='OPEN'
            $limit
        ORDER BY
            $price $order, timest ASC
    ");

    $last_price = $btc_amount_at_price = $total_btc_amount = "0";
    $mine = $mine_count = 0;
    while ($row = mysql_fetch_array($result)) {
        $have_amount = $row['amount'];
        $want_amount = $row['want_amount'];

        if ($bids) {
            $btc_amount  = $want_amount;
            $fiat_amount = $have_amount;
        } else {
            $btc_amount  = $have_amount;
            $fiat_amount = $want_amount;
        }

        $price = fiat_and_btc_to_price($fiat_amount, $btc_amount, $bids ? 'down' : 'up');

        if ($price == $last_price)
            $btc_amount_at_price = gmp_add($btc_amount_at_price, $btc_amount);
        else {
            if ($last_price) {
                show_mini_orderbook_table_row($want_type, $last_price, $last_have, $last_want, $btc_amount_at_price, $total_btc_amount, $mine);
                $mine = 0;
            }
                                              
            $last_price = $price;
            $btc_amount_at_price = $btc_amount;
        }

        $last_have = $have_amount;
        $last_want = $want_amount;
        $total_btc_amount = gmp_add($total_btc_amount, $btc_amount);

        if ($row['me']) {
            $mine = $row['orderid'];
            $mine_count++;
        }
    }
    if ($last_price)
        show_mini_orderbook_table_row($want_type, $last_price, $last_have, $last_want, $btc_amount_at_price, $total_btc_amount, $mine);

    echo "</table>\n";

    return $mine_count;
}

function show_mini_orderbook()
{
    echo "<table><tr><td>\n";
    $mine = show_mini_orderbook_table(true);
    echo "</td><td>";
    $mine += show_mini_orderbook_table(false);
    echo "</td></tr></table>";
    echo "<p>" . sprintf(_("Showing all orders within %s%% of the best price."), ORDERBOOK_PRICE_RANGE_PERCENTAGE) . "</p>\n";

    if ($mine)
        echo "<p>" . _("The bold lines indicate prices at which you have orders.  Note that other users may have orders at the same price, and so the depth shown isn't necessarily all due to your order.  You can click the bold lines to view or cancel your orders.") . "</p>\n";
}

    if (isset($_GET['have']))
        $in_amount = internal_to_numstr(get('have'));
    else
        $in_amount = '';

    if (isset($_GET['want']))
        $out_amount = internal_to_numstr(get('want'));
{'fraction_non_alphanumeric': 0.1712967816332949, 'fraction_numerical': 0.0035643149177062585, 'mean_word_length': 2.517699115044248, 'pattern_counts': {'":': 0, '<': 80, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2386602', 'n_tokens_mistral': 3513, 'n_tokens_neox': 3394, 'n_words': 653}