예제 #1
0
<?php

require_once 'order_utils.php';
if (isset($_POST['csrf_token'])) {
    if ($_SESSION['csrf_token'] != $_POST['csrf_token']) {
        throw new Error("csrf", "csrf token mismatch!");
    }
} else {
    throw new Error("csrf", "csrf token missing");
}
$have_amount = post('amount');
$have_currency = post('type');
$want_amount = post('want_amount');
$want_currency = post('want_type');
$_SESSION['currency_in'] = strtoupper($have_currency);
$orderid = place_order($have_amount, $have_currency, $want_amount, $want_currency);
?>

<div class='content_box'>
    <h3><?php 
echo _("Order placed");
?>
</h3>

    <p><?php 
printf(_("Your order offering %s for %s has been placed."), $have_amount . " " . $have_currency, $want_amount . " " . $want_currency);
?>
</p>

    <p><?php 
printf(_("You may view your %snew order%s or visit the %sorderbook%s."), '<a href="?page=view_order&orderid=' . $orderid . '">', '</a>', '<a href="?page=orderbook">', '</a>');
예제 #2
0
function my_algo($data, &$config)
{
    global $json_log;
    static $show_status = 0;
    $cur_buy_price = $data["cur_buy_price"];
    $cur_sell_price = $data["cur_sell_price"];
    $my_orders = $data["my_orders"];
    $my_base_coin = $data["my_wallet"][$config['base_coin']];
    $my_target_coin = $data["my_wallet"][$config['target_coin']];
    $action = array();
    $show_status++;
    $show_status = $show_status % (15 * 120);
    // ATTENTION!!! only support 1 buy and 1 sell order
    if (sizeof($my_orders) == 0) {
        $action = place_order($data, $config);
    } else {
        if (sizeof($my_orders) == 1) {
            if (sizeof($data["my_trade"]) != 0) {
                print "\n";
                static $order_id = 0;
                $my_trade = $data["my_trade"][0];
                if ($my_trade["order_id"] != $order_id) {
                    print $my_trade["tradetype"] . " " . $my_trade["quantity"] . " at price " . $my_trade["tradeprice"] . " , total " . $config['base_coin'] . " " . $my_trade["total"] . "\n";
                    $file = $config['log_filename'];
                    if ($file != "") {
                        file_put_contents($file, $my_trade["tradetype"] . " " . $my_trade["quantity"] . " at price " . $my_trade["tradeprice"] . " , total " . $config['base_coin'] . " " . $my_trade["total"] . "\n", FILE_APPEND);
                        $file .= ".json";
                        $mydata = array();
                        $mydata["date"] = $my_trade["datetime"];
                        $mydata["label"] = $config["target_coin"] . "/" . $config["base_coin"];
                        $mydata["tradetype"] = $my_trade["tradetype"];
                        $mydata["price"] = $my_trade["tradeprice"];
                        $mydata["quantity"] = $my_trade["quantity"];
                        $mydata["total"] = $my_trade["total"];
                        $mydata["buy_count"] = $config["buy_count"];
                        $mydata["sell_count"] = $config["sell_count"];
                        $json_log[sizeof($json_log)] = $mydata;
                        file_put_contents($file, json_encode($json_log));
                    }
                    $order_id = $my_trade["order_id"];
                }
                if ($my_trade["tradetype"] == "Buy") {
                    $config['buy_count']++;
                    $config['sell_count'] = 0;
                } else {
                    if ($my_trade["tradetype"] == "Sell") {
                        $config['sell_count']++;
                        $config['buy_count'] = 0;
                    }
                }
            }
            $action['cancel_market_orders'] = 1;
        } else {
            if ($show_status % 12 == 0) {
                //$this->show_status();
                //printf("%s ",$data["cur_buy_price"]*100000000);
                if (sizeof($my_orders) > 2) {
                    printf("U");
                } else {
                    printf(".");
                }
                if ($show_status == 0) {
                    printf("\n");
                }
            }
        }
    }
    return $action;
}
예제 #3
0
function my_algo($data, &$config)
{
    global $json_log;
    $cur_buy_price = $data["cur_buy_price"];
    $cur_sell_price = $data["cur_sell_price"];
    $my_orders = $data["my_orders"];
    $my_base_coin = $data["my_wallet"][$config['base_coin']];
    $my_target_coin = $data["my_wallet"][$config['target_coin']];
    $action = array();
    // ATTENTION!!! only support 1 buy and 1 sell order
    if (sizeof($my_orders) == 0) {
        $action = place_order($data, $config);
        return $action;
    } else {
        if (sizeof($my_orders) == 1) {
            if (sizeof($data["my_trade"]) != 0) {
                static $order_id = 0;
                $my_trade = $data["my_trade"][0];
                if ($my_trade["order_id"] != $order_id) {
                    print $my_trade["tradetype"] . " " . $my_trade["quantity"] . " at price " . $my_trade["tradeprice"] . " , total " . $config['base_coin'] . " " . $my_trade["total"] . "\n";
                    $file = $config['log_filename'];
                    if ($file != "") {
                        file_put_contents($file, $my_trade["tradetype"] . " " . $my_trade["quantity"] . " at price " . $my_trade["tradeprice"] . " , total " . $config['base_coin'] . " " . $my_trade["total"] . "\n", FILE_APPEND);
                        $file .= ".json";
                        $mydata = array();
                        $mydata["date"] = $my_trade["datetime"];
                        $mydata["label"] = $config["target_coin"] . "/" . $config["base_coin"];
                        $mydata["tradetype"] = $my_trade["tradetype"];
                        $mydata["price"] = $my_trade["tradeprice"];
                        $mydata["quantity"] = $my_trade["quantity"];
                        $mydata["total"] = $my_trade["total"];
                        $mydata["buy_count"] = $config["buy_count"];
                        $mydata["sell_count"] = $config["sell_count"];
                        $json_log[sizeof($json_log)] = $mydata;
                        file_put_contents($file, json_encode($json_log));
                    }
                    $order_id = $my_trade["order_id"];
                }
                if ($my_trade["tradetype"] == "Buy") {
                    $config['buy_count']++;
                    $config['sell_count'] = 0;
                } else {
                    if ($my_trade["tradetype"] == "Sell") {
                        $config['sell_count']++;
                        // don't set buy_count to 0 if we have bought more than 2 times
                        if ($config['buy_count'] > 1) {
                            $config['buy_count'] -= 1;
                        } else {
                            $config['buy_count'] = 0;
                        }
                    }
                }
            }
            $action['cancel_market_orders'] = 1;
            return $action;
        } else {
            if (sizeof($my_orders) > 2) {
                // something wrong here
                $action['cancel_market_orders'] = 1;
                return $action;
            }
        }
    }
    $dt = new DateTime();
    $dt->setTimezone(new DateTimeZone('EST'));
    $datetime = $dt->format('Y\\-m\\-d\\ h:i:s');
    print "{$datetime} - current price: {$cur_buy_price}\r";
    return $action;
}
예제 #4
0
function addOrder()
{
    $reqid = place_order(post('have_amount'), post('have_currency'), post('want_amount'), post('want_currency'));
    return array("status" => "OK", "orderid" => $reqid);
}
예제 #5
0
Copyright (c) 2008 Metathinking Ltd.
This file is part of Affiliates For All.
Affiliates For All is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Affiliates For All is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with Affiliates For All.  If not, see
<http://www.gnu.org/licenses/>.
*/
require_once 'dummycart.inc';
place_order();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN";
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Test Shopping Cart</title>
</head>
<body>
  <h1>Order Placed</h1>

  <p>Order <?php 
echo $_GET['orderno'];
?>
 for $<?php 
echo $_GET['quantity'] * 5;