public function actionTest() { if ($_SERVER['HTTP_HOST'] !== 'btcbot.loc') { return; } $start = time(); Yii::app()->cache->flush(); Yii::app()->db->createCommand()->truncateTable(Buy::model()->tableName()); Yii::app()->db->createCommand()->truncateTable(Sell::model()->tableName()); Yii::app()->db->createCommand()->truncateTable(Order::model()->tableName()); Yii::app()->db->createCommand()->truncateTable(Balance::model()->tableName()); Status::setParam('balance', 5000); Status::setParam('balance_btc', 0); $exs = Exchange::getAll(); $cnt = 0; foreach ($exs as $exchange) { $obj = new stdClass(); $obj->dtm = $exchange['dt']; $obj->buy = $exchange['buy']; $obj->sell = $exchange['sell']; $cnt++; $bot = new Bot($obj); $bot->run(); } $end = time(); echo '<b>Время выполнения: ' . ($end - $start) / 60 . ' мин.<br/>'; echo '<b>Сделано шагов: ' . $cnt . '<br/>'; //$this->render('index'); }
public static function NOSQL_getAvg($name, $from, $to) { $key = 'nosql.exchange.getavg.' . $name . '-' . $from . '-' . $to; $val = Yii::app()->cache->get($key); if ($val) { return $val; } $list = Exchange::getAll(); $sum = 0; $cnt = 0; foreach ($list as $item) { if ($item['dt'] >= $from && $item['dt'] <= $to) { $sum += $item[$name]; $cnt++; } elseif ($item['dt'] > $to) { break; } } if ($cnt > 0) { $val = $sum / $cnt; } else { $val = false; } Yii::app()->cache->set($key, $val, 60 * 60); return $val; }