I need a simple hack to change the Drupal uc_bitcoin
modules code so it gets the exchange rate from Coinbase, it is designed to use MtGox. I want to avoid using the entire coinbase API because I just want the exchange rate, not the kitchen sink. There is a lot of documentation there.
I have found the code in the uc_bitcoin
drupal module which gets the information from MtGox. It needs some simple changes so it gets this data from Coinbase. Since both are so different, and I’m not fluent with PHP I thought someone might be able to help me with this.
Here is the code which gets the exchange rate from MtGox:
function uc_bitcoin_exchange_rate($order) {
static $rate;
if(isset($rate)) {
return $rate;
}
if ($order->currency == 'BTC') {
// BTC 1:1
return 1;
}
// Supported MtGox currencies, Dec 15 2012
$mtGox_currencies = array(
'USD',
'EUR',
'JPY',
'CAD',
'GBP',
'CHF',
'RUB',
'AUD',
'SEK',
'DKK',
'HKD',
'PLN',
'CNY',
'SGD',
'THB',
'NZD',
'NOK'
);
// @todo add cache
if (in_array($order->currency, $mtGox_currencies)) {
if ($response = drupal_http_request('https://data.mtgox.com/api/1/BTC' . $order->currency . '/ticker')) {
if ($response->code == 200) {
$data = json_decode($response->data);
if(!empty($data->return->avg->value)) {
$rate = $data->return->avg->value;
}
}
}
}
// @todo add cache
if (in_array($order->currency, $mtGox_currencies)) {
if ($response = drupal_http_request('https://data.mtgox.com/api/1/BTC' . $order->currency . '/ticker')) {
if ($response->code == 200) {
$data = json_decode($response->data);
if(!empty($data->return->avg->value)) {
$rate = $data->return->avg->value;
}
}
}
}
if (!$rate || !is_numeric($rate)) {
watchdog('uc_bitcoin', 'MtGox lookup - Unable to get current exchange rate', WATCHDOG_ERROR);
$rate = FALSE; // just to be super sure.
}
return $rate;
}