Пример #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/>';
 }
Пример #2
0
 public function __construct()
 {
     //Инициализируем переменные
     $this->fee = 0.2 / 100;
     // Комиссия за операцию
     $this->imp_div = 1 / 100;
     // Процент при котором считать подъем/падение = 1%
     //$this->buy_sum = 350; // Покупать на 300 руб.
     $this->buy_value = 0.01;
     // Сколько покупать
     $this->buystep_n = 5;
     // Смотрим по ... блоков
     $this->sellstep_n = 4;
     // Смотрим по ... блоков
     $this->analize_period = 60 * 60 * 1;
     // Период за который анализируем график (6 часов)
     $this->min_income = 10;
     // Мин. доход
     $this->balance = Status::getParam('balance');
     $this->balance_btc = Status::getParam('balance_btc');
     $this->order_cnt = 0;
     $this->bought = Buy::model()->with('sell')->findAll();
     $this->total_income = Sell::getTotalIncome();
 }
Пример #3
0
 public static function getNotSold()
 {
     $sql = "\r\n\t\t\t\t\tSELECT\r\n\t\t\t\t\t\t\tb.*\r\n\t\t\t\t\tFROM `buy` b\n\t\t\t\t\tleft join `order` o on o.buy_id = b.id\r\n\t\t\t\t\twhere\n\t\t\t\t\t\tb.sold = 0\n\t\t\t\t\t\tand\r\n\t\t\t\t\t\to.id is null\t\n\t\t\t\t\t\tand\n\t\t\t\t\t\tb.count >= " . Bot::min_order_val . "\t\t\t\t\t\r\n\t\t\t\t\t";
     //if ($curtime == '2013-12-11 16:42:00')
     $list = Buy::model()->findAllBySql($sql);
     return $list;
 }
Пример #4
0
 public function actionSell()
 {
     if ($_SERVER['HTTP_HOST'] !== 'btcbot.loc') {
         return;
     }
     $btc_rur = Exchange::updatePrices('btc_rur');
     $bot = new Bot($btc_rur);
     $info = $bot->api->getInfo();
     if ($info) {
         $bot->setBalance($info['funds']['rur']);
         $bot->setBalanceBtc($info['funds']['btc']);
         Status::setParam('balance', $info['funds']['rur']);
         Status::setParam('balance_btc', $info['funds']['btc']);
         Balance::actualize('rur', $bot->balance);
         Balance::actualize('btc', $bot->balance_btc);
     }
     $buy = Buy::model()->findByPk(1);
     $bot->startSell($buy, array('test' => 'test'));
 }