コード例 #1
0
ファイル: YahooFinanceProvider.php プロジェクト: tautiz/cuex
 /**
  * {@inheritdoc}
  */
 public function fetchRate(CurrencyPair $currencyPair)
 {
     $queryPairs = sprintf('"%s%s"', $currencyPair->getBaseCurrency(), $currencyPair->getQuoteCurrency());
     $query = sprintf('select * from yahoo.finance.xchange where pair in (%s)', $queryPairs);
     $url = sprintf(self::URL, urlencode($query));
     $content = $this->fetchContent($url);
     $json = StringUtil::jsonToArray($content);
     $data = $json['query']['results']['rate'];
     if ('0.00' === $data['Rate'] || 'N/A' === $data['Date']) {
         throw new UnsupportedCurrencyPairException($currencyPair);
     }
     $dateString = $data['Date'] . ' ' . $data['Time'];
     $date = \DateTime::createFromFormat('m/d/Y H:ia', $dateString);
     return new Rate($data['Rate'], $date, "Yahoo Finance");
 }
コード例 #2
0
ファイル: CurrencylayerProvider.php プロジェクト: tautiz/cuex
 /**
  * {@inheritdoc}
  */
 public function fetchRate(CurrencyPair $currencyPair)
 {
     if ('USD' !== $currencyPair->getBaseCurrency()) {
         throw new UnsupportedCurrencyPairException($currencyPair);
     }
     $url = sprintf(self::URL, $this->accKey);
     $content = $this->fetchContent($url);
     $data = StringUtil::jsonToArray($content);
     if (isset($data['error'])) {
         throw new Exception($data['info']);
     }
     $date = new \DateTime();
     $date->setTimestamp($data['timestamp']);
     if ($data['source'] === $currencyPair->getBaseCurrency() && isset($data['quotes']['USD' . $currencyPair->getQuoteCurrency()])) {
         return new Rate((string) $data['quotes']['USD' . $currencyPair->getQuoteCurrency()], $date, 'Currencylayer');
     }
     throw new UnsupportedCurrencyPairException($currencyPair);
 }
コード例 #3
0
ファイル: GoogleFinanceProvider.php プロジェクト: tautiz/cuex
 /**
  * {@inheritdoc}
  */
 public function fetchRate(CurrencyPair $currencyPair)
 {
     $url = sprintf(self::URL, $currencyPair->getBaseCurrency(), $currencyPair->getQuoteCurrency());
     $content = $this->fetchContent($url);
     $document = new \DOMDocument();
     @$document->loadHTML($content);
     $xpath = new \DOMXPath($document);
     $nodes = $xpath->query('//span[@class="bld"]');
     if (0 === $nodes->length) {
         throw new Exception('The currency is not supported or Google changed the response format');
     }
     $nodeContent = $nodes->item(0)->textContent;
     $bid = strstr($nodeContent, ' ', true);
     if (!is_numeric($bid)) {
         throw new Exception('The currency is not supported or Google changed the response format');
     }
     return new Rate($bid, new \DateTime(), "Google Finance");
 }
コード例 #4
0
ファイル: CuEx.php プロジェクト: tautiz/cuex
 public function getRates($currencyPair)
 {
     if (is_string($currencyPair)) {
         $currencyPair = CurrencyPair::createFromString($currencyPair);
     } elseif (!$currencyPair instanceof CurrencyPair) {
         throw new \InvalidArgumentException('The currency pair must be either a string or an instance of CurrencyPair');
     }
     /**
      * @TODO: Imti is Cache duomenis
      */
     if (null !== $this->cache && null !== ($rate = $this->cache->fetchRate($currencyPair))) {
         return $rate;
     }
     if (isset($this->chainProviders)) {
         $rate = $this->chainProviders->fetchRates($currencyPair);
     } else {
         $rate = $this->provider->fetchRates($currencyPair);
     }
     if (null !== $this->cache) {
         $this->cache->storeRate($currencyPair, $rate);
     }
     return $rate;
 }
コード例 #5
0
 public function __construct(CurrencyPair $currencyPair)
 {
     parent::__construct(sprintf('The currency pair "%s" is not supported.', $currencyPair->toString()));
     $this->currencyPair = $currencyPair;
 }
コード例 #6
0
ファイル: DoctrineCache.php プロジェクト: tautiz/cuex
 /**
  * {@inheritdoc}
  */
 public function storeRate(CurrencyPair $currencyPair, Rate $rate)
 {
     $this->cache->save($currencyPair->toString(), $rate, $this->ttl);
 }