Exemplo n.º 1
0
 /**
  * @param string  $type
  * @param float   $price
  * @param float   $strike
  * @param float   $futuresPrice
  * @param float   $futuresPrice52WeekHigh
  * @param float   $futuresPrice52WeekLow
  * @param Futures $futures
  * @return OptionPrice|null
  */
 private function createOptionPrice(string $type, float $price, float $strike, float $futuresPrice, float $futuresPrice52WeekHigh, float $futuresPrice52WeekLow, Futures $futures)
 {
     $optionContract = $this->getOptionContract($type, $futures, $strike);
     $optionPrice = $this->optionPriceRepository->findOneForLastHourByOptionId($optionContract->getId());
     if ($optionPrice) {
         return null;
     }
     return new OptionPrice($this->dateTime, $price, $optionContract, $futuresPrice, $futuresPrice52WeekHigh, $futuresPrice52WeekLow, $futures);
 }
Exemplo n.º 2
0
 /**
  * @param Trade[] $openedTrades
  */
 public function closeExpiredTrades(array $openedTrades) : int
 {
     $closedTradesCount = 0;
     foreach ($openedTrades as $trade) {
         $optionPrice = $trade->getOpenPrice();
         $optionContract = $optionPrice->getOptionContract();
         $futures = $optionContract->getFutures();
         if ($futures->isExpired()) {
             $trade->expire();
             $optionContract = $trade->getOpenPrice()->getOptionContract();
             $currentOptionPrice = $this->optionPriceRepository->findOptionCurrentPrice($optionContract->getId());
             $this->closeTrade($trade->getId(), $currentOptionPrice->getId());
             $closedTradesCount++;
         }
     }
     $this->tradeRepository->flush();
     return $closedTradesCount;
 }