示例#1
0
 /**
  * @author Tuzki
  * @param integer
  * @desc 将改组账号的配置设置到对象的属性中,new 出账号组的账号对象
  */
 private function init()
 {
     Logger::Log("Initialize account group from db.");
     $this->accounts = array();
     $this->config = null;
     $this->name = null;
     $this->holding_btc_weight_total = 0;
     $account_dao = new AccountDao();
     $account_group_dao = new AccountGroupDao();
     $account_group = $account_group_dao->get($this->id);
     if ($account_group) {
         $this->name = $account_group['name'];
     } else {
         throw new Exception('Account Group is not found.');
     }
     $this->id = $account_group['id'];
     $this->config = new ConfigModel($this->id);
     $accounts = $account_dao->getAccountListByAccountGroupId($this->id);
     foreach ($accounts as $account) {
         $account = new AccountModel($account['id']);
         //持币权重之和(后面用于计算交易类型)
         $this->holding_btc_weight_total += $account->market->holding_btc_weight;
         $this->accounts[] = $account;
     }
 }
示例#2
0
 function __construct($account_id = null)
 {
     if (!empty($account_id)) {
         $account_model = new AccountDao();
         $account = $account_model->get($account_id);
         if ($account) {
             $this->account_id = $account_id;
             // 市场类名
             $market_name = $account->market['name'];
             $market_name = 'Market\\' . $market_name;
             // 市场配置
             $account_config = array();
             $account_config_model = new AccountConfigDao();
             foreach ($account_config_model->getConfigListByAccountId($account['id']) as $config) {
                 $account_config[$config['name']] = format_val($config['value']);
             }
             try {
                 $this->market = new $market_name($account_config);
             } catch (Exception $e) {
                 throw new Exception("API {$market_name} not found.");
             }
         } else {
             throw new Exception('Account not found.');
         }
     }
 }
示例#3
0
 public function indexAction()
 {
     $account1 = new AccountDao(1);
     //$account2 = new AccountModel(3);
     //var_dump($account1->market->getAllConfig());
     var_dump($account1->matchPrice());
     //print_vars($account2->market->getInfo());
     $this->getView()->assign("content", "sss");
 }
示例#4
0
 public function getAction()
 {
     $account_group_dao = new AccountGroupDao('account_group');
     $params = $this->getRequest()->getParams();
     $handle = array_search('edit', $params);
     if (!empty($handle) && $params[$handle] === 'edit') {
         $account_group = $account_group_dao->get($handle);
         if (empty($account_group)) {
             $this->redirect('/account-group');
             exit;
         }
         $config_dao = new ConfigDao();
         $config_list = $config_dao->getConfigListByAccountGroupId($account_group['id']);
         $this->getView()->assign('config_list', $config_list);
         $this->getView()->assign('account_group', $account_group);
         $this->getView()->display('account-group-edit.phtml');
         exit;
     }
     if (array_key_exists('new', $params)) {
         $config_list = get_config_keys();
         $this->getView()->assign('config_list', $config_list);
         $this->getView()->display('account-group-new.phtml');
         exit;
     }
     $redis = Yaf\Registry::get('redis');
     if (!empty($params) && count($params) === 1) {
         $id = array_keys($params)[0];
         $config_dao = new ConfigDao();
         $config_list = $config_dao->getConfigListByAccountGroupId($id);
         $account_group_config = array();
         foreach ($config_list as $row) {
             $account_group_config[$row['name']] = $row['value'];
         }
         $account_dao = new AccountDao();
         $account_list = $account_dao->getAccountListByAccountGroupId($id);
         $market_dao = new MarketDao();
         $account_info_list = array();
         foreach ($account_list as $account) {
             $key = 'AccountInfo_' . $account['id'];
             $market = $market_dao->get($account['market_id']);
             $account_info_list[] = array_merge(json_decode($redis->get($key), true), array('market_name' => $market['name']));
         }
         $btc_price = json_decode($redis->get('Market\\HuoLPrice'), true)['buy'][0][0];
         $this->getView()->assign('btc_price', $btc_price);
         $this->getView()->assign('account_group_config', $account_group_config);
         $this->getView()->assign('account_info_list', $account_info_list);
         $this->getView()->display('account-group-view.phtml');
         exit;
     }
     $this->getView()->assign('account_group_list', $account_group_dao->getList());
     $this->getView()->display('account-group.phtml');
 }
示例#5
0
 public function getAction()
 {
     $orders_dao = new OrderDao();
     $order_list = $orders_dao->getList(100)->order('id desc');
     $account_dao = new AccountDao();
     $account_list = $account_dao->getList();
     $temp = $account_list;
     foreach ($temp as $row) {
         $account_list[$row['id']] = $row['name'];
     }
     $this->getView()->assign('order_list', $order_list);
     $this->getView()->assign('account_list', $account_list);
     $this->getView()->display('index.phtml');
 }
示例#6
0
 /**
  * Insert pattern
  * @param PatternDto $pattern
  * @return number
  */
 public function insert($pattern)
 {
     $patternId = -1;
     try {
         $this->dp->getDB()->beginTransaction();
         // Change tag of pattern (all column name)
         $tag = '';
         foreach ($pattern->header as $key => $column) {
             $tag .= $column->header . ' ';
         }
         // Get account id
         $accDao = new AccountDao($this->dp);
         $acc = $accDao->getByFbId($pattern->info->accountid);
         $pattern->info->accountid = $acc->id;
         // Insert pattern;
         $pattern->info->tag = $tag;
         $patternId = $this->patternDao->insert($pattern->info);
         $columnIdArr = array();
         foreach ($pattern->header as $key => $column) {
             $column->patternid = $patternId;
             $columnId = $this->patternHeaderDao->insert($column);
             $columnIdArr[] = $columnId;
         }
         for ($i = 0; $i < count($pattern->data); $i++) {
             $detail = $pattern->data[$i];
             $detail->patternid = $patternId;
             $detail->columnid = $columnIdArr[$i % $pattern->info->columnsize];
             $this->patternDetailDao->insert($detail);
         }
         $this->dp->getDB()->commit();
     } catch (Exception $ex) {
         // Something went wrong rollback!
         $this->dp->getDB()->rollBack();
         Plog::log($ex->getMessage());
     }
     return $patternId;
 }
示例#7
0
 public function deleteAction()
 {
     $id = $this->getRequest()->getParam('id');
     $account_dao = new AccountDao();
     $account_dao->delete($id);
     var_dump($account_dao->delete($id));
     $this->redirect('/accounts');
 }