/** * This command echoes what you have entered as the message. * @param string $message the message to be echoed. */ public function actionIndex() { foreach (self::$ticks as $tick) { //Pide la ultima de todas $curl = new curl\Curl(); $response = json_decode($curl->get('https://cex.io/api/trade_history/' . $tick), true); $lastCex = $response[0]['tid']; $lastSaved = -1; do { if ($lastSaved == -1) { $lastTid = new Query(); $lastTid = $lastTid->select('max(tid) as tid')->from('trades')->where(['tick' => $tick])->one(); $lastTid = $lastTid['tid']; if (!is_null($lastTid)) { $since = $lastTid + 1; } else { $since = 1; } } else { $since = $lastSaved + 1; } $response = json_decode($curl->get('https://cex.io/api/trade_history/' . $tick . '/?since=' . $since), true); $index = count($response); $nine = $index - 1; echo 'Since:' . $since . ', Res:' . $response[$nine]['tid'] . '\\r\\n'; if ($response[$nine]['tid'] < $since) { if ($since - $response[$nine]['tid'] < 1000) { $index = $nine - ($since - $response[$nine]['tid']); } else { $since += $since - $response[$nine]['tid']; $response = json_decode($curl->get('https://cex.io/api/trade_history/' . $tick . '/?since=' . $since), true); } } while ($index) { $trade = $response[--$index]; $tradeModel = new Trades(); $tradeModel->tick = $tick; $tradeModel->type = $trade['type']; $tradeModel->date = $trade['date']; $tradeModel->amount = $trade['amount']; $tradeModel->price = $trade['price']; $tradeModel->tid = $trade['tid']; if ($tradeModel->save() && $tradeModel->tid > $lastSaved) { $lastSaved = $tradeModel->tid; } else { var_dump($tradeModel->errors); } unset($tradeModel); } } while ($lastSaved < $lastCex); } }
public function Rates($FirstCurrency = "BTC", $SecondCurrency = "USD") { $title = $FirstCurrency . "/" . $SecondCurrency; $back = strtolower($FirstCurrency . "_" . $SecondCurrency); $Refresh = "No"; $user = Session::read('member'); $id = $user['_id']; $details = Details::find('first', array('conditions' => array('user_id' => $id))); if ($details['page.refresh'] == true || $details['page.refresh'] == 1) { $data = array('page.refresh' => false); Details::find('all', array('conditions' => array('user_id' => $id)))->save($data); $Refresh = "Yes"; } $URL = "/" . $locale . 'ex/x/' . $back; $trades = Trades::find('first', array('conditions' => array('trade' => $title))); if ($trades['refresh'] == true || $trades['refresh'] == 1) { $data = array('refresh' => false); Trades::find('all', array('conditions' => array('trade' => $title)))->save($data); $Refresh = "Yes"; } $mongodb = Connections::get('default')->connection; $Rates = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 0, 'Action' => '$Action', 'PerPrice' => '$PerPrice', 'Completed' => '$Completed', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency', 'TransactDateTime' => '$Transact.DateTime')), array('$match' => array('Completed' => 'Y', 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency)), array('$group' => array('_id' => array('year' => array('$year' => '$TransactDateTime'), 'month' => array('$month' => '$TransactDateTime'), 'day' => array('$dayOfMonth' => '$TransactDateTime')), 'min' => array('$min' => '$PerPrice'), 'max' => array('$max' => '$PerPrice'))), array('$sort' => array('_id.year' => -1, '_id.month' => -1, '_id.day' => -1)), array('$limit' => 1)))); // print_r($Rates['result']); foreach ($Rates['result'] as $r) { $Low = $r['min']; $High = $r['max']; } $Last = Orders::find('all', array('conditions' => array('Completed' => 'Y', 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency), 'limit' => 1, 'order' => array('Transact.DateTime' => 'DESC'))); foreach ($Last as $l) { $LastPrice = $l['PerPrice']; } $TotalOrders = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 0, 'Action' => '$Action', 'Amount' => '$Amount', 'Completed' => '$Completed', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency', 'TransactDateTime' => '$Transact.DateTime', 'TotalAmount' => array('$multiply' => array('$Amount', '$PerPrice')))), array('$match' => array('Completed' => 'Y', 'Action' => 'Buy', 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency)), array('$group' => array('_id' => array('year' => array('$year' => '$TransactDateTime'), 'month' => array('$month' => '$TransactDateTime')), 'Amount' => array('$sum' => '$Amount'), 'TotalAmount' => array('$sum' => '$TotalAmount'))), array('$sort' => array('_id.year' => -1, '_id.month' => -1)), array('$limit' => 1)))); // print_r($SecondCurrency); return $this->render(array('json' => array('Refresh' => $Refresh, 'URL' => $URL, 'Low' => number_format($Low, 5), 'High' => number_format($High, 5), 'Last' => number_format($LastPrice, 5), 'VolumeFirst' => number_format($TotalOrders['result'][0]['Amount'], 5), 'VolumeSecond' => number_format($TotalOrders['result'][0]['TotalAmount'], 3), 'VolumeFirstUnit' => $FirstCurrency, 'VolumeSecondUnit' => $SecondCurrency))); }
public function index() { $usernameX = "SiiUserA"; $details = Details::find('first', array('conditions' => array('username' => 'SiiUserA'))); if ($usernameX == $details['username']) { $keyX = $details['key']; } $usernameY = "SiiUserB"; $details = Details::find('first', array('conditions' => array('username' => 'SiiUserB'))); if ($usernameY == $details['username']) { $keyY = $details['key']; } $trades = Trades::find('all'); foreach ($trades as $trade) { $pair = substr($trade['trade'], 0, 3) . "_" . substr($trade['trade'], 4, 3); $amount = $trade['amount'] + $this->float_rand(0, 1, 3); $price = $trade['Base'] + $this->float_rand(0, 0.5, 4); if (round($this->float_rand(0, 1, 0), 0) != 0) { $ActionX = "Buy"; // $usernameX = "SiiUserA"; $ActionY = "Sell"; // $usernameY = "SiiUserB"; $nounce = time(); } else { $ActionX = "Sell"; // $usernameX = "SiiUserB"; $ActionY = "Buy"; // $usernameY = "SiiUserA"; $nounce = time(); } $url = "https://spotcrypto.com/API/Trade/" . $keyX; $fields = array(); $fields_string = ""; $fields = array('type' => $ActionX, 'pair' => $pair, 'amount' => $amount, 'price' => $price, 'nounce' => $nounce); print_r($pair); foreach ($fields as $key => $value) { $fields_string .= $key . '=' . $value . '&'; } rtrim($fields_string, '&'); print_r("\n"); print_r($url); print_r("\n"); print_r($fields_string); print_r("\n"); $useragent = "Mozilla 5.0 "; $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_USERAGENT, $useragent); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_VERBOSE, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //execute post $result = curl_exec($ch); curl_close($ch); /////////////////////////////////////////////////////////////////////////////////// $fields = array(); $fields_string = ""; $url = "https://spotcrypto.com/API/Trade/" . $keyY; $fields = array('type' => $ActionY, 'pair' => $pair, 'amount' => $amount, 'price' => $price, 'nounce' => $nounce); print_r($pair); foreach ($fields as $key => $value) { $fields_string .= $key . '=' . $value . '&'; } rtrim($fields_string, '&'); print_r("\n"); print_r($url); print_r("\n"); print_r($fields_string); print_r("\n"); $useragent = "Mozilla 5.0 "; $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_USERAGENT, $useragent); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_VERBOSE, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //execute post $result = curl_exec($ch); curl_close($ch); } }
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))); } } }
<ul class="nav navbar-nav navbar-right"> <?php if ($user != "") { ?> <li ><a href='#' class='dropdown-toggle' data-toggle='dropdown' > <?php echo $user['username']; ?> <i class='glyphicon glyphicon-chevron-down'></i> </a> <ul class="dropdown-menu"> <li><a href="/users/settings"><i class="fa fa-gears"></i> Settings</a></li> <li><a href="/ex/dashboard"><i class="fa fa-dashboard"></i> Dashboard</a></li> <li class="divider"></li> <?php $trades = Trades::find('all'); $currencies = array(); $VirtualCurr = array(); $FiatCurr = array(); foreach ($trades as $tr) { $first_curr = substr($tr['trade'], 0, 3); array_push($currencies, $first_curr); $second_curr = substr($tr['trade'], 4, 3); array_push($currencies, $second_curr); if ($tr['FirstType'] == 'Virtual') { array_push($VirtualCurr, $first_curr); } else { array_push($VirtualCurr, $first_curr); } if ($tr['SecondType'] == 'Virtual') { array_push($VirtualCurr, $second_curr);
public function dashboard() { if ($this->request->query['json'] == true) { $this->_render['type'] = 'json'; } $user = Session::read('default'); $id = $user['_id']; if ($user == "") { return $this->redirect('/login'); exit; } $details = Details::find('first', array('conditions' => array('user_id' => $id))); $trades = Trades::find('all'); $YourOrders = array(); foreach ($trades as $t) { $YourOrders['Buy'] = $this->YourOrders($id, 'Buy', substr($t['trade'], 0, 3), substr($t['trade'], 4, 3)); $YourOrders['Sell'] = $this->YourOrders($id, 'Sell', substr($t['trade'], 0, 3), substr($t['trade'], 4, 3)); $YourCompleteOrders['Buy'] = $this->YourCompleteOrders($id, 'Buy', substr($t['trade'], 0, 3), substr($t['trade'], 4, 3)); $YourCompleteOrders['Sell'] = $this->YourCompleteOrders($id, 'Sell', substr($t['trade'], 0, 3), substr($t['trade'], 4, 3)); } $Commissions = $this->TotalCommissions($id); $CompletedCommissions = $this->CompletedTotalCommissions($id); $RequestFriends = $this->RequestFriend($id); $UsersRegistered = Details::count(); $functions = new Functions(); $OnlineUsers = $functions->OnlineUsers(); foreach ($trades as $t) { $TotalOrders['Buy'] = $this->TotalOrders($id, 'Buy', substr($t['trade'], 0, 3), substr($t['trade'], 4, 3)); $TotalOrders['Sell'] = $this->TotalOrders($id, 'Sell', substr($t['trade'], 0, 3), substr($t['trade'], 4, 3)); $TotalCompleteOrders['Buy'] = $this->TotalCompleteOrders($id, 'Buy', substr($t['trade'], 0, 3), substr($t['trade'], 4, 3)); $TotalCompleteOrders['Sell'] = $this->TotalCompleteOrders($id, 'Sell', substr($t['trade'], 0, 3), substr($t['trade'], 4, 3)); } $title = "Dashboard"; $keywords = "Dashboard, trading platform, bitcoin exchange, we trust, United Kingdom, UK"; $description = "Dashboard for trading platform for bitcoin exchange in United Kingdom, UK"; $settings = Settings::find('first'); return compact('title', 'details', 'YourOrders', 'Commissions', 'CompletedCommissions', 'YourCompleteOrders', 'RequestFriends', 'UsersRegistered', 'OnlineUsers', 'TotalOrders', 'TotalCompleteOrders', 'keywords', 'description', 'settings'); }
public function play() { $details = Details::find('all', array('conditions' => array('username' => array('$regex' => 'SiiCrypto.comUser')))); $trades = Trades::find('all'); return compact('details', 'trades'); }
<?php use app\models\Parameters; use app\models\Pages; use app\models\Orders; use app\models\Trades; use lithium\core\Environment; use lithium\data\Connections; $Comm = Parameters::find('first'); $howmany = 100; $tradesV = Trades::find('first', array('conditions' => array('SecondType' => 'Virtual'), 'limit' => $howmany, 'order' => array('order' => 1))); $first_currency = substr($tradesV['trade'], 0, 3); $second_currency = substr($tradesV['trade'], 4, 3); $tradesVF = Trades::find('all', array('conditions' => array('SecondType' => 'Fiat'), 'limit' => $howmany, 'order' => array('order' => -1))); $trades = Trades::find('all', array('limit' => $howmany, 'order' => array('order' => 1))); $mongodb = Connections::get('default')->connection; $Rates = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 0, 'Action' => '$Action', 'PerPrice' => '$PerPrice', 'Completed' => '$Completed', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency', 'TransactDateTime' => '$Transact.DateTime')), array('$match' => array('Completed' => 'Y')), array('$group' => array('_id' => array('FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency', 'year' => array('$year' => '$TransactDateTime'), 'month' => array('$month' => '$TransactDateTime'), 'day' => array('$dayOfMonth' => '$TransactDateTime')), 'min' => array('$min' => '$PerPrice'), 'avg' => array('$avg' => '$PerPrice'), 'max' => array('$max' => '$PerPrice'), 'last' => array('$last' => '$PerPrice'))), array('$sort' => array('_id.year' => -1, '_id.month' => -1, '_id.day' => -1, '_id.hour' => -1)), array('$limit' => count($trades))))); ?> <p> </p> <div class="container-fluid"> <div class="row placeholders"> <?php foreach ($tradesVF as $tradeVF) { if (substr($tradeVF['trade'], 0, 3) == $second_currency) { ?> <div class="col-xs-6 col-sm-6 placeholder" style="text-align:center"> <h4><?php echo $tradeVF['trade']; ?> </h4> <?php