Esempio n. 1
0
 /**
  * @param ArrayCollection $initialLots
  * @param LotModel $model
  * @return int|null
  */
 protected function compareRtQuantity(ArrayCollection $initialLots, LotModel $model)
 {
     foreach ($initialLots as $initialLot) {
         if ($initialLot->getQuantity() > $model->getQuantity()) {
             // Close lot
             $model->setStatus(WealthbotLot::LOT_CLOSED);
             $model->setWasClosed(true);
             $model->setInitialLotId($initialLot->getId());
             $model->setRealizedGain($model->getAmount() - $model->getQuantity() * $initialLot->calcPrice());
             //$this->lotRepo->insert($model);
             $this->lotRepo->save($model);
             // Create new lot
             $newModel = new LotModel();
             $newModel->setDate($model->getDate());
             $newModel->setStatus(WealthbotLot::LOT_INITIAL);
             $newModel->setQuantity($initialLot->getQuantity() - $model->getQuantity());
             $newModel->setAmount($newModel->getQuantity() * $initialLot->calcPrice());
             $newModel->setWasClosed(false);
             $newModel->setCostBasis($model->getCostBasis());
             $newModel->setSecurityId($model->getSecurityId());
             $newModel->setRealizedGain(null);
             $newModel->setInitialLotId($initialLot->getId());
             $newModel->setClientSystemAccountId($model->getClientSystemAccountId());
             $newModel->setWasRebalancerDiff(false);
             // Divide initial lot
             $this->dividedLot($initialLot->getId());
             // Save lot
             return $this->lotRepo->save($newModel);
         }
     }
     return null;
 }
Esempio n. 2
0
 /**
  * @param LotModel $model
  * @param int $status
  * @return bool
  */
 protected function compareRebalancerQueue(LotModel $model, $status)
 {
     $amount = $model->getAmount();
     if (!empty($amount)) {
         $parameters['status'] = $status;
         $parameters['quantity'] = $model->getQuantity();
         $parameters['security_id'] = $model->getSecurityId();
         $status == RebalancerQueueModel::STATUS_SELL && ($parameters['lot_id'] = $model->getInitialLotId());
         if ($rebalancerQueue = $this->rebalancerQueueRepo->findOneBy($parameters)) {
             $percent = abs(($model->getAmount() - $rebalancerQueue->getAmount()) / $model->getAmount() * 100);
             return $percent > 10;
         }
     }
     return false;
 }
Esempio n. 3
0
 /**
  * @param Lot $model
  * @return bool|int|null
  */
 public function save(Lot $model)
 {
     $result = $this->getAllQuery(array('account_id' => $model->getClientSystemAccountId(), 'security_id' => $model->getSecurityId(), 'quantity' => $model->getQuantity(), 'date' => $model->getDate()))->limit(1)->fetch('id');
     return $result ? $this->update($result, $model) : $this->insert($model);
 }