Bitcoin Forum
May 06, 2024, 11:21:53 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Universal bitcoin exchange rate module for OpenCart  (Read 1143 times)
Sebjectivist (OP)
Newbie
*
Offline Offline

Activity: 50
Merit: 0



View Profile
April 16, 2013, 09:30:28 PM
 #1

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,
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
Sebjectivist (OP)
Newbie
*
Offline Offline

Activity: 50
Merit: 0



View Profile
April 22, 2013, 12:35:50 PM
 #2

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?
Sukrim
Legendary
*
Offline Offline

Activity: 2618
Merit: 1006


View Profile
April 22, 2013, 12:36:47 PM
 #3

Why not openexchangerates?

https://www.coinlend.org <-- automated lending at various exchanges.
https://www.bitfinex.com <-- Trade BTC for other currencies and vice versa.
Sebjectivist (OP)
Newbie
*
Offline Offline

Activity: 50
Merit: 0



View Profile
April 22, 2013, 01:33:47 PM
 #4

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:
<?php
// 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)"
?>
Sebjectivist (OP)
Newbie
*
Offline Offline

Activity: 50
Merit: 0



View Profile
May 05, 2013, 07:13:54 AM
Last edit: May 10, 2013, 08:35:05 PM by Sebjectivist
 #5

Come on, give me a hint..

Edit; somebody did!!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!