コード例 #1
0
ファイル: AbstractLot.php プロジェクト: junjinZ/wealthbot
 /**
  * @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;
 }
コード例 #2
0
ファイル: Sell.php プロジェクト: junjinZ/wealthbot
 /**
  * @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;
 }
コード例 #3
0
 /**
  * Update lot
  *
  * @param int $id
  * @param Lot $model
  * @return bool
  */
 public function update($id, Lot $model)
 {
     $this->fpdo->update($this->table, array('quantity' => $model->getQuantity(), 'amount' => $model->getAmount(), 'cost_basis' => $model->getCostBasis(), 'was_closed' => $model->getWasClosed(), 'realized_gain_loss' => $model->getRealizedGain(), 'position_id' => $model->getPositionId()), $id)->execute();
     return $id;
 }