Beispiel #1
0
 /**
  * @return all account balances
  * @throws AccountFetchException if something bad happened
  */
 public function fetchBalances($account, CurrencyFactory $factory, Logger $logger)
 {
     $url = "https://cex.io/api/balance/";
     $logger->info($url);
     try {
         $this->throttle($logger);
         $post_data = $this->generatePostData($account);
         $logger->info($post_data);
         $raw = Fetch::post($url, $post_data);
     } catch (FetchHttpException $e) {
         throw new AccountFetchException($e->getContent(), $e);
     }
     $json = Fetch::jsonDecode($raw);
     if (isset($json['error'])) {
         throw new AccountFetchException($json['error']);
     }
     $result = array();
     foreach ($this->fetchSupportedCurrencies($factory, $logger) as $cur) {
         $code = $this->getCEXioCode($cur);
         if (isset($json[$code])) {
             $result[$cur] = array('available' => $json[$code]['available']);
             if (isset($json[$code]['orders'])) {
                 $result[$cur]['reserved'] = $json[$code]['orders'];
                 $result[$cur]['confirmed'] = $result[$cur]['available'] + $result[$cur]['reserved'];
             } else {
                 $result[$cur]['confirmed'] = $result[$cur]['available'];
             }
         }
     }
     return $result;
 }
Beispiel #2
0
 function fetchAllRates(Logger $logger)
 {
     $params = $this->generatePostData("getmarkets");
     $url = "https://www.cryptsy.com/api";
     $logger->info($url);
     $raw = Fetch::post($url, $params['post'], array(), $params['headers']);
     $json = Fetch::jsonDecode($raw);
     if (!$json['success']) {
         throw new ExchangeRateException($json['error']);
     }
     $result = array();
     foreach ($json['return'] as $market) {
         $key = $market['label'];
         if ($market['last_trade'] == 0) {
             $logger->info("Ignoring '{$key}' market: last trade price is 0");
             continue;
         }
         $currency1 = $this->getCurrencyCode($market['secondary_currency_code']);
         $currency2 = $this->getCurrencyCode($market['primary_currency_code']);
         $rate = array("currency1" => $currency1, "currency2" => $currency2, "last_trade" => $market['last_trade'], "volume" => $market['current_volume'], 'low' => $market['low_trade'], 'high' => $market['high_trade']);
         if ($this->shouldSwitch($currency1, $currency2)) {
             $rate = array('currency1' => $rate['currency2'], 'currency2' => $rate['currency1'], 'last_trade' => 1 / $rate['last_trade'], 'volume' => $rate['volume'] / $rate['last_trade'], 'low' => $rate['high'] == 0 ? 0 : 1 / $rate['high'], 'high' => $rate['low'] == 0 ? 0 : 1 / $rate['low']);
         }
         $result[] = $rate;
     }
     return $result;
 }
Beispiel #3
0
 /**
  * @return all account balances
  * @throws AccountFetchException if something bad happened
  */
 public function fetchBalances($account, CurrencyFactory $factory, Logger $logger)
 {
     if (!$account['accept']) {
         throw new AccountFetchException("Cannot fetch balances without accepting unsafety of API");
     }
     $url = "https://poloniex.com/tradingApi";
     $logger->info($url);
     try {
         $this->throttle($logger);
         $post_data = $this->generatePostData($account);
         $raw = Fetch::post($url, $post_data['post_data'], array(), $post_data['headers']);
     } catch (FetchHttpException $e) {
         throw new AccountFetchException($e->getMessage(), $e);
     }
     $json = Fetch::jsonDecode($raw);
     if (isset($json['error']) && $json['error']) {
         throw new AccountFetchException($json['error']);
     }
     $result = array();
     foreach ($json as $cur => $balance) {
         $currency = $this->getCurrencyCode($cur);
         if (strlen($currency) === 3) {
             $result[$currency] = array('confirmed' => $balance['available'] + $balance['onOrders'], 'available' => $balance['available'], 'reserved' => $balance['onOrders']);
         }
     }
     return $result;
 }
Beispiel #4
0
 /**
  * @return all account balances
  * @throws AccountFetchException if something bad happened
  */
 public function fetchBalances($account, CurrencyFactory $factory, Logger $logger)
 {
     $url = "https://www.bitmarket.pl/api2/";
     $logger->info($url);
     try {
         $this->throttle($logger);
         $post_data = $this->generatePostData($account);
         $logger->info($post_data['post_data']);
         $raw = Fetch::post($url, $post_data['post_data'], array(), $post_data['headers']);
     } catch (FetchHttpException $e) {
         throw new AccountFetchException($e->getMessage(), $e);
     }
     $json = Fetch::jsonDecode($raw);
     if (isset($json['errorMsg'])) {
         throw new AccountFetchException($json['errorMsg']);
     }
     if (isset($json['error'])) {
         throw new AccountFetchException($json['error']);
     }
     $result = array();
     foreach ($this->fetchSupportedCurrencies($factory, $logger) as $cur) {
         $result[$cur] = array('available' => $json['data']['balances']['available'][$this->getBitMarketPlCode($cur)]);
         if (isset($json['data']['balances']['blocked'][$this->getBitMarketPlCode($cur)])) {
             $result[$cur]['blocked'] = $json['data']['balances']['blocked'][$this->getBitMarketPlCode($cur)];
             $result[$cur]['confirmed'] = $result[$cur]['available'] + $result[$cur]['blocked'];
         } else {
             $result[$cur]['confirmed'] = $result[$cur]['available'];
         }
     }
     return $result;
 }
 /**
  *
  * @throws {@link BalanceException} if something happened and the balance could not be obtained.
  */
 function getBalance($address, Logger $logger, $is_received = false)
 {
     $code = $this->currency->getCode();
     if ($is_received) {
         // we use HTML scraping for received balance
         $logger->info("We are looking for received balance.");
         $url = sprintf($this->url, urlencode($address));
         $logger->info($url);
         $html = Fetch::get($url);
         $html = $this->stripHTML($html);
         $matches = false;
         if (preg_match("#Total Nxt in:?</td><td>([0-9\\.]+)</td>#im", $html, $matches)) {
             $balance = $matches[1];
             $logger->info("Address balance: " . $balance);
             return $balance;
         } else {
             throw new BalanceException("Could not find received balance on page");
         }
     } else {
         // there is a POST JSON that we can use to get the final balance
         $url = $this->post_url;
         $logger->info($url);
         $post = array("ac" => $address);
         $logger->info("Posting " . print_r($post, true));
         $json = Fetch::jsonDecode(Fetch::post($url, $post));
         if (isset($json['balance'])) {
             $balance = $json['balance'];
             $logger->info("Address balance: " . $balance);
             return $balance;
         } else {
             throw new BalanceException("Could not find final balance on page");
         }
     }
 }
Beispiel #6
0
 /**
  * @return all account balances
  * @throws AccountFetchException if something bad happened
  */
 public function fetchBalances($account, CurrencyFactory $factory, Logger $logger)
 {
     $url = "https://btc-e.com/tapi/";
     $logger->info($url);
     try {
         $this->throttle($logger);
         $post_data = $this->generatePostData($account);
         $logger->info($post_data['post_data']);
         $raw = Fetch::post($url, $post_data['post_data'], array(), $post_data['headers']);
     } catch (FetchHttpException $e) {
         throw new AccountFetchException($e->getMessage(), $e);
     }
     $json = Fetch::jsonDecode($raw);
     if (isset($json['error'])) {
         throw new AccountFetchException($json['error']);
     }
     $result = array();
     foreach ($json['return']['funds'] as $cur => $balance) {
         $cur = $this->getCurrencyCode($cur);
         // special exceptions for currencies with wallets but can't be traded
         if ($cur == "trc" || $cur == "ftc" || $cur == "xpm") {
             continue;
         }
         $result[$cur] = array('confirmed' => $balance);
     }
     return $result;
 }
 function getAccountLines($address, Logger $logger)
 {
     $url = $this->url;
     $logger->info($url);
     $data = array("method" => "account_lines", "params" => array(array("account" => $address)));
     $json = Fetch::jsonDecode(Fetch::post($url, json_encode($data)));
     return $json['result']['lines'];
 }
 protected function havelockQuery($url, $post_data, Logger $logger)
 {
     $logger->info($url);
     try {
         $this->throttle($logger);
         $raw = Fetch::post($url, $post_data);
     } catch (FetchHttpException $e) {
         throw new AccountFetchException($e->getMessage(), $e);
     }
     if ($raw === "Access denied") {
         throw new AccountFetchException($raw);
     }
     $json = Fetch::jsonDecode($raw);
     if (isset($json['message']) && $json['message']) {
         throw new AccountFetchException($json['message']);
     }
     if (is_array($json) && !$json) {
         throw new AccountFetchException("Havelock API returned an empty array");
     }
     return $json;
 }
Beispiel #9
0
 /**
  * @return all account balances
  * @throws AccountFetchException if something bad happened
  */
 public function fetchBalances($account, CurrencyFactory $factory, Logger $logger)
 {
     $url = "https://www.bit2c.co.il/Account/Balance/v2";
     $logger->info($url);
     try {
         $this->throttle($logger);
         $post_data = $this->generatePostData($account);
         $logger->info($post_data['post_data']);
         $raw = Fetch::post($url, $post_data['post_data'], array(), $post_data['headers']);
     } catch (FetchHttpException $e) {
         throw new AccountFetchException($e->getMessage(), $e);
     }
     $json = Fetch::jsonDecode($raw);
     if (isset($json['error'])) {
         throw new AccountFetchException($json['error']);
     }
     $result = array();
     foreach ($this->fetchSupportedCurrencies($factory, $logger) as $cur) {
         $result[$cur] = array('confirmed' => $json[$this->getBit2cCode($cur)]);
     }
     return $result;
 }
Beispiel #10
0
 /**
  * @return all account balances
  * @throws AccountFetchException if something bad happened
  */
 public function fetchBalances($account, CurrencyFactory $factory, Logger $logger)
 {
     $url = $this->getBalanceURL();
     $logger->info($url);
     try {
         $this->throttle($logger);
         $post_data = $this->generatePostData($account);
         $logger->info($post_data['post_data']);
         $raw = Fetch::post($url, $post_data['post_data'], array(), $post_data['headers']);
     } catch (FetchHttpException $e) {
         throw new AccountFetchException($e->getMessage(), $e);
     }
     $json = Fetch::jsonDecode($raw);
     if (isset($json['error'])) {
         throw new AccountFetchException($json['error']);
     }
     $result = array();
     foreach ($this->fetchSupportedCurrencies($factory, $logger) as $cur) {
         $result[$cur] = array('confirmed' => $json['data']['Wallets'][$this->getANXCode($cur)]['Balance']['value'], 'available' => $json['data']['Wallets'][$this->getANXCode($cur)]['Available_Balance']['value'], 'daily_withdrawl' => $json['data']['Wallets'][$this->getANXCode($cur)]['Daily_Withdrawal_Limit']['value'], 'max_widthdrawl' => $json['data']['Wallets'][$this->getANXCode($cur)]['Max_Withdraw']['value']);
     }
     return $result;
 }
Beispiel #11
0
 /**
  * @return all account balances
  * @throws AccountFetchException if something bad happened
  */
 public function fetchBalances($account, CurrencyFactory $factory, Logger $logger)
 {
     $url = "https://api.kraken.com/0/private/Balance";
     $logger->info($url);
     try {
         $this->throttle($logger);
         $post_data = $this->generatePostData($account, "/0/private/Balance");
         $raw = Fetch::post($url, $post_data['post_data'], array(), $post_data['headers']);
     } catch (FetchHttpException $e) {
         throw new AccountFetchException($e->getMessage(), $e);
     }
     $json = Fetch::jsonDecode($raw);
     if (isset($json['error']) && $json['error']) {
         throw new AccountFetchException(implode(", ", $json['error']));
     }
     $result = array();
     foreach ($json['result'] as $cur => $balance) {
         $currency = $this->getCurrencyCode($cur);
         $result[$currency] = array('confirmed' => $balance);
     }
     return $result;
 }
Beispiel #12
0
 /**
  * @return all account balances
  * @throws AccountFetchException if something bad happened
  */
 public function fetchBalances($account, CurrencyFactory $factory, Logger $logger)
 {
     $url = "https://cex.io/api/ghash.io/hashrate";
     $logger->info($url);
     try {
         $this->throttle($logger);
         $post_data = $this->generatePostData($account);
         $logger->info($post_data);
         $raw = Fetch::post($url, $post_data);
     } catch (FetchHttpException $e) {
         throw new AccountFetchException($e->getContent(), $e);
     }
     $json = Fetch::jsonDecode($raw);
     if (isset($json['error'])) {
         throw new AccountFetchException($json['error']);
     }
     $result = array();
     foreach ($this->fetchSupportedCurrencies($factory, $logger) as $cur) {
         $result[$cur] = array('hashrate' => $json['last5m'] * 1000000.0);
     }
     return $result;
 }
Beispiel #13
0
 /**
  * @return all account balances
  * @throws AccountFetchException if something bad happened
  */
 public function fetchBalances($account, CurrencyFactory $factory, Logger $logger)
 {
     $url = "https://www.bitstamp.net/api/balance/";
     $logger->info($url);
     try {
         $this->throttle($logger);
         $post_data = $this->generatePostData($account);
         $logger->info($post_data);
         $raw = Fetch::post($url, $post_data);
     } catch (FetchHttpException $e) {
         throw new AccountFetchException($e->getContent(), $e);
     }
     $json = Fetch::jsonDecode($raw);
     if (isset($json['error'])) {
         throw new AccountFetchException($json['error']);
     }
     $result = array();
     foreach ($this->fetchSupportedCurrencies($factory, $logger) as $cur) {
         $result[$cur] = array('confirmed' => $json[$cur . "_balance"], 'reserved' => $json[$cur . "_reserved"], 'available' => $json[$cur . "_available"]);
     }
     return $result;
 }
Beispiel #14
0
 /**
  * @return all account balances
  * @throws AccountFetchException if something bad happened
  */
 public function fetchBalances($account, CurrencyFactory $factory, Logger $logger)
 {
     $url = "https://btclevels.com/api/info";
     $logger->info($url);
     try {
         $this->throttle($logger);
         $post_data = $this->generatePostData($account);
         $raw = Fetch::post($url, $post_data);
     } catch (FetchHttpException $e) {
         throw new AccountFetchException($e->getMessage(), $e);
     }
     try {
         $json = Fetch::jsonDecode($raw);
     } catch (FetchException $e) {
         $message = strlen($raw) < 64 ? $e->getMessage() : $raw;
         throw new AccountFetchException($message, $e);
     }
     if (isset($json['error'])) {
         throw new AccountFetchException($json['error']);
     }
     $result = array('btc' => array('unconfirmed' => $json['info']['balance'], 'confirmed' => $json['info']['actualbalance']));
     return $result;
 }
Beispiel #15
0
 /**
  * @return all account balances
  * @throws AccountFetchException if something bad happened
  */
 public function fetchBalances($account, CurrencyFactory $factory, Logger $logger)
 {
     $url = "https://www.cryptsy.com/api";
     $logger->info($url);
     try {
         $this->throttle($logger);
         $post_data = $this->generatePostData($account);
         $raw = Fetch::post($url, $post_data['post_data'], array(), $post_data['headers']);
     } catch (FetchHttpException $e) {
         throw new AccountFetchException($e->getMessage(), $e);
     }
     $json = Fetch::jsonDecode($raw);
     if (!$json['success']) {
         throw new AccountFetchException($json['error']);
     }
     $result = array();
     foreach ($json['return']['balances_available'] as $cur => $balance) {
         $currency = $this->getCurrencyCode($cur);
         if (strlen($currency) === 3) {
             $result[$currency] = array('confirmed' => $balance);
         }
     }
     return $result;
 }