コード例 #1
0
ファイル: Account.php プロジェクト: Aimsam/BTCAutoTrade
 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.');
         }
     }
 }
コード例 #2
0
ファイル: Index.php プロジェクト: Aimsam/BTCAutoTrade
 /**
  * @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();
     }
 }
コード例 #3
0
ファイル: Accounts.php プロジェクト: Aimsam/BTCAutoTrade
 public function getAction()
 {
     $account_dao = new AccountDao();
     $account_group_dao = new AccountGroupDao('account-group');
     $params = $this->getRequest()->getParams();
     $param_id = array_search('edit', $params);
     if (!empty($param_id) && $params[$param_id] === 'edit') {
         $account_dao = new AccountDao();
         $market_dao = new MarketDao();
         $account_config_dao = new AccountConfigDao('account_config');
         $account_group_list = $account_group_dao->getList();
         $account = $account_dao->get($param_id);
         $market = $market_dao->get($account['market_id']);
         //account config
         $account_config_list = $account_config_dao->getConfigListByAccountId($param_id);
         $this->getView()->assign('account', $account);
         $this->getView()->assign('account_group_list', $account_group_list);
         $this->getView()->assign('account_config_list', $account_config_list);
         $this->getView()->assign('market', $market);
         $this->getView()->display('accounts-edit.phtml');
         exit;
     }
     if (array_key_exists('new', $params)) {
         $account_group_dao = new AccountGroupDao('account-group');
         $market_dao = new MarketDao();
         $account_group_list = $account_group_dao->getList();
         $market_list = $market_dao->getList();
         //account config
         $account_config_list = array();
         foreach ($market_list as $market) {
             $account_config_list[$market['name']] = get_account_config_keys($market['name']);
         }
         $this->getView()->assign('account_group_list', $account_group_list);
         $this->getView()->assign('account_config_list', $account_config_list);
         $this->getView()->assign('market_list', $market_list);
         $this->getView()->display('accounts-new.phtml');
         exit;
     }
     $this->getView()->assign('account_list', $account_dao->getAccountList());
     $this->getView()->display('accounts.phtml');
 }