Exemple #1
0
 private function exchange($account_group_id, $to_usd_rate, $to_cny_rate)
 {
     $account_group = new AccountGroupModel($account_group_id);
     $trades = $account_group->availableTrades();
     if (count($trades) > 0) {
         foreach ($trades as $trade) {
             Logger::Log("Judge Trade: " . $trade->__toString());
             if ($trade->tacticsTransport($to_usd_rate, $to_cny_rate)) {
                 $trade->run(TradeModel::MODE_LOOSE);
                 Logger::Log('finished 1 time, next trade.');
                 return $this->runAction();
             } else {
                 Logger::Log('no chance, next trade.');
             }
         }
         return $this->exchange($account_group_id, $to_usd_rate, $to_cny_rate);
     } else {
         throw new Exception('no possible trade, fix it!');
     }
 }
Exemple #2
0
 public function runAction($force_update = true)
 {
     $this->restart();
     ini_set('default_socket_timeout', -1);
     $account_group = new AccountGroupModel(1);
     $trades = $account_group->availableTrades($force_update);
     if (count($trades) > 0) {
         foreach ($trades as $trade) {
             Logger::Log("Judge Trade: " . $trade->__toString());
             if ($trade->tacticsHedge()) {
                 $trade->run(TradeModel::MODE_LOOSE);
                 Logger::Log('finished 1 time, next trade.');
                 return $this->runAction();
             } else {
                 Logger::Log('no chance, next trade.');
             }
         }
     } else {
         Logger::Log("No available trade, try again.");
     }
     // 释放 account group 对象
     unset($account_group);
     return $this->runAction(false);
 }