TakeMoney($Fees, -1, $from_id, true); AddMoney($Amount + $Fees, $owner, $from_id); } mysql_query("DELETE FROM trades WHERE `Id`='{$ids}'"); } //-------------------------------------- if (isset($_POST["Amount"])) { if ($_POST["price1"] > 0 && $_POST["Amount"] > 0) { $PricePer = mysql_real_escape_string($_POST["price1"]); $Amount = mysql_real_escape_string($_POST["Amount"]); $Fees = file_get_contents("http://dev3.openex.pw/system/calculatefees2.php?P=" . $Amount); $Total = $Fees + $Amount; echo $Total; $user_id = $loggedInUser->user_id; if (TakeMoney($Total, $user_id, $id) == true) { AddMoney($Fees, -1, $id); $New_Trade = new Trade(); $New_Trade->trade_to = $Currency_1a; $New_Trade->trade_from = $name; $New_Trade->trade_amount = $Amount; $New_Trade->trade_value = $PricePer; $New_Trade->trade_owner = $user_id; $New_Trade->trade_type = $name; $New_Trade->trade_fees = $Fees; $New_Trade->trade_total = $Total; $New_Trade->trade_type = $name; $New_Trade->standard = $Amount; $New_Trade->GetEquivalentTrade(); $New_Trade->ExecuteTrade(); //mysql_query("INSERT INTO trades (`To`,`From`,`Amount`,`Value`,`User_ID`,`Type`,`Fee`,`Total`)VALUES ('$Currency_1a','$name','$Amount','$PricePer','$user_id','$name','$Fees','$Total');"); } else {
public function ExecuteTrade() { if ($this->etrade_id != NULL) { if ($this->trade_from == $this->trade_type) { $difference = $this->trade_amount - $this->etrade_amount; if ($difference < 0) { $newamount = 0 - $difference; $sellmoney = $this->trade_value * $this->trade_amount; $buymoney = $this->etrade_amount - $newamount; AddMoney($sellmoney, $this->trade_owner, $this->trade_to); AddMoney($buymoney, $this->etrade_owner, $this->etrade_to); $this->etrade_amount = $newamount; $this->trade_amount = 0; //echo "1"; } if ($difference > 0) { $newamount = 0 + $difference; $sellmoney = ($this->trade_amount - $newamount) * $this->trade_value; AddMoney($sellmoney, $this->trade_owner, $this->trade_to); AddMoney($this->etrade_amount, $this->etrade_owner, $this->etrade_to); $this->trade_amount = $newamount; $this->etrade_amount = 0; // echo "2"; } if ($difference == 0) { AddMoney($this->trade_amount * $this->trade_value, $this->trade_owner, $this->etrade_to); AddMoney($this->etrade_amount, $this->etrade_owner, $this->etrade_to); $this->trade_amount = 0; $this->etrade_amount = 0; //echo "3"; } } else { $difference = $this->etrade_amount - $this->trade_amount; if ($difference < 0) { $newamount = 0 - $difference; $sellmoney = $this->etrade_value * $this->etrade_amount; $buymoney = $this->trade_amount - $newamount; AddMoney($sellmoney, $this->etrade_owner, $this->etrade_to); AddMoney($buymoney, $this->trade_owner, $this->trade_to); $this->trade_amount = $newamount; $this->etrade_amount = 0; //echo "1"; } if ($difference > 0) { $newamount = 0 + $difference; $sellmoney = ($this->etrade_amount - $newamount) * $this->etrade_value; AddMoney($sellmoney, $this->etrade_owner, $this->etrade_to); AddMoney($this->trade_amount, $this->trade_owner, $this->trade_to); $this->etrade_amount = $newamount; $this->trade_amount = 0; //echo "2"; } if ($difference == 0) { AddMoney($this->etrade_amount * $this->etrade_value, $this->etrade_owner, $this->etrade_to); AddMoney($this->trade_amount, $this->trade_owner, $this->trade_to); $this->etrade_amount = 0; $this->trade_amount = 0; //echo "3"; } } $type = $this->trade_type; $sql_112 = mysql_query("SELECT * FROM Wallets WHERE `Acronymn`='{$type}'"); $type_id = mysql_result($sql_112, 0, "Id"); $quantity = $this->standard; $time = time(); $price = $this->trade_value; mysql_query("INSERT INTO Trade_History (`Market_Id`,`Price`,`Quantity`,`Timestamp`)VALUES ('{$type_id}','{$price}','{$quantity}','{$time}');"); } $this->UpdateTrade(); $this->UpdateETrade(); }