コード例 #1
0
ファイル: Lot.php プロジェクト: junjinZ/wealthbot
 /**
  * @param array $lots
  * @return int|null
  */
 public function createPosition($lots)
 {
     if (!count($lots)) {
         return null;
     }
     $amount = $quantity = 0;
     $status = $lots[0]->getStatus();
     foreach ($lots as $lot) {
         if ($lot->getStatus() !== $status) {
             $status = WealthbotLot::LOT_IS_OPEN;
         }
         if ($lot->isMF()) {
             $amount = $lot->getAmount();
             $quantity = $lot->getQuantity();
         } else {
             if ($lot->isOpen()) {
                 $amount += $lot->getAmount();
                 $quantity += $lot->getQuantity();
             }
             if ($lot->isInitial()) {
                 $amount += $lot->getAmount();
                 $quantity += $lot->getQuantity();
             }
         }
     }
     $position = new PositionModel();
     $position->setAmount($amount);
     $position->setQuantity($quantity);
     if ($status == WealthbotLot::LOT_IS_OPEN) {
         $position->setStatus(WealthbotPosition::POSITION_STATUS_IS_OPEN);
     }
     if ($status == WealthbotLot::LOT_INITIAL) {
         $position->setStatus(WealthbotPosition::POSITION_STATUS_INITIAL);
     }
     if ($status == WealthbotLot::LOT_CLOSED) {
         $position->setStatus(WealthbotPosition::POSITION_STATUS_IS_CLOSE);
     }
     $position->setDate($lots[0]->getDate());
     $position->setClientSystemAccountId($lots[0]->getClientSystemAccountId());
     $position->setSecurityId($lots[0]->getSecurityId());
     return $position;
 }
コード例 #2
0
 /**
  * @param Position $model
  * @return bool|int|null
  */
 public function save(Position $model)
 {
     $result = $this->getAllQuery(array('account_id' => $model->getClientSystemAccountId(), 'security_id' => $model->getSecurityId(), 'date' => $model->getDate()))->limit(1)->fetch('id');
     return $result ? $this->update($result, $model) : $this->insert($model);
 }