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.'); } } }
/** * @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(); } }
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'); }