Hello
I'm creating a portuguese virtual coins blog in wordpress and i want to put the real time prices and charts on my blog.
for exemple, in dogecoin.com they have always the this: "1 doge =US$0.0011". and it is always update. and i want to do it for all the coins from here (http://cryptmarketcap.com/).
Important, i need the prices to be displayed in euros.
so, if it is possible, could anyone give one code for one coin, and explain me how i can change it to use it to another coins?
Sorry for my poor english.
Best regards
Hariprasad Vijayan answers:
Hello,
Check following code. (Just create a php file using following code and execute.)
<?php
$virtual_coins = array('btc','ltc','ppc','doge');
foreach ($virtual_coins as $row)
{
$pair = $row."_usd";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.cryptocoincharts.info/v2/api/tradingPair/".$pair);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$rawData = curl_exec($curl);
curl_close($curl);
// decode to array
$data = json_decode($rawData);
echo "<pre>";
echo "Price of ".$data->id.": ".$data->price."\n";
echo "Trade this pair on ".$data->best_market."\n";
echo "</pre>";
}
?>
It give updated virtual currency values.
You can see an array
$virtual_coins = array('btc','ltc','ppc','doge');
You can add more currencies into that array from http://cryptmarketcap.com/
You can change $pair = $row."_usd";
to $pair = $row."_eur";
for changing currency to euro. But it won't work for all currencies. I think the reason is some currency has low conversion rate comparing to euro. Let me know if you need any more help.
joao comments:
Hello friend,
the code works, but i dont understand where can i paste the code to appear on one the post, or on the side bar. could you help me?
Hariprasad Vijayan comments:
Sure. Can you show your site url? and tell me where you want to display it.
joao comments:
i can send you the url, but its important? i ask that because i'm only on the begining of the blog, i dont have final template, any post or images. so, when i change template it it will need to change your code?
http://turfmaq.pt/antigo/wordpress/
Hariprasad Vijayan comments:
So, Do you want to display it in http://turfmaq.pt/antigo/wordpress/?p=29 ?
Hariprasad Vijayan comments:
Am not sure about your requirement. If you want to display result in http://turfmaq.pt/antigo/wordpress/?p=29. Do the following steps
1. Install insert php plugin(http://wordpress.org/plugins/insert-php/)
2. Edit post http://turfmaq.pt/antigo/wordpress/?p=29 from dashobard and update with following content.
[insert_php]
$virtual_coins = array('btc','ltc','ppc','doge');
foreach ($virtual_coins as $row)
{
$pair = $row."_usd";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.cryptocoincharts.info/v2/api/tradingPair/".$pair);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$rawData = curl_exec($curl);
curl_close($curl);
// decode to array
$data = json_decode($rawData);
echo "<pre>";
echo "Price of ".$data->id.": ".$data->price."\n";
echo "Trade this pair on ".$data->best_market."\n";
echo "</pre>";
}
[/insert_php]
Nothing more just added [insert_php] and [/insert_php] to code. Feel free to ask doubt if you have any.
Hariprasad Vijayan comments:
Is it working? Please let me know if you need help.
joao comments:
Hello Hariprasad,
It almost done. i can put it on posts. But how can i put it on sidebar?
Best regards
Hariprasad Vijayan comments:
Use PHP Code Widget plugin(http://wordpress.org/plugins/php-code-widget).
Hariprasad Vijayan comments:
Working?
Hariprasad Vijayan comments:
Is it working or still have trouble? Need help?
joao comments:
Hello Hariprasad,
Its working my friend.
Thank you.
Just Me answers:
How do you want this to work? Do you want to read the values (in Euros) from the cryptmarketcap website, display them and keep them up to date by checking the website every few seconds to read the new values and display those?
If so I am not so sure the owner of the website will be pleased by the bandwidth you will be consuming by doing that.
joao comments:
Hello Just me,
on dogecoin.com you have this:1 doge =US$0.0011. If you clink on "US$0.0011" you will go to this page. http://www.cryptocoincharts.info/#jump-doge-btc
in that page you have the prices displayed in euros. exploring this page i fund this:
http://www.cryptocoincharts.info/v2/tools/api
Just Me comments:
Okay, I wasn't aware they provided an API. But keep in mind they also say don't abuse it, and don't create a copy of the page.
Did you try one of the code examples?
You can add this to the functions.php file of your theme.
function my_coin_rates(){
// copy one of the given code blocks here
}
Then call this function on a page.
You can create a new page for it, create a template for that page and add a command like this `my_coin_rates();`
joao comments:
Hello friend,
i dont want to make a copy of the page. what i want to do is make a page for each coin. and only in that page will be display that coin value. On the side bar i only put the top 3 or something..
i dont know if i understand what you said, but i will try.
Best regards
Sébastien | French WordpressDesigner answers:
http://stackoverflow.com/questions/4873873/realtime-currency-webservice
Sébastien | French WordpressDesigner comments:
or try this plugin for wordpress :)
http://codecanyon.net/item/currency-converter-wp/4251740?ref=wpfreemium&ref=wpfreemium&clickthrough_id=203710587&redirect_back=true
Sébastien | French WordpressDesigner comments:
or one of this wordpress plugins :)
http://codecanyon.net/search?utf8=✓&term=currency+converter
joao comments:
hello,
none of them work with digital money.
Best regards