Author

Topic: Universal bitcoin exchange rate module for OpenCart (Read 1164 times)

newbie
Activity: 50
Merit: 0
Come on, give me a hint..

Edit; somebody did!!
newbie
Activity: 50
Merit: 0
Why not openexchangerates?
Even better!

Getting closer. the documentation of openexchangerates gives an example that looks a lot like the code in the module;
Code:
// Requested file
// Could also be e.g. 'currencies.json' or 'historical/2011-01-01.json'
$file 'latest.json';
$appId 'YOUR_APP_ID';

// Open CURL session:
$ch curl_init("http://openexchangerates.org/api/{$file}?app_id={$appId}");
curl_setopt($chCURLOPT_RETURNTRANSFER1);

// Get the data:
$json curl_exec($ch);
curl_close($ch);

// Decode JSON response:
$exchangeRates json_decode($json);

// You can now access the rates inside the parsed object, like so:
printf(
    
"1 %s in GBP: %s (as of %s)",
    
$exchangeRates->base,
    
$exchangeRates->rates->GBP,
    
date('H:i jS F, Y'$exchangeRates->timestamp)
);
// -> eg. "1 USD in GBP: 0.643749 (as of 11:01, 3rd January 2012)"
?>
legendary
Activity: 2618
Merit: 1007
Why not openexchangerates?
newbie
Activity: 50
Merit: 0
So this code works with dollars and the mtgox api:

Code:
public function runUpdate() {
// print "update running\n";
$path = "1/BTCUSD/ticker";
$req = array();

// API settings
$key = '';
$secret = '';

// generate a nonce as microtime, with as-string handling to avoid problems with 32bits systems
$mt = explode(' ', microtime());
$req['nonce'] = $mt[1].substr($mt[0], 2, 6);

// generate the POST data string
$post_data = http_build_query($req, '', '&');

// generate the extra headers
$headers = array(
'Rest-Key: '.$key,
'Rest-Sign: '.base64_encode(hash_hmac('sha512', $post_data, base64_decode($secret), true)),
);

// our curl handle (initialize if required)
static $ch = null;
if (is_null($ch)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
}
curl_setopt($ch, CURLOPT_URL, 'http://data.mtgox.com/api/'.$path);

// run the query
$res = curl_exec($ch);
if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
$dec = json_decode($res, true);
if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and requested API exists');
$btcdata = $dec;

$currency = "BTC";
$value = $btcdata['return']['avg']['value'];

if ((float)$value) {
$value = 1/$value;
$this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '" . (float)$value . "', date_modified = '" .  $this->db->escape(date('Y-m-d H:i:s')) . "' WHERE code = '" . $this->db->escape($currency) . "'");
}

$this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '1.00000', date_modified = '" .  $this->db->escape(date('Y-m-d H:i:s')) . "' WHERE code = '" . $this->db->escape($this->config->get('config_currency')) . "'");
$this->cache->delete('currency');
}
}
?>
I want to change it so it works with euro's and the bitcoincharts api. could somebody please tell me how?
newbie
Activity: 50
Merit: 0
I'm incorporating the bitcoin valuta into the webshops I create, and a big problem is still that I have to manually adjust the value of btc. because I don't use USD as the standard currency. there is a module available module that works, but only in relation to USD and so I can't use it practically because my customers are in uk/europe.

Request

I'm fine adjusting code, but creating it not yet  Roll Eyes . So I looked at it and it doesn't seem like such a huge effort to adjust the btcgear module, but I don't know what to do. and I'm not getting any response from btcgear so I'm asking you; would it be possible to fork the module and have users choose any of the markets mentioned here, perhaps by using their API..? Much appreciated,
Jump to: