Exemple #1
0
 public function actionTest()
 {
     $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());
     // Тест на 10 000 руб.
     Status::setParam('balance', 10000);
     Status::setParam('balance_btc', 0);
     $exs = Exchange::getAllByDt('btc_rur', '2013-12-16', '2014-01-06');
     $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>Elapsed time: ' . ($end - $start) / 60 . ' min.<br/>';
     echo '<b>Steps count: ' . $cnt . '<br/>';
 }
Exemple #2
0
 public function actionChart($type = 'btc_rur')
 {
     $buy = new Buy();
     $exch = Exchange::getAllByDt('btc_rur', '2013-12-16', '2014-01-06');
     $data_buy = array();
     $data_sell = array();
     foreach ($exch as $item) {
         $tm = strtotime($item['dt']) * 1000 + 4 * 60 * 60 * 1000;
         $data_buy[] = array($tm, (double) $item['buy']);
         $data_sell[] = array($tm, (double) $item['sell']);
     }
     // Покупки
     $orders = Order::model()->findAll();
     $lastEx = Exchange::getLast();
     $status['total_income'] = Sell::getTotalIncome();
     $status['balance'] = Status::getParam('balance');
     $status['balance_btc'] = Status::getParam('balance_btc');
     $status['total_balance'] = $status['balance'] + $status['balance_btc'] * $lastEx->sell;
     $this->render('chart', array('data_buy' => json_encode($data_buy), 'data_sell' => json_encode($data_sell), 'orders' => $orders, 'status' => $status));
 }