This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathorderbook.php
69 lines (62 loc) · 2.13 KB
/
orderbook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
require 'util.php';
function display_double_entry($curr_a, $curr_b, $base_curr)
{
echo "<div class='content_box'>\n";
echo "<h3>People offering $curr_a for $curr_b</h3>\n";
$exchange_fields = calc_exchange_rate($curr_a, $curr_b, $base_curr);
if (!$exchange_fields) {
echo "<p>Nobody is selling $curr_a for $curr_b.</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 "1 $curr_a is worth <b>$rate $curr_b</b>";
else
echo "1 $curr_b is worth <b>$rate $curr_a</b>";
echo ".</p>";
echo "<p>$total_amount $curr_a being sold for $total_want_amount $curr_b.</p>";
?><table class='display_data'>
<tr>
<th>Cost / BTC</th>
<th>Giving</th>
<th>Wanted</th>
</tr><?php
$query = "
SELECT
*,
IF(
type='BTC',
initial_want_amount/initial_amount,
initial_amount/initial_want_amount
) AS rate
FROM orderbook
WHERE type='$curr_a' AND want_type='$curr_b' AND status='OPEN'
ORDER BY
IF(type='BTC', rate, -rate) ASC
";
$result = do_query($query);
while ($row = mysql_fetch_array($result)) {
$amount = internal_to_numstr($row['amount']);
$want_amount = internal_to_numstr($row['want_amount']);
# MySQL kindly computes this for us.
# we trim the excessive 0
$rate = clean_sql_numstr($row['rate']);
echo " <tr>\n";
echo " <td>$rate</td>\n";
echo " <td>$amount $curr_a</td>\n";
echo " <td>$want_amount $curr_b</td>\n";
echo " </tr>\n";
}
echo " <tr>\n";
echo " <td>Total:</td>\n";
echo " <td>$total_amount $curr_a</td>\n";
echo " <td>$total_want_amount $curr_b</td>\n";
echo " </tr>\n";
echo "</table></div>";
}
display_double_entry('BTC', 'GBP', BASE_CURRENCY::A);
display_double_entry('GBP', 'BTC', BASE_CURRENCY::B);
?>