public function index($s = null) { $greencoin = new Greencoin('http://' . GREENCOIN_WALLET_SERVER . ':' . GREENCOIN_WALLET_PORT, GREENCOIN_WALLET_USERNAME, GREENCOIN_WALLET_PASSWORD); $paytxfee = Parameters::find('first'); $txfee = $paytxfee['payxgctxfee']; $getrawtransaction = $greencoin->getrawtransaction($s); $decoderawtransaction = $greencoin->decoderawtransaction($getrawtransaction); foreach ($decoderawtransaction['vout'] as $out) { foreach ($out['scriptPubKey']['addresses'] as $address) { $username = $greencoin->getaccount($address); $Amount = (double) $out['value']; if ($greencoin->getaccount($address) != "") { $Transactions = Transactions::find('first', array('conditions' => array('TransactionHash' => $s))); if ($Transactions['_id'] == "") { $t = Transactions::create(); $Amount = $Amount; $comment = "Move from User: "******"; Address: " . GREENCOINX_ADDRESS . "; Amount:" . $Amount . ";"; $transfer = $greencoin->sendfrom($username, GREENCOINX_ADDRESS, (double) $Amount, (int) 0, $comment); if (isset($transfer['error'])) { $error = $transfer['error']; } else { $error = $transfer; } $data = array('DateTime' => new \MongoDate(), 'TransactionHash' => $s, 'username' => $username, 'address' => $address, 'Currency' => 'XGC', 'Amount' => $Amount, 'Added' => true, 'Transfer' => $comment); $t->save($data); $userName = str_replace("SiiCrypto-", "", $username); $details = Details::find('first', array('conditions' => array('username' => (string) $userName))); $dataDetails = array('balance.XGC' => (double) ((double) $details['balance.XGC'] + (double) $Amount), 'XGCnewaddress' => 'Yes'); $details = Details::find('all', array('conditions' => array('username' => (string) $userName)))->save($dataDetails); } else { $Transactions = Transactions::find('first', array('conditions' => array('TransactionHash' => $s)))->save($data); } } } } }
public function trade($key = null) { if (!$this->request->data) { return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Not submitted through POST."))); } if ($key == null) { return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Key not specified. Please get your key from your settings page under security."))); } else { $details = Details::find('first', array('conditions' => array('key' => $key))); print_r($details['username']); if (count($details) == 0) { return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Incorrect Key! Please get your key from your settings page under security."))); } else { if (!$this->requestAPI("trade", $details['username'])) { return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Too many requests from your IP. Try after some time."))); } $type = $this->request->data['type']; $pair = $this->request->data['pair']; $amount = $this->request->data['amount']; $price = $this->request->data['price']; if (!($type == "Buy" || $type == "Sell")) { return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Type is incorrect! Should be 'Buy' or 'Sell'." . $type))); } /* if(!($pair=='BTC_USD' || $pair=='BTC_GBP' || $pair=='BTC_EUR' || $pair=='BTC_LTC' || $pair=='LTC_USD' || $pair=='LTC_GBP' || $pair=='LTC_EUR')){ return $this->render(array('json' => array('success'=>0, 'now'=>time(), 'error'=>"Pair is incorrect! Should be 'BTC_USD','BTC_GBP','BTC_EUR','BTC_LTC','LTC_USD','LTC_GBP','LTC_EUR'.".$pair ))); } */ if ((double) $amount <= 0) { return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Amount less than or equal to ZERO! Should be greater than ZERO." . $amount))); } if ((double) $price <= 0) { return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Price less than or equal to ZERO! Should be greater than ZERO." . $price))); } $first_curr = strtoupper(substr($pair, 0, 3)); $second_curr = strtoupper(substr($pair, 4, 3)); //======================Trade======================================================== $data = array('page.refresh' => true); Details::find('all')->save($data); $details = Details::find('first', array('conditions' => array('key' => $key))); $id = $details['user_id']; $user = Users::find('first', array('conditions' => array('_id' => $id))); $Action = $type; $commission = Parameters::find('first'); $commissionRate = $commission['value']; if ($Action == "Buy") { $PendingAction = 'Sell'; $FirstCurrency = $first_curr; $SecondCurrency = $second_curr; $Commission = (double) $commissionRate; $CommissionAmount = number_format((double) $commissionRate * (double) $amount / 100, 8); $CommissionCurrency = $first_curr; $Amount = (double) $amount; $PerPrice = (double) $price; $BalanceAmount = $details['balance'][$second_curr]; if ($amount * $price >= $BalanceAmount) { return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Amount exceeds your balance! Balance: " . $BalanceAmount))); } $NewBalanceAmount = round($BalanceAmount - $amount * $price, 8); $Currency = 'balance.' . $second_curr; // Update balance of user with NewBalance Amount $data = array('balance.' . $second_curr => (double) $NewBalanceAmount); $details = Details::find('first', array('conditions' => array('user_id' => $id)))->save($data); print_r("Buy-Save"); } if ($Action == "Sell") { $PendingAction = 'Buy'; $FirstCurrency = $first_curr; $SecondCurrency = $second_curr; $Commission = (double) $commissionRate; $CommissionAmount = number_format((double) $commissionRate * (double) $amount * (double) $price / 100, 8); $CommissionCurrency = $second_curr; $Amount = (double) $amount; $PerPrice = (double) $price; $BalanceAmount = $details['balance'][$first_curr]; if ($amount >= $BalanceAmount) { return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Amount exceeds your balance! Balance: " . $BalanceAmount))); } $NewBalanceAmount = round($BalanceAmount - $amount, 8); $Currency = 'balance.' . $first_curr; // Update balance of user with NewBalance Amount $data = array('balance.' . $first_curr => (double) $NewBalanceAmount); $details = Details::find('first', array('conditions' => array('user_id' => $id)))->save($data); print_r("Sell-Save"); } $data = array('Action' => $Action, 'FirstCurrency' => $first_curr, 'SecondCurrency' => $second_curr, 'CommissionPercent' => (double) $Commission, 'Commission.Amount' => (double) $CommissionAmount, 'Commission.Currency' => $CommissionCurrency, 'Amount' => (double) $Amount, 'PerPrice' => (double) $PerPrice, 'DateTime' => new \MongoDate(), 'Completed' => 'N', 'IP' => $_SERVER['REMOTE_ADDR'], 'username' => $user['username'], 'user_id' => (string) $user['_id']); print_r($data); // Create Order for the user $orders = Orders::create(); $orders->save($data); $order_id = $orders->_id; $data = array('refresh' => true); Trades::find('all', array('conditions' => array('trade' => $title)))->save($data); $ex = new ExController(); $ex->SendEmails($order_id, $user['_id']); // =Pending Orders================================================================================= $FirstCurrency = $first_curr; $SecondCurrency = $second_curr; $query = array('conditions' => array('Action' => $PendingAction, 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency, 'Completed' => 'N', 'user_id' => array('$ne' => $user['_id']), 'PerPrice' => (double) $PerPrice), 'order' => array('DateTime' => 'ASC')); $PendingOrders = Orders::find('all', $query); $i = 0; foreach ($PendingOrders as $PO) { if ((double) $PO['Amount'] == (double) $Amount) { $data = array('Completed' => 'Y', 'Transact.id' => $order_id, 'Transact.username' => $user['username'], 'Transact.user_id' => $user['_id'], 'Transact.DateTime' => new \MongoDate()); $orders = Orders::find('first', array('conditions' => array('_id' => $PO['_id'])))->save($data); $orders = Orders::find('first', array('conditions' => array('_id' => $PO['_id']))); $data = array('Completed' => 'Y', 'Transact.id' => $PO['_id'], 'Transact.username' => $PO['username'], 'Transact.user_id' => $PO['user_id'], 'Transact.DateTime' => new \MongoDate()); $orders = Orders::find('first', array('conditions' => array('_id' => $order_id)))->save($data); $ex->updateBalance($order_id); $ex->updateBalance($PO['_id']); $ex->SendOrderCompleteEmails($order_id, $user['_id']); $ex->SendOrderCompleteEmails($PO['_id'], $PO['user_id']); break; } if ((double) $PO['Amount'] > (double) $Amount) { // Update Previous Order with New Order Amount and New Commission and Transact User if ($PO['Action'] == "Buy") { $PrevCommAmount = round($PO['CommissionPercent'] * $Amount / 100, 8); $CurrCommAmount = round($PO['CommissionPercent'] * ($PO['Amount'] - $Amount) * $PO['PrePrice'] / 100, 8); $PrevCommCurr = $PO['FirstCurrency']; $CurrCommCurr = $PO['SecondCurrency']; } else { $PrevCommAmount = round((double) $PO['CommissionPercent'] * (double) $Amount * (double) $PerPrice / 100, 8); $CurrCommAmount = round($PO['CommissionPercent'] * $Amount / 100, 8); $PrevCommCurr = $PO['SecondCurrency']; $CurrCommCurr = $PO['FirstCurrency']; } $data = array('Commission.Amount' => (double) $PrevCommAmount, 'Amount' => (double) $Amount, 'Completed' => 'Y', 'Transact.id' => $order_id, 'Transact.username' => $user['username'], 'Transact.user_id' => $user['_id'], 'Transact.DateTime' => new \MongoDate(), 'Order' => 'P>C: Update Previous Commission and Amount and Complete Order'); $orders = Orders::find('first', array('conditions' => array('_id' => $PO['_id'])))->save($data); // --------------------Complete // Create new Order for Previous Order so that the order tallies if ($PO['Action'] == "Buy") { $PrevCommAmount = round((double) round((double) $PO['Amount'] - (double) $Amount, 8) * (double) $PO['CommissionPercent'] / 100, 8); } else { $PrevCommAmount = round((double) round((double) $PO['Amount'] - (double) $Amount, 8) * (double) $PO['PerPrice'] * (double) $PO['CommissionPercent'] / 100, 8); } $data = array('Amount' => (double) round((double) $PO['Amount'] - (double) $Amount, 8), 'Action' => $PO['Action'], 'FirstCurrency' => $PO['FirstCurrency'], 'SecondCurrency' => $PO['SecondCurrency'], 'CommissionPercent' => (double) $PO['CommissionPercent'], 'Commission.Amount' => (double) $PrevCommAmount, 'Commission.Currency' => $PrevCommCurr, 'PerPrice' => (double) $PO['PerPrice'], 'DateTime' => $PO['DateTime'], 'Completed' => 'N', 'IP' => $PO['IP'], 'username' => $PO['username'], 'user_id' => $PO['user_id'], 'Order' => 'P>C: Create New Previous Order with Balance details'); $orders = Orders::create(); $orders->save($data); //-------------------Complete //Update New order with Transact User $data = array('Completed' => 'Y', 'Transact.id' => $PO['_id'], 'Transact.username' => $PO['username'], 'Transact.user_id' => $PO['user_id'], 'Transact.DateTime' => new \MongoDate(), 'Order' => 'P>C: Update current order no change in commission or amount'); $orders = Orders::find('first', array('conditions' => array('_id' => $order_id)))->save($data); //---------------------Complete //To update Balance $ex->updateBalance($order_id); $ex->updateBalance($PO['_id']); $ex->SendOrderCompleteEmails($order_id, $user['_id']); $ex->SendOrderCompleteEmails($PO['_id'], $PO['user_id']); break; } if ((double) $PO['Amount'] < (double) $Amount) { // Update Previous Order with New Order Amount and New Commission and Transact User if ($PO['Action'] == "Buy") { $PrevCommAmount = round($PO['CommissionPercent'] * ($PO['Amount'] - $Amount) / 100, 8); $CurrCommAmount = round($PO['CommissionPercent'] * ($PO['Amount'] - $Amount) * $PO['PrePrice'] / 100, 8); $PrevCommCurr = $PO['FirstCurrency']; $CurrCommCurr = $PO['SecondCurrency']; } else { $PrevCommAmount = round($PO['CommissionPercent'] * ($PO['Amount'] - $Amount) * $PO['PerPrice'] / 100, 8); $CurrCommAmount = round($PO['CommissionPercent'] * ($PO['Amount'] - $Amount) / 100, 8); $PrevCommCurr = $PO['SecondCurrency']; $CurrCommCurr = $PO['FirstCurrency']; } if ($PO['Action'] == "Buy") { $PrevCommAmount = round($PO['CommissionPercent'] * $PO['Amount'] / 100, 8); } else { $PrevCommAmount = round($PO['CommissionPercent'] * $PO['Amount'] * $PO['PerPrice'] / 100, 8); } $data = array('Commission.Amount' => (double) $PrevCommAmount, 'Amount' => (double) $PO['Amount'], 'Completed' => 'Y', 'Transact.id' => $order_id, 'Transact.username' => $user['username'], 'Transact.user_id' => $user['_id'], 'Transact.DateTime' => new \MongoDate(), 'Order' => 'P<C: Update Previous Record'); $orders = Orders::find('first', array('conditions' => array('_id' => $PO['_id'])))->save($data); //--------------------Complete // Update current order with new commission and amount if ($PO['Action'] == "Buy") { $CurrCommAmount = round($PO['CommissionPercent'] * $PO['Amount'] * $PO['PerPrice'] / 100, 8); } else { $CurrCommAmount = round($PO['CommissionPercent'] * $PO['Amount'] / 100, 8); } $data = array('Commission.Amount' => (double) $CurrCommAmount, 'Amount' => (double) $PO['Amount'], 'Completed' => 'Y', 'Transact.id' => $PO['_id'], 'Transact.username' => $PO['username'], 'Transact.user_id' => $PO['user_id'], 'Transact.DateTime' => new \MongoDate(), 'Order' => 'P<C: Update current record'); $orders = Orders::find('first', array('conditions' => array('_id' => $order_id)))->save($data); //--------------------Complete //Create a new order of pending amount if ($PO['Action'] == 'Buy') { $CurrCommAmount = round($PO['CommissionPercent'] * (double) round((double) $Amount - (double) $PO['Amount'], 8) * $PerPrice / 100, 8); } else { $CurrCommAmount = round($PO['CommissionPercent'] * (double) round((double) $Amount - (double) $PO['Amount'], 8) / 100, 8); } $data = array('Action' => $Action, 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency, 'CommissionPercent' => (double) $Commission, 'Commission.Amount' => (double) $CurrCommAmount, 'Commission.Currency' => $CurrCommCurr, 'Amount' => (double) round((double) $Amount - (double) $PO['Amount'], 8), 'PerPrice' => (double) $PerPrice, 'DateTime' => new \MongoDate(), 'Completed' => 'N', 'IP' => $_SERVER['REMOTE_ADDR'], 'username' => $user['username'], 'user_id' => $user['_id'], 'Order' => 'P<C: Create New Previous Order with Balance details'); $orders = Orders::create(); $orders->save($data); $ex->updateBalance($order_id); $ex->updateBalance($PO['_id']); $ex->SendOrderCompleteEmails($order_id, $user['_id']); $ex->SendOrderCompleteEmails($PO['_id'], $PO['user_id']); break; } } // =Pending orders================================================================================= //======================Trade======================================================== $Order = Orders::find('first', array('conditions' => array('_id' => $order_id))); $result = array('Order_id' => String::hash($Order['_id']), 'pair' => $pair, 'type' => $type, 'Commission.Amount' => $Order['Commission']['Amount'], 'Commission.Currency' => $Order['Commission']['Currency'], 'amount' => $Order['Amount'], 'price' => $Order['PerPrice'], 'time' => $Order['DateTime']->sec, 'Completed' => $Order['Completed'], 'username' => $Order['username']); return $this->render(array('json' => array('success' => 1, 'now' => time(), 'result' => $result))); } } }
public function x($currency = null) { if ($this->request->query['json'] == true) { $this->_render['type'] = 'json'; } if ($currency == null) { $this->redirect(array('controller' => 'ex', 'action' => 'dashboard/')); } $first_curr = strtoupper(substr($currency, 0, 3)); $second_curr = strtoupper(substr($currency, 4, 3)); $title = $first_curr . "/" . $second_curr; $currencyStatus = Trades::find('first', array('conditions' => array('trade' => $title))); $this->SetGraph($first_curr, $second_curr); $user = Session::read('default'); $id = $user['_id']; // if($id==null){$this->redirect(array('controller'=>'ex','action'=>'dashboard/'));} $details = Details::find('first', array('conditions' => array('user_id' => $id))); // if trade order is submitted by post ---------------- if ($this->request->data) { $data = array('page.refresh' => true); Details::find('all')->save($data); $data = array('refresh' => true); Trades::find('all', array('conditions' => array('trade' => $title)))->save($data); $commission = Parameters::find('first', array('conditions' => array('commission' => true))); $SellMultiple = $this->request->data['SellMultiple']; $BuyMultiple = $this->request->data['BuyMultiple']; $SellIDs = $this->request->data['SellIDs']; $BuyIDs = $this->request->data['BuyIDs']; $Action = $this->request->data['Action']; if ($Action == "Buy") { if ((double) $this->request->data['BuyAmount'] <= 0) { $this->redirect($this->request->params); } if ((double) $this->request->data['BuyPriceper'] <= 0) { $this->redirect($this->request->params); } if ((double) $this->request->data['BuyCommission'] <= 0) { $this->redirect($this->request->params); } if ((double) $this->request->data['BuyCommissionAmount'] <= 0) { $this->redirect($this->request->params); } $PendingAction = 'Sell'; $FirstCurrency = $this->request->data['BuyFirstCurrency']; $SecondCurrency = $this->request->data['BuySecondCurrency']; $Commission = $this->request->data['BuyCommission']; // $CommissionAmount = $this->request->data['BuyCommissionAmount']; $CommissionCurrency = $this->request->data['BuyCommissionCurrency']; $Amount = $this->request->data['BuyAmount']; $PerPrice = $this->request->data['BuyPriceper']; $BalanceAmount = $details['balance'][$SecondCurrency]; $CommissionAmount = $Amount * $commission['value'] / 100; $NewBalanceAmount = round($BalanceAmount - $Amount * $PerPrice, 8); $Currency = 'balance.' . $SecondCurrency; // Update balance of user with NewBalance Amount $data = array('balance.' . $SecondCurrency => (double) $NewBalanceAmount); $details = Details::find('first', array('conditions' => array('user_id' => $id)))->save($data); } if ($Action == "Sell") { if ((double) $this->request->data['SellAmount'] <= 0) { $this->redirect($this->request->params); } if ((double) $this->request->data['SellPriceper'] <= 0) { $this->redirect($this->request->params); } if ((double) $this->request->data['SellCommission'] <= 0) { $this->redirect($this->request->params); } if ((double) $this->request->data['SellCommissionAmount'] <= 0) { $this->redirect($this->request->params); } $PendingAction = 'Buy'; $FirstCurrency = $this->request->data['SellFirstCurrency']; $SecondCurrency = $this->request->data['SellSecondCurrency']; $Commission = $this->request->data['SellCommission']; // $CommissionAmount = $this->request->data['SellCommissionAmount']; $CommissionCurrency = $this->request->data['SellCommissionCurrency']; $Amount = $this->request->data['SellAmount']; $PerPrice = $this->request->data['SellPriceper']; $BalanceAmount = $details['balance'][$FirstCurrency]; $CommissionAmount = $Amount * $PerPrice * $commission['value'] / 100; $NewBalanceAmount = round($BalanceAmount - $Amount, 8); $Currency = 'balance.' . $FirstCurrency; // Update balance of user with NewBalance Amount $data = array('balance.' . $FirstCurrency => (double) $NewBalanceAmount); $details = Details::find('first', array('conditions' => array('user_id' => $id)))->save($data); } $data = array('Action' => $Action, 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency, 'CommissionPercent' => (double) $Commission, 'Commission.Amount' => (double) $CommissionAmount, 'Commission.Currency' => $CommissionCurrency, 'Amount' => (double) $Amount, 'PerPrice' => (double) $PerPrice, 'DateTime' => new \MongoDate(), 'Completed' => 'N', 'IP' => $_SERVER['REMOTE_ADDR'], 'username' => $user['username'], 'user_id' => $user['_id']); // Create Order for the user $orders = Orders::create(); $orders->save($data); $order_id = $orders->_id; $this->SendEmails($order_id, $user['_id']); // $this->SendFriendsEmails($order_id,$user['_id']); /* if($PendingAction=="Buy"){ $PendingOrders = Orders::find('all', array( 'conditions'=> array( 'Action' => $PendingAction, 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency, 'Completed' => 'N', 'user_id' => array('$ne' => $user['_id']), 'PerPrice' => array('$gte'=>(float)($PerPrice)), ), 'order'=>array('DateTime'=>'ASC') )); } if($PendingAction=="Sell"){ $PendingOrders = Orders::find('all', array( 'conditions'=> array( 'Action' => $PendingAction, 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency, 'Completed' => 'N', 'user_id' => array('$ne' => $user['_id']), 'PerPrice' => array('$lte'=>(float)($PerPrice)), ), 'order'=>array('DateTime'=>'ASC') )); } foreach($PendingOrders as $PO){ $PreviousOrder = $this->ChangePreviousOrder($PO['_id'],$order_id,$PerPrice,$user); $this->updateBalance($PO['_id']); $this->SendOrderCompleteEmails($PO['_id'],$PO['user_id']); $NewOrder = $this->ChangeCurrentOrder($order_id,$PO['_id'],$PO['Amount'],$user); $this->updateBalance($order_id); $this->SendOrderCompleteEmails($order_id,$user['_id']); if($NewOrder==false){ break; } $order_id = $NewOrder; } // exit; $this->redirect($this->request->params); // get out of this page and load the page again without POST! */ if ($SellMultiple == "Y" || $BuyMultiple == "Y") { if ($SellMultiple == "Y") { $IDs = $SellIDs; } if ($BuyMultiple == "Y") { $IDs = $BuyIDs; } $ids = explode(",", $IDs); foreach ($ids as $id) { if ($id != "") { $PO = Orders::find('first', array('conditions' => array('_id' => new MongoID($id)))); // print_r($PO['user_id']); // print_r($PO['username']); $data = array('Completed' => 'Y', 'Transact.id' => $order_id, 'Transact.username' => $user['username'], 'Transact.user_id' => $user['_id'], 'Transact.DateTime' => new \MongoDate()); $orders = Orders::find('first', array('conditions' => array('_id' => $PO['_id'])))->save($data); $orders = Orders::find('first', array('conditions' => array('_id' => $PO['_id']))); $data = array('Completed' => 'Y', 'Transact.id' => $PO['_id'], 'Transact.username' => $PO['username'], 'Transact.user_id' => $PO['user_id'], 'Transact.DateTime' => new \MongoDate()); $orders = Orders::find('first', array('conditions' => array('_id' => $order_id)))->save($data); $this->updateBalance($order_id); $this->updateBalance($PO['_id']); $this->SendOrderCompleteEmails($order_id, $user['_id']); $this->SendOrderCompleteEmails($PO['_id'], $PO['user_id']); } } $this->redirect($this->request->params); } //Start FOR loop----------------------------------------------------- $PendingOrders = Orders::find('all', array('conditions' => array('Action' => $PendingAction, 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency, 'Completed' => 'N', 'user_id' => array('$ne' => $user['_id']), 'PerPrice' => (double) $PerPrice), 'order' => array('DateTime' => 'ASC'))); foreach ($PendingOrders as $PO) { if ((double) $PO['Amount'] == (double) $Amount) { $data = array('Completed' => 'Y', 'Transact.id' => $order_id, 'Transact.username' => $user['username'], 'Transact.user_id' => $user['_id'], 'Transact.DateTime' => new \MongoDate()); $orders = Orders::find('first', array('conditions' => array('_id' => $PO['_id'])))->save($data); $orders = Orders::find('first', array('conditions' => array('_id' => $PO['_id']))); $data = array('Completed' => 'Y', 'Transact.id' => $PO['_id'], 'Transact.username' => $PO['username'], 'Transact.user_id' => $PO['user_id'], 'Transact.DateTime' => new \MongoDate()); $orders = Orders::find('first', array('conditions' => array('_id' => $order_id)))->save($data); $this->updateBalance($order_id); $this->updateBalance($PO['_id']); $this->SendOrderCompleteEmails($order_id, $user['_id']); $this->SendOrderCompleteEmails($PO['_id'], $PO['user_id']); break; } if ((double) $PO['Amount'] > (double) $Amount) { // Update Previous Order with New Order Amount and New Commission and Transact User if ($PO['Action'] == "Buy") { $PrevCommAmount = round($PO['CommissionPercent'] * $Amount / 100, 8); $CurrCommAmount = round($PO['CommissionPercent'] * ($PO['Amount'] - $Amount) * $PO['PrePrice'] / 100, 8); $PrevCommCurr = $PO['FirstCurrency']; $CurrCommCurr = $PO['SecondCurrency']; } else { $PrevCommAmount = round((double) $PO['CommissionPercent'] * (double) $Amount * (double) $PerPrice / 100, 8); $CurrCommAmount = round($PO['CommissionPercent'] * $Amount / 100, 8); $PrevCommCurr = $PO['SecondCurrency']; $CurrCommCurr = $PO['FirstCurrency']; } $data = array('Commission.Amount' => (double) $PrevCommAmount, 'Amount' => (double) $Amount, 'Completed' => 'Y', 'Transact.id' => $order_id, 'Transact.username' => $user['username'], 'Transact.user_id' => $user['_id'], 'Transact.DateTime' => new \MongoDate(), 'Order' => 'P>C: Update Previous Commission and Amount and Complete Order'); $orders = Orders::find('first', array('conditions' => array('_id' => $PO['_id'])))->save($data); // --------------------Complete // Create new Order for Previous Order so that the order tallies if ($PO['Action'] == "Buy") { $PrevCommAmount = round((double) round((double) $PO['Amount'] - (double) $Amount, 8) * (double) $PO['CommissionPercent'] / 100, 8); } else { $PrevCommAmount = round((double) round((double) $PO['Amount'] - (double) $Amount, 8) * (double) $PO['PerPrice'] * (double) $PO['CommissionPercent'] / 100, 8); } $data = array('Amount' => (double) round((double) $PO['Amount'] - (double) $Amount, 8), 'Action' => $PO['Action'], 'FirstCurrency' => $PO['FirstCurrency'], 'SecondCurrency' => $PO['SecondCurrency'], 'CommissionPercent' => (double) $PO['CommissionPercent'], 'Commission.Amount' => (double) $PrevCommAmount, 'Commission.Currency' => $PrevCommCurr, 'PerPrice' => (double) $PO['PerPrice'], 'DateTime' => $PO['DateTime'], 'Completed' => 'N', 'IP' => $PO['IP'], 'username' => $PO['username'], 'user_id' => $PO['user_id'], 'Order' => 'P>C: Create New Previous Order with Balance details'); $orders = Orders::create(); $orders->save($data); //-------------------Complete //Update New order with Transact User $data = array('Completed' => 'Y', 'Transact.id' => $PO['_id'], 'Transact.username' => $PO['username'], 'Transact.user_id' => $PO['user_id'], 'Transact.DateTime' => new \MongoDate(), 'Order' => 'P>C: Update current order no change in commission or amount'); $orders = Orders::find('first', array('conditions' => array('_id' => $order_id)))->save($data); //---------------------Complete //To update Balance $this->updateBalance($order_id); $this->updateBalance($PO['_id']); $this->SendOrderCompleteEmails($order_id, $user['_id']); $this->SendOrderCompleteEmails($PO['_id'], $PO['user_id']); break; } if ((double) $PO['Amount'] < (double) $Amount) { // Update Previous Order with New Order Amount and New Commission and Transact User if ($PO['Action'] == "Buy") { $PrevCommAmount = round($PO['CommissionPercent'] * ($PO['Amount'] - $Amount) / 100, 8); $CurrCommAmount = round($PO['CommissionPercent'] * ($PO['Amount'] - $Amount) * $PO['PrePrice'] / 100, 8); $PrevCommCurr = $PO['FirstCurrency']; $CurrCommCurr = $PO['SecondCurrency']; } else { $PrevCommAmount = round($PO['CommissionPercent'] * ($PO['Amount'] - $Amount) * $PO['PerPrice'] / 100, 8); $CurrCommAmount = round($PO['CommissionPercent'] * ($PO['Amount'] - $Amount) / 100, 8); $PrevCommCurr = $PO['SecondCurrency']; $CurrCommCurr = $PO['FirstCurrency']; } if ($PO['Action'] == "Buy") { $PrevCommAmount = round($PO['CommissionPercent'] * $PO['Amount'] / 100, 8); } else { $PrevCommAmount = round($PO['CommissionPercent'] * $PO['Amount'] * $PO['PerPrice'] / 100, 8); } $data = array('Commission.Amount' => (double) $PrevCommAmount, 'Amount' => (double) $PO['Amount'], 'Completed' => 'Y', 'Transact.id' => $order_id, 'Transact.username' => $user['username'], 'Transact.user_id' => $user['_id'], 'Transact.DateTime' => new \MongoDate(), 'Order' => 'P<C: Update Previous Record'); $orders = Orders::find('first', array('conditions' => array('_id' => $PO['_id'])))->save($data); //--------------------Complete // Update current order with new commission and amount if ($PO['Action'] == "Buy") { $CurrCommAmount = round($PO['CommissionPercent'] * $PO['Amount'] * $PO['PerPrice'] / 100, 8); } else { $CurrCommAmount = round($PO['CommissionPercent'] * $PO['Amount'] / 100, 8); } $data = array('Commission.Amount' => (double) $CurrCommAmount, 'Amount' => (double) $PO['Amount'], 'Completed' => 'Y', 'Transact.id' => $PO['_id'], 'Transact.username' => $PO['username'], 'Transact.user_id' => $PO['user_id'], 'Transact.DateTime' => new \MongoDate(), 'Order' => 'P<C: Update current record'); $orders = Orders::find('first', array('conditions' => array('_id' => $order_id)))->save($data); //--------------------Complete //Create a new order of pending amount if ($PO['Action'] == 'Buy') { $CurrCommAmount = round($PO['CommissionPercent'] * (double) round((double) $Amount - (double) $PO['Amount'], 8) * $PerPrice / 100, 8); } else { $CurrCommAmount = round($PO['CommissionPercent'] * (double) round((double) $Amount - (double) $PO['Amount'], 8) / 100, 8); } $data = array('Action' => $Action, 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency, 'CommissionPercent' => (double) $Commission, 'Commission.Amount' => (double) $CurrCommAmount, 'Commission.Currency' => $CurrCommCurr, 'Amount' => (double) round((double) $Amount - (double) $PO['Amount'], 8), 'PerPrice' => (double) $PerPrice, 'DateTime' => new \MongoDate(), 'Completed' => 'N', 'IP' => $_SERVER['REMOTE_ADDR'], 'username' => $user['username'], 'user_id' => $user['_id'], 'Order' => 'P<C: Create New Previous Order with Balance details'); $orders = Orders::create(); $orders->save($data); $this->updateBalance($order_id); $this->updateBalance($PO['_id']); $this->SendOrderCompleteEmails($order_id, $user['_id']); $this->SendOrderCompleteEmails($PO['_id'], $PO['user_id']); break; } } // End FOR Loop ----------------------------------- // exit; // Temporary EXIT $this->redirect($this->request->params); // get out of this page and load the page again without POST! } // submitted by post! // without POST... load the page! $details = Details::find('first', array('conditions' => array('user_id' => $id))); $mongodb = Connections::get('default')->connection; $TotalSellOrders = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 0, 'Action' => '$Action', 'Amount' => '$Amount', 'Completed' => '$Completed', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency', 'TotalAmount' => array('$multiply' => array('$Amount', '$PerPrice')))), array('$match' => array('Action' => 'Sell', 'Completed' => 'N', 'FirstCurrency' => $first_curr, 'SecondCurrency' => $second_curr)), array('$group' => array('_id' => array(), 'Amount' => array('$sum' => '$Amount'), 'TotalAmount' => array('$sum' => '$TotalAmount'))), array('$sort' => array('PerPrice' => 1))))); $TotalBuyOrders = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 0, 'Action' => '$Action', 'Amount' => '$Amount', 'Completed' => '$Completed', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency', 'TotalAmount' => array('$multiply' => array('$Amount', '$PerPrice')))), array('$match' => array('Action' => 'Buy', 'Completed' => 'N', 'FirstCurrency' => $first_curr, 'SecondCurrency' => $second_curr)), array('$group' => array('_id' => array(), 'Amount' => array('$sum' => '$Amount'), 'TotalAmount' => array('$sum' => '$TotalAmount'))), array('$sort' => array('PerPrice' => 1))))); $SellOrders = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 1, 'Action' => '$Action', 'Amount' => '$Amount', 'user_id' => '$user_id', 'username' => '$username', 'PerPrice' => '$PerPrice', 'Completed' => '$Completed', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency')), array('$match' => array('Action' => 'Sell', 'Completed' => 'N', 'FirstCurrency' => $first_curr, 'SecondCurrency' => $second_curr)), array('$group' => array('_id' => array('PerPrice' => '$PerPrice', 'username' => '$username', 'user_id' => '$user_id', 'id' => '$_id'), 'Amount' => array('$sum' => '$Amount'), 'No' => array('$sum' => 1))), array('$sort' => array('_id.PerPrice' => 1)), array('$limit' => 20)))); $BuyOrders = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 1, 'Action' => '$Action', 'Amount' => '$Amount', 'user_id' => '$user_id', 'username' => '$username', 'PerPrice' => '$PerPrice', 'Completed' => '$Completed', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency')), array('$match' => array('Action' => 'Buy', 'Completed' => 'N', 'FirstCurrency' => $first_curr, 'SecondCurrency' => $second_curr)), array('$group' => array('_id' => array('PerPrice' => '$PerPrice', 'username' => '$username', 'user_id' => '$user_id', 'id' => '$_id'), 'Amount' => array('$sum' => '$Amount'), 'No' => array('$sum' => 1))), array('$sort' => array('_id.PerPrice' => -1)), array('$limit' => 20)))); $YourOrders = Orders::find('all', array('conditions' => array('user_id' => $id, 'Completed' => 'N', 'FirstCurrency' => $first_curr, 'SecondCurrency' => $second_curr), 'order' => array('DateTime' => -1))); $YourCompleteOrders = Orders::find('all', array('conditions' => array('user_id' => $id, 'Completed' => 'Y', 'FirstCurrency' => $first_curr, 'SecondCurrency' => $second_curr), 'order' => array('DateTime' => -1))); $page = Pages::find('first', array('conditions' => array('pagename' => 'ex/x/' . $currency))); $this->SetForecastGraph($SellOrders, $BuyOrders, $first_curr, $second_curr); $title = $page['title']; $keywords = $page['keywords']; $description = $page['description']; $settings = Settings::find('first'); return compact('title', 'details', 'SellOrders', 'BuyOrders', 'TotalSellOrders', 'TotalBuyOrders', 'YourOrders', 'YourCompleteOrders', 'keywords', 'description', 'settings', 'currencyStatus'); }
public function hard() { if ($this->__init() == false) { $this->redirect('ex::dashboard'); } if ($this->request->data) { $Withdrawal = Parameters::find('all')->save($this->request->data); } $Withdrawal = Parameters::find('first'); return compact('Withdrawal'); }
public function funding_ltc() { $title = "Funding LTC"; $user = Session::read('default'); if ($user == "") { return $this->redirect('/login'); } $id = $user['_id']; $details = Details::find('first', array('conditions' => array('user_id' => (string) $id))); $secret = $details['secret']; $userid = $details['user_id']; $paytxfee = Parameters::find('first'); $txfee = $paytxfee['payltctxfee']; $transactions = Transactions::find('first', array('conditions' => array('username' => $user['username'], 'Added' => false, 'Paid' => 'No', 'Currency' => 'LTC'))); return compact('details', 'address', 'txfee', 'title', 'transactions', 'user'); }
<?php use app\models\Parameters; $Comm = Parameters::find('first'); ?> <h3>FAQ</h3> <p><strong><u>Become a Customer</u></strong></p> <blockquote>To become an SiiCrypto customer please click <a href="/users/signup">signup</a>. Registration implies you have read and agreed to our <a href="/company/termsofservice">Terms of Service.</a> </blockquote> <p><strong><u>Fees</u></strong></p> <blockquote><ul> <li>We charge <strong><?php echo $Comm['value']; ?> </strong>% per transaction.</li> <li>If you <strong>buy</strong> 1 Bitcoin our fee is <strong><?php echo $Comm['value'] / 100; ?> </strong> Bitcoins.</li> <li>If you <strong>sell</strong> $100 worth of Bitcoins our fee is <strong><?php echo $Comm['value'] * 100; ?> </strong> cent.</li> </ul> </blockquote> <p><strong><u>Deposits/Withdrawals</u></strong></p> <blockquote> <ul>
public function CheckServer() { $parameters = Parameters::find('first'); if ($parameters['server'] == true) { return $this->render(array('json' => array('Refresh' => 'Yes'))); } else { return $this->render(array('json' => array('Refresh' => 'No'))); } }
<?php use lithium\storage\Session; use app\models\Pages; use app\models\Details; use app\models\Parameters; if (!isset($title)) { $page = Pages::find('first', array('conditions' => array('pagename' => 'home'))); $title = $page['title']; $keywords = $page['keywords']; $description = $page['description']; } $user = Session::read('default'); $detail = Details::find("first", array("conditions" => array("user_id" => $user["_id"]))); $parameters = Parameters::find('first'); //Pagetime Start $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $pagestarttime = $mtime; //Pagetime End ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <?php echo $this->html->charset(); ?>
public function Commission() { $commission = Parameters::find('first', array('conditions' => array('commission' => true))); return $this->render(array('json' => array('Commission' => $commission['value']))); }