Exemplo n.º 1
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.');
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @desc 获取价格Action
  * @param string market
  */
 public function getPriceAction()
 {
     Yaf\Registry::get('redis')->lPush('get_price_pids', getmypid());
     $market_name = $this->getRequest()->getParam('market');
     $market_name = "Market\\{$market_name}";
     $market = new $market_name();
     while (true) {
         if ($market_name == 'Market\\Btce') {
             $account_config = array();
             $account_config_model = new AccountConfigDao();
             foreach ($account_config_model->getConfigListByAccountId(9) as $config) {
                 $account_config[$config['name']] = format_val($config['value']);
             }
             $market = new $market_name($account_config);
         }
         if ($market_name == 'Market\\Bitfinex') {
             $account_config = array();
             $account_config_model = new AccountConfigDao();
             foreach ($account_config_model->getConfigListByAccountId(10) as $config) {
                 $account_config[$config['name']] = format_val($config['value']);
             }
             $market = new $market_name($account_config);
         }
         usleep(Yaf\Application::app()->getConfig()->console->price_sleep_delay);
         $market->getPrice();
     }
 }
Exemplo n.º 3
0
 public function putAction()
 {
     $account_dao = new AccountDao();
     $account = array();
     $account['id'] = $this->getRequest()->getParam('id');
     $account['name'] = $this->getRequest()->getParam('name');
     $account['description'] = $this->getRequest()->getParam('description');
     $market_name = $this->getRequest()->getParam('market_name');
     $account['account_group_id'] = $this->getRequest()->getParam('account_group_id');
     $config_list = array();
     $account_config_name_list = get_account_config_keys($market_name);
     foreach ($account_config_name_list as $account_config_name) {
         $config_list[] = array('account_id' => $account['id'], 'name' => $account_config_name, 'value' => $this->getRequest()->getParam("{$market_name}_{$account_config_name}"));
     }
     $account_config_dao = new AccountConfigDao();
     foreach ($config_list as $config) {
         $account_config_dao->insert_update($config);
     }
     $account_dao->update($account);
     $this->redirect('/accounts');
 }