public static function priceDifference() { $orderId = Core::validate(self::getVar('orderId')); if ($orderId == null) { self::printErrorJson("not all parameters are defined"); return; } $order = new Order(); if (!$order->findById($orderId)) { self::printErrorJson("order with id = '{$orderId}' is not exist"); return; } $rate = new Rate(); $rate->findById($order->getRateId()); $result['success'] = 1; $result['return'] = $order->getType() == OrderType::BUY ? $rate->getBid() - $order->getPrice() : $rate->getAsk() - $order->getPrice(); print json_encode($result); }
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; }