public function __construct($exchange = false) { if (!$exchange) { $exchange = Exchange::getLast(); } $this->current_exchange = $exchange; $this->curtime = strtotime($exchange->dtm); $this->balance = Status::getParam('balance'); $this->balance_btc = Status::getParam('balance_btc'); $this->total_income = 0; $this->buy_imp_dif = 0.005; // Шаг при анализе покупки 5% //150; $this->sell_imp_dif = 0.007; // Шаг при анализе продажи 7% $this->order_cnt = 0; // Периоды анализа графика для покупки и продажи (в сек.) $this->buy_periods = array(15 * 60, 30 * 60, 60 * 60, 2 * 60 * 60, 6 * 60 * 60, 24 * 60 * 60, 36 * 60 * 60); $this->sell_periods = array(60 * 60, 2 * 60 * 60, 6 * 60 * 60, 24 * 60 * 60, 36 * 60 * 60); $this->api = APIProvider::get_Instance(); self::$self = $this; }
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)); }
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']; }