Example #1
0
function display_double_entry($curr_a, $curr_b, $base_curr, $uid, $is_admin)
{
    if (isset($_GET['show_all']) && get('show_all') == 'true') {
        $show_all = true;
    } else {
        $show_all = false;
    }
    echo "<div class='content_box'>\n";
    if ($curr_a == 'BTC') {
        echo "<h3>" . sprintf(_("People selling %s for %s"), $curr_a, $curr_b) . "</h3>\n";
    } else {
        echo "<h3>" . sprintf(_("People buying %s for %s"), $curr_b, $curr_a) . "</h3>\n";
    }
    $exchange_fields = calc_exchange_rate($curr_a, $curr_b, $base_curr);
    if (!$exchange_fields) {
        if ($curr_a == 'BTC') {
            echo "<p>" . sprintf(_("Nobody is selling %s for %s."), $curr_a, $curr_b) . "</p>";
        } else {
            echo "<p>" . sprintf(_("Nobody is buying %s for %s."), $curr_b, $curr_a) . "</p>";
        }
        echo "</div>";
        return;
    }
    list($total_amount, $total_want_amount, $rate) = $exchange_fields;
    echo "<p>" . _("Best exchange rate is") . " ";
    if ($base_curr == BASE_CURRENCY::A) {
        echo "<b>{$rate} {$curr_b}/{$curr_a}</b>";
    } else {
        echo "<b>{$rate} {$curr_a}/{$curr_b}</b>";
    }
    echo ".</p>";
    if (!$show_all) {
        echo "<p>" . sprintf(_("Showing top %d entries"), DEFAULT_ORDERBOOK_DEPTH) . ":</p>";
    }
    ?>
<table class='display_data'>
        <tr>
            <th><?php 
    echo _("Cost / BTC");
    ?>
</th>
            <th><?php 
    echo _("Giving");
    ?>
</th>
            <th><?php 
    echo _("Wanted");
    ?>
</th>
<?php 
    if ($is_admin) {
        ?>
            <th><?php 
        echo _("User");
        ?>
</th>
<?php 
    }
    if (SHOW_CUMULATIVE_DEPTH) {
        ?>
            <th><?php 
        echo _("Cumulative Give");
        ?>
</th>
            <th><?php 
        echo _("Cumulative Want");
        ?>
</th>
<?php 
    }
    ?>
        </tr><?php 
    $show_query = 'LIMIT ' . DEFAULT_ORDERBOOK_DEPTH;
    if ($show_all) {
        $show_query = '';
    }
    $query = "\n        SELECT\n            orderid,\n            amount,\n            want_amount,\n            uid={$uid} as me,\n            uid,\n            IF(\n                type='BTC',\n                initial_want_amount/initial_amount,\n                initial_amount/initial_want_amount\n            ) AS rate\n        FROM orderbook\n        WHERE type='{$curr_a}' AND want_type='{$curr_b}' AND status='OPEN'\n        ORDER BY\n            IF(type='BTC', rate, -rate) ASC, timest ASC\n        {$show_query}\n    ";
    $result = do_query($query);
    $cumulative_curr_a = 0;
    $cumulative_curr_b = 0;
    if ($curr_a == 'BTC') {
        $precision_a = BTC_PRECISION;
        $precision_b = FIAT_PRECISION;
    } else {
        $precision_a = FIAT_PRECISION;
        $precision_b = BTC_PRECISION;
    }
    while ($row = mysql_fetch_array($result)) {
        $amount_i = $row['amount'];
        $amount = internal_to_numstr($amount_i, $precision_a);
        $cumulative_curr_a = gmp_add($cumulative_curr_a, $amount_i);
        $want_amount_i = $row['want_amount'];
        $want_amount = internal_to_numstr($want_amount_i, $precision_b);
        $cumulative_curr_b = gmp_add($cumulative_curr_b, $want_amount_i);
        // MySQL kindly computes this for us.
        // we trim the excessive 0
        $rate = clean_sql_numstr($row['rate']);
        $me = $row['me'];
        $uid = $row['uid'];
        if ($me) {
            echo "    ", active_table_row("me", "?page=view_order&orderid={$row['orderid']}");
        } else {
            echo "    ", active_table_row("them", "?page=trade&in={$curr_b}&have={$want_amount_i}&want={$amount_i}&rate={$rate}");
        }
        echo "        <td>{$rate}</td>\n";
        echo "        <td>{$amount} {$curr_a}</td>\n";
        echo "        <td>{$want_amount} {$curr_b}</td>\n";
        if ($is_admin) {
            echo "        <td>{$uid}</td>\n";
        }
        if (SHOW_CUMULATIVE_DEPTH) {
            echo "        <td>" . internal_to_numstr($cumulative_curr_a, $precision_a) . " {$curr_a}</td>\n";
            echo "        <td>" . internal_to_numstr($cumulative_curr_b, $precision_b) . " {$curr_b}</td>\n";
        }
        echo "    </tr>\n";
    }
    echo "    <tr>\n";
    echo "        <td>" . _("Total") . ":</td>\n";
    // strstr's 3rd argument only works in PHP 5.3.0 and newer
    //   http://php.net/manual/en/function.strstr.php
    // use explode instead
    $total_amount = explode('.', $total_amount, 2);
    $total_amount = $total_amount[0];
    echo "        <td>{$total_amount} {$curr_a}</td>\n";
    echo "        <td></td>\n";
    echo "    </tr>\n";
    echo "</table>\n";
    if ($show_all) {
        echo "<p><a href='?page=orderbook&show_all=false'>&gt;&gt; " . _("hide") . "</a></p>\n";
    } else {
        echo "<p><a href='?page=orderbook&show_all=true'>&gt;&gt; " . _("show all") . "</a></p>\n";
    }
    echo "</div>\n";
}
Example #2
0
function get_ticker_data()
{
    $query = "\n    SELECT\n        ROUND(MAX(a_amount/b_amount), " . PRICE_PRECISION . ") AS high,\n        ROUND(MIN(a_amount/b_amount), " . PRICE_PRECISION . ") AS low,\n        SUM(a_amount/b_amount) AS sum_of_prices,\n        COUNT(*)               AS number_of_prices,\n        SUM(a_amount)          AS sum_of_a_amounts,\n        SUM(b_amount)          AS sum_of_b_amounts,\n        SUM(b_amount)          AS vol\n    FROM\n        transactions\n    WHERE\n        b_amount > 0\n        AND timest > NOW() - INTERVAL 1 DAY;\n    ";
    $result = do_query($query);
    $row = get_row($result);
    if (isset($row['vol'])) {
        $sum_of_prices = $row['sum_of_prices'];
        $number_of_prices = $row['number_of_prices'];
        $sum_of_a_amounts = $row['sum_of_a_amounts'];
        $sum_of_b_amounts = $row['sum_of_b_amounts'];
        $high = $row['high'];
        $low = $row['low'];
        $avg = fiat_and_btc_to_price($sum_of_prices, $number_of_prices);
        $vwap = fiat_and_btc_to_price($sum_of_a_amounts, $sum_of_b_amounts);
        $vol = internal_to_numstr($row['vol'], BTC_PRECISION);
    } else {
        $high = $low = $avg = $vwap = $vol = 0;
    }
    $exchange_fields = calc_exchange_rate(CURRENCY, 'BTC', BASE_CURRENCY::B);
    if (!$exchange_fields) {
        $buy = 0;
    } else {
        list($total_amount, $total_want_amount, $buy) = $exchange_fields;
    }
    $exchange_fields = calc_exchange_rate('BTC', CURRENCY, BASE_CURRENCY::A);
    if (!$exchange_fields) {
        $sell = 0;
    } else {
        list($total_amount, $total_want_amount, $sell) = $exchange_fields;
    }
    $last = get_last_price();
    // for testing layout when all stats have 4 decimal places
    // return array('21.1234', '20.1234', '21.6789', '21.4567', '1234567.3456', '21.5543', '21.2345', '22.1257');
    return array($high, $low, $avg, $vwap, $vol, $last, $buy, $sell);
}
Example #3
0
function show_header($page, $is_logged_in, $base = false)
{
    global $shown_header;
    $shown_header = true;
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html itemscope itemtype="http://schema.org/Organization" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <title><?php 
    echo SITE_NAME;
    ?>
</title>
    <script type='text/javascript' src='js/util.js'></script>
<?php 
    if (!isset($_GET['fancy'])) {
        ?>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
        <script>
            !window.jQuery && document.write('<script src="js/jquery-1.4.4.min.js"><\/script>');
        </script>
        <script type="text/javascript" src="js/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
        <link rel="stylesheet" type="text/css" href="js/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
        <script type="text/javascript">
            $(document).ready(function() {
                $(".fancy").fancybox({'margin'  :  20,
                                      'padding' :   2,
                                      'speedIn' : 500,
                                      'speedOut': 100});
            });
        </script>
<?php 
        if ($page == 'trade') {
            ?>
        <script type='text/javascript' src='js/exchanger.js'></script>
<?php 
            echo "    <script type='text/javascript'>\n";
            $fiat_currency = strtolower(CURRENCY);
            echo "        fiat_currency = '{$fiat_currency}';\n";
            echo "        fiat_currency_full = '" . CURRENCY_FULL . "';\n";
            if (isset($_GET['rate'])) {
                echo "        typed_price = true;\n";
            } else {
                $currencies = array('BTC', CURRENCY);
                $rates = array();
                $list = calc_exchange_rate('btc', $fiat_currency, BASE_CURRENCY::A);
                $rates[$fiat_currency] = $list[2];
                $list = calc_exchange_rate($fiat_currency, 'btc', BASE_CURRENCY::B);
                $rates['btc'] = $list[2];
                echo "        typed_price = false;\n";
                echo "        exchange_rates = " . json_encode($rates) . ";\n";
            }
            echo "    </script>\n";
        }
    }
    if ($base) {
        echo "    <base href=\"{$base}\" />\n";
    }
    ?>
    <link rel="stylesheet" type="text/css" href="style.css" />
    <link rel="icon" type="image/png" href="favicon.png" />

<!-- start of google +snippet code -->
<meta itemprop="name" content="<?php 
    echo SITE_NAME;
    ?>
">
<meta itemprop="description" content="<?php 
    echo SITE_DESCRIPTION;
    ?>
">
<meta itemprop="image" content="<?php 
    echo SITE_IMAGE;
    ?>
">
<!-- end of google +snippet code -->

<!-- start of google +1 code -->
<script type="text/javascript">
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>
<!-- end of google +1 code -->

<?php 
    if ($page != 'login') {
        ?>
<!-- start of google analytics code -->
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '<?php 
        echo ANALYTICS_ACCOUNT;
        ?>
']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
<!-- end of google analytics code -->
<?php 
    }
    ?>
</head>

<?php 
    if ($page == 'trade') {
        if (isset($_GET['in'])) {
            if (get('in') == 'BTC') {
                $in = 'btc';
            } else {
                $in = $fiat_currency;
            }
        } else {
            if (isset($_SESSION['currency_in']) && $_SESSION['currency_in'] == 'BTC') {
                $in = 'btc';
            } else {
                $in = $fiat_currency;
            }
        }
        if ($in == 'btc') {
            echo "<body onload='set_currency_in(\"btc\"); set_currency_out(\"{$fiat_currency}\");'>\n";
        } else {
            echo "<body onload='set_currency_in(\"{$fiat_currency}\"); set_currency_out(\"btc\");'>\n";
        }
    } else {
        if (isset($_GET['fancy'])) {
            echo "<body><div class='fancy_box'>\n";
            return;
        }
    }
    echo "<body>\n";
    ?>
    <img id='flower' src='images/flower.png' />
    <a href="."><img id='header' src='images/header.png' /></a>
    <img id='skyline' src='images/skyline.png' />
    <div id='main_pane'>
        <div id='links_bg'>
            <div id='content'>
                <div id='content_sideshadow'>
<?php 
    show_content_header($is_logged_in);
}