forked from applsdev/openex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.trade.php
114 lines (110 loc) · 3.02 KB
/
class.trade.php
1
<?phpclass Trade{ public $trade_value; public $trade_amount; public $trade_type; public $trade_id; public $trade_to; public $trade_from; public $trade_owner; public $etrade_owner; public $etrade_id; public $etrade_value; public $etrade_amount; public function UpdateTrade() { $id = $this->trade_id; $amount = $this->trade_amount; if($this->trade_amount == 0) { mysql_query("DELETE FROM trades WHERE `Id`='$id'"); } else { mysql_query("UPDATE trades SET `Amount`='$amount' WHERE `Id`='$id'"); } } public function UpdateETrade() { $id = $this->etrade_id; $amount = $this->etrade_amount; if($this->etrade_amount == 0) { mysql_query("DELETE FROM trades WHERE `Id`='$id'"); } else { mysql_query("UPDATE trades SET `Amount`='$amount' WHERE `Id`='$id'"); } } function Trade($id) { $tradesql = mysql_query("SELECT * FROM trades WHERE `Id`='$id'"); $this->trade_value = mysql_result($tradesql,0,"Value"); $this->trade_amount = mysql_result($tradesql,0,"Amount"); $this->trade_id = $id; $this->trade_from = mysql_result($tradesql,0,"From"); $this->trade_to = mysql_result($tradesql,0,"To"); $this->trade_owner = mysql_result($tradesql,0,"User_ID"); if($this->trade_to != "BTC") { $this->trade_type = "BUY"; } else { $this->trade_type = "SELL"; } } public function GetEquivalentTrade() { $from = $this->trade_from; $value = $this->trade_value; echo $from; $tradesql2 = mysql_query("SELECT * FROM trades WHERE `To` = '$from' AND `Value`=$value"); $this->etrade_id = mysql_result($tradesql2,0,"Id"); $this->etrade_value = mysql_result($tradesql2,0,"Value"); $this->etrade_amount = mysql_result($tradesql2,0,"Amount"); $this->etrade_owner = mysql_result($tradesql2,0,"User_ID"); } public function ExecuteTrade() { if($this->etrade_id != NULL) { $difference = $this->etrade_amount - $this->trade_amount; if($difference < 0) { echo "1"; $newamount = 0 - $difference; $sellmoney = $this->etrade_value * $this->etrade_amount; $buymoney = ($this->trade_amount - $newamount); AddMoney($sellmoney, $this->etrade_owner, "BTC"); AddMoney($buymoney,$this->trade_owner,$this->trade_to); $this->trade_amount = $newamount; $this->etrade_amount = 0; } if($difference > 0) { echo "2"; $newamount = 0 + $difference; $sellmoney = ($this->etrade_amount - $newamount) * $this->etrade_value; AddMoney($sellmoney, $this->etrade_owner, "BTC"); AddMoney($this->trade_amount,$this->trade_owner,$this->trade_to); $this->etrade_amount = $newamount; $this->trade_amount=0; } if($difference == 0) { echo "3"; AddMoney($this->etrade_amount * $this->etrade_value, $this->etrade_owner, "BTC"); AddMoney($this->trade_amount,$this->trade_owner,$this->trade_to); $this->etrade_amount=0; $this->trade_amount=0; } $this->UpdateTrade(); $this->UpdateETrade(); mysql_query("UPDATE markets SET `Last_Trade`='". $this->etrade_value . "' WHERE `Acronymn`='".$this->trade_to . "'"); } }}?>