/**
  * {inheritDoc}
  */
 public function add(MarketDepthPriceInterface $marketDepthPrice)
 {
     if (!$this->currencyPair->equals($marketDepthPrice)) {
         throw new InvalidArgumentException('Cannot add market depth price to market depth price collection: currency pair must be equal');
     }
     $type = strtolower($marketDepthPrice->getType()) . 's';
     $depthArray =& $this->{$type};
     $multiplier = (string) $marketDepthPrice->getMultiplier();
     if (false === array_key_exists($multiplier, $this->{$type})) {
         $depthArray[$multiplier] = $marketDepthPrice;
         return;
     }
     /**
      * @var $existingMarketDepthPrice \Matmar10\Money\CurrencyExchange\Entity\MarketDepthPriceInterface
      */
     $existingMarketDepthPrice = $depthArray[$multiplier];
     $existingDepth = $existingMarketDepthPrice->getDepth();
     if (!$existingDepth->getCurrency()->equals($marketDepthPrice->getDepth()->getCurrency())) {
         $unconvertedDepth = $marketDepthPrice->getDepth();
         $depth = $existingMarketDepthPrice->convert($unconvertedDepth);
     } else {
         $depth = $marketDepthPrice->getDepth();
     }
     $existingMarketDepthPrice->setDepth($existingDepth->add($depth));
     $depthArray[$multiplier] = $existingMarketDepthPrice;
 }
Exemple #2
0
 /**
  * Checks whether the provided currency pair is the opposite of this pair
  *
  * @param \Matmar10\Money\Entity\CurrencyPairInterface $currencyPair The currency pair to check against
  * @return boolean
  */
 public function isInverse(CurrencyPairInterface $currencyPair)
 {
     return self::currencyCodesMatch($this->fromCurrency, $currencyPair->getToCurrency()) && self::currencyCodesMatch($this->toCurrency, $currencyPair->getFromCurrency());
 }