示例#1
0
文件: Log.php 项目: HotAttack/btcbot
 public static function notsell($reason)
 {
     $bot = Bot::get_Instance();
     // Не пишем файл при дебаге
     if (YII_DEBUG) {
         return;
     }
     $dtm = date('Y-m-d H:i:s', $bot->curtime);
     $fn = 'logs/not-sell-' . date('Y-m-d', $bot->curtime) . '.html';
     $text = '<i>' . $dtm . '</i> ' . $reason . '<br/>';
     file_put_contents($fn, $text, FILE_APPEND);
 }
示例#2
0
 public static function add($currency, $desc, $summ)
 {
     $last = Balance::model()->find(array('condition' => 'currency = "' . $currency . '"', 'order' => 'id desc'));
     $last_balance = 0;
     if ($last) {
         $last_balance = $last->balance;
     }
     $bot = Bot::get_Instance();
     $b = new Balance();
     $b->dtm = $bot->current_exchange->dtm;
     $b->description = $desc;
     $b->summ = $summ;
     $b->balance = $last_balance + $summ;
     $b->currency = $currency;
     $b->save() || die(print_r($b->errors, true));
     return $last;
 }
示例#3
0
 private function makeOrderVirtual($cnt, $pair, $type, $price)
 {
     $bot = Bot::get_Instance();
     $summ = $cnt * $price;
     // Создаем виртуальную заявку на покупку, будет исполнена при следующем запросе
     // Расчитываем баланс
     if ($type == 'buy') {
         $balance_btc = $this->balance_btc;
         $balance = $this->balance - $summ;
     } else {
         $balance_btc = $this->balance_btc - $cnt;
         $balance = $this->balance;
     }
     // Имитация возвращаемых данных
     $result = array('success' => 1, 'return' => array('received' => 0, 'remains' => $cnt, 'order_id' => 87715140 + rand(0, 999) * 10000 + date('m') * 1000 + date('h') * 100 + date('m') * 10 + date('s'), 'funds' => array('btc' => (double) $balance_btc, 'rur' => (double) $balance)));
     // Добавляем заказ в список активных заказов
     $lastEx = Exchange::getLast();
     $this->activeOrders[$result['return']['order_id']] = array('pair' => 'btc_rur', 'type' => $type, 'amount' => $cnt, 'rate' => $price, 'timestamp_created' => $lastEx->dtm, 'status' => 0);
     $this->balance = $balance;
     $this->balance_btc = $balance_btc;
     return $result['return'];
 }
示例#4
0
 public function cancel()
 {
     $bot = Bot::get_Instance();
     $res = $bot->api->CancelOrder($this);
     if ($res['success'] == 1) {
         $bot->setBalance($res['return']['funds']['rur']);
         $bot->setBalanceBtc($res['return']['funds']['btc']);
         $this->status = 'cancel';
         $this->close_dtm = $bot->current_exchange->dtm;
         $this->save();
         Dump::d($this->errors);
     }
 }