/** * @dataProvider provideTestData */ public function test(CurrencyPairInterface $pair, CurrencyInterface $depthCurrency, array $bids, array $asks, $desiredRate, $desiredType, $desiredCurrency, $desiredAmountFloat, array $expectedSupported, $exception) { if ($exception) { $this->setExpectedException($exception); } $collection = new MarketDepthCollection(); $collection->setCurrencyPair($pair); foreach ($bids as $bidPrice => $bidAmount) { $amount = new Money($depthCurrency); $amount->setAmountFloat($bidAmount); $bid = new MarketDepthPrice($pair->getFromCurrency(), $pair->getToCurrency(), (double) $bidPrice, CurrencyExchangeOperationInterface::TYPE_BID, $amount); $collection->add($bid); } foreach ($asks as $askPrice => $askAmount) { $amount = new Money($depthCurrency); $amount->setAmountFloat($askAmount); $ask = new MarketDepthPrice($pair->getFromCurrency(), $pair->getToCurrency(), (double) $askPrice, CurrencyExchangeOperationInterface::TYPE_ASK, $amount); $collection->add($ask); } $desiredAmount = new Money($desiredCurrency); $desiredAmount->setAmountFloat($desiredAmountFloat); $desired = new MarketDepthPrice($pair->getFromCurrency(), $pair->getToCurrency(), $desiredRate, $desiredType, $desiredAmount); $expectedType = CurrencyExchangeOperationInterface::TYPE_ASK === $desiredType ? CurrencyExchangeOperationInterface::TYPE_BID : CurrencyExchangeOperationInterface::TYPE_ASK; $expectedSupportedDepthPrices = array(); foreach ($expectedSupported as $price => $amount) { $amountAsMoney = new Money($depthCurrency); $amountAsMoney->setAmountFloat($amount); $expectedSupportedDepthPrices[$price] = new MarketDepthPrice($pair->getFromCurrency(), $pair->getToCurrency(), (double) $price, $expectedType, $amountAsMoney); } $supported = $collection->getSupported($desired); $this->assertEquals($expectedSupportedDepthPrices, $supported); }
public static function convertMarketDepth($input, $fromCurrencyCode, $fromCurrencyPrecision, $fromCurrencyDisplayPrecision, $fromCurrencySymbol, $toCurrencyCode, $toCurrencyPrecision, $toCurrencyDisplayPrecision, $toCurrencySymbol, $type, $depthCurrency, $depthCurrencyPrecision, $depthCurrencyDisplayPrecision, $depthCurrencySymbol) { $fromCurrency = new Currency($fromCurrencyCode, $fromCurrencyPrecision, $fromCurrencyDisplayPrecision, $fromCurrencySymbol); $toCurrency = new Currency($toCurrencyCode, $toCurrencyPrecision, $toCurrencyDisplayPrecision, $toCurrencySymbol); $currencyPair = new CurrencyPair($fromCurrency, $toCurrency); $amountCurrency = new Currency($depthCurrency, $depthCurrencyPrecision, $depthCurrencyDisplayPrecision, $depthCurrencySymbol); $marketDepthCollection = new MarketDepthCollection($currencyPair); foreach ($input as $depthData) { list($rate, $ordersValue) = $depthData; $ordersAmount = new Money($amountCurrency); $ordersAmount->setAmountFloat($ordersValue); $marketDepthPrice = new MarketDepthPrice($fromCurrency, $toCurrency, $rate, $type, $ordersAmount); $marketDepthCollection->add($marketDepthPrice); } return $marketDepthCollection; }