public function updatePart() { $completedDeals = Deal::findBy(array('OrderId' => $this->id, 'Done' => 1)); $volumes = array_map(function ($deals) { return $deals['Volume']; }, $completedDeals); $volumes = array_sum($volumes); $this->part = $volumes / $this->volume; }
public static function rateInfo($firstCurName = null, $secondCurName = null) { $isAjax = 0; if ($firstCurName == null) { $firstCurName = Core::validate(self::getVar('firstCurrency')); $isAjax = 1; } if ($secondCurName == null) { $secondCurName = Core::validate(self::getVar('secondCurrency')); $isAjax = 1; } $rate = self::getRate($firstCurName, $secondCurName); if ($rate == null) { return; } $searchConditions['RateId'] = $rate->getId(); $searchConditions['Done'] = 0; $searchConditions['Type'] = 0; $buyDeals = Deal::findBy($searchConditions); $searchConditions['Type'] = 1; $sellDeals = Deal::findBy($searchConditions); $priceVolume = array_map(function ($deals) { return $deals['Volume'] * $deals['Price']; }, $buyDeals); $total_price = array_sum($priceVolume); $volumes = array_map(function ($deals) { return $deals['Volume']; }, $sellDeals); $total_volume = array_sum($volumes); $data['bid'] = $rate->getBid(); $data['ask'] = $rate->getAsk(); $data['total_volume'] = $total_volume; $data['total_price'] = $total_price; $result['data'] = $data; if ($isAjax == 0) { return $data; } print json_encode($data); }
private static function refreshRatePrices(Rate $rate) { $where['RateId'] = $rate->getId(); $where['Done'] = 0; $where['Type'] = OrderType::BUY; $buyDeals = Deal::findBy($where); $where['Type'] = OrderType::SELL; $sellDeals = Deal::findBy($where); $getOnlyPrices = function ($deals) { return $deals['Price']; }; $isUpdated = false; if (!empty($buyDeals)) { $buyPrices = array_map($getOnlyPrices, $buyDeals); $bid = max($buyPrices); if ($rate->getBid() != $bid) { $rate->setBid($bid); $rate->save(); $isUpdated = true; } } if (!empty($sellDeals)) { $sellPrices = array_map($getOnlyPrices, $sellDeals); $ask = min($sellPrices); if ($rate->getAsk() != $ask) { $rate->setAsk($ask); $rate->save(); $isUpdated = true; } } return $isUpdated; }