Example #1
0
 function fetchAllRates(Logger $logger)
 {
     $url = "https://api.vircurex.com/api/get_info_for_currency.json";
     $logger->info($url);
     $json = Fetch::jsonDecode(Fetch::get($url));
     $result = array();
     $ignored = 0;
     foreach ($json as $pair2 => $pairs) {
         if ($pair2 == "status") {
             continue;
         }
         foreach ($pairs as $pair1 => $market) {
             if ($market['last_trade'] == 0 || $market['lowest_ask'] == 0 || $market['highest_bid'] == 0) {
                 // ignore empty markets
                 $ignored++;
                 continue;
             }
             $currency1 = $this->getCurrencyCode($pair1);
             $currency2 = $this->getCurrencyCode($pair2);
             if (CurrencyOrder::hasOrder($currency1) && CurrencyOrder::hasOrder($currency2)) {
                 if (!CurrencyOrder::isOrdered($currency1, $currency2)) {
                     // do not duplicate ordered currencies
                     continue;
                 }
             }
             $rate = array("currency1" => $currency1, "currency2" => $currency2, "last_trade" => $market['last_trade'], "volume" => $market['volume'], 'bid' => $market['highest_bid'], 'ask' => $market['lowest_ask']);
             $result[] = $rate;
         }
     }
     $logger->info("Ignored " . $ignored . " markets with last trade price of 0");
     return $result;
 }
Example #2
0
 function shouldSwitch($cur1, $cur2)
 {
     return !\Exchange\CurrencyOrder::isOrdered($cur1, $cur2);
 }
 function testBTCLTC()
 {
     $this->assertTrue(CurrencyOrder::isOrdered("btc", "ltc"));
     $this->assertFalse(CurrencyOrder::isOrdered("ltc", "btc"));
 }
 /**
  * In openclerk/exchanges, we want to return all exchange pairs according to a
  * particular currency order.
  */
 function testRatesAreOrdered()
 {
     $rates = $this->getAllRates();
     foreach ($rates as $rate) {
         if (\Exchange\CurrencyOrder::hasOrder($rate['currency1'])) {
             if (\Exchange\CurrencyOrder::hasOrder($rate['currency2'])) {
                 $this->assertTrue(\Exchange\CurrencyOrder::isOrdered($rate['currency1'], $rate['currency2']), "Expected reverse order of pair " . $rate['currency1'] . "/" . $rate['currency2']);
             }
         }
     }
 }