Bitcoin Forum
March 29, 2024, 06:21:37 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Looking to display Bitcoin price plus extra % that i will set  (Read 1691 times)
pamamolf (OP)
Member
**
Offline Offline

Activity: 119
Merit: 10

My passion in life is to help people.


View Profile
November 27, 2015, 11:09:06 PM
 #1

Hi

I am looking for someone that can write a few lines of code (maybe use an API) so i can display the current bitcoin price plus an extra % that i will be able to set on a site.

Maybe use a div so it will be easy to use the code in any place on my page.

Thank you
1711693297
Hero Member
*
Offline Offline

Posts: 1711693297

View Profile Personal Message (Offline)

Ignore
1711693297
Reply with quote  #2

1711693297
Report to moderator
"Governments are good at cutting off the heads of a centrally controlled networks like Napster, but pure P2P networks like Gnutella and Tor seem to be holding their own." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1711693297
Hero Member
*
Offline Offline

Posts: 1711693297

View Profile Personal Message (Offline)

Ignore
1711693297
Reply with quote  #2

1711693297
Report to moderator
1711693297
Hero Member
*
Offline Offline

Posts: 1711693297

View Profile Personal Message (Offline)

Ignore
1711693297
Reply with quote  #2

1711693297
Report to moderator
1711693297
Hero Member
*
Offline Offline

Posts: 1711693297

View Profile Personal Message (Offline)

Ignore
1711693297
Reply with quote  #2

1711693297
Report to moderator
coinableS
Legendary
*
Offline Offline

Activity: 1442
Merit: 1179



View Profile WWW
November 28, 2015, 03:34:25 AM
 #2

Here's a simple one I created in PHPfiddle:  http://phpfiddle.org/lite/code/9mbw-iu5v

http://btcthreads.com/how-to-get-the-current-bitcoin-price/

Code:
$url = "https://coinbase.com/api/v1/prices/spot_rate";
$json = json_decode(file_get_contents($url), true);
$price = $json["amount"];
$addP = $price * 1.05; //add 5% to the current exchange rate
echo $addP;

batesresearch
Legendary
*
Offline Offline

Activity: 2424
Merit: 1147


View Profile WWW
November 28, 2015, 12:04:10 PM
 #3

Here's a simple one I created in PHPfiddle:  http://phpfiddle.org/lite/code/9mbw-iu5v

http://btcthreads.com/how-to-get-the-current-bitcoin-price/

Code:
$url = "https://coinbase.com/api/v1/prices/spot_rate";
$json = json_decode(file_get_contents($url), true);
$price = $json["amount"];
$addP = $price * 1.05; //add 5% to the current exchange rate
echo $addP;

Nice little script, good work.

Visit Satoshi's Place, a Bitcoin Hub based in Bury, Manchester, UK.
Website: https://satoshisplace.co.uk
Goals: Educate & Onboard users in to Bitcoin. Lightning network⚡️
pamamolf (OP)
Member
**
Offline Offline

Activity: 119
Merit: 10

My passion in life is to help people.


View Profile
November 28, 2015, 11:01:54 PM
 #4

Great THANKS Smiley

But can you add a few lines of ajax so it can auto refresh?
batesresearch
Legendary
*
Offline Offline

Activity: 2424
Merit: 1147


View Profile WWW
November 28, 2015, 11:31:25 PM
 #5

You can add

header("refresh: 240;"); on the next line after the <?php

^ That's a 240 refresh second, just watch the amount of times your pulling from the API don't exceed the limit

Visit Satoshi's Place, a Bitcoin Hub based in Bury, Manchester, UK.
Website: https://satoshisplace.co.uk
Goals: Educate & Onboard users in to Bitcoin. Lightning network⚡️
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
November 28, 2015, 11:34:32 PM
 #6

Here's a simple one I created in PHPfiddle:  http://phpfiddle.org/lite/code/9mbw-iu5v

http://btcthreads.com/how-to-get-the-current-bitcoin-price/

Code:
$url = "https://coinbase.com/api/v1/prices/spot_rate";
$json = json_decode(file_get_contents($url), true);
$price = $json["amount"];
$addP = $price * 1.05; //add 5% to the current exchange rate
echo $addP;

.php code file
Code:
$k = 0
do {
$url = "https://coinbase.com/api/v1/prices/spot_rate";
$json = json_decode(file_get_contents($url), true);
$price = $json["amount"];
$addP = $price * 1.05; //add 5% to the current exchange rate
echo $addP;
popen("pythonfile.py"); //apparently this works!
} while ($k > 1);

pythonfile.py
Code:

import time
time.sleep(5)

SORRY! for using a previous person's content, i think this should work! If the content owner is unhappy with this, I will remove it (please pm if unhappy)!
I would suggest that you use the preev.com api (it refreshes faster!)

█████████████████████████████████████████████████████████████████████████████████
or this!
.php code file
Code:
$k = 0
do {
header("refresh: 240;");
$url = "https://coinbase.com/api/v1/prices/spot_rate";
$json = json_decode(file_get_contents($url), true);
$price = $json["amount"];
$addP = $price * 1.05; //add 5% to the current exchange rate
echo $addP;
} while ($k > 1);
pamamolf (OP)
Member
**
Offline Offline

Activity: 119
Merit: 10

My passion in life is to help people.


View Profile
November 28, 2015, 11:49:02 PM
 #7

preev.com is cool but no idea how to use the api of them Sad
coinableS
Legendary
*
Offline Offline

Activity: 1442
Merit: 1179



View Profile WWW
November 29, 2015, 03:37:46 AM
 #8

Great THANKS Smiley

But can you add a few lines of ajax so it can auto refresh?

Not a good idea, you'll get banned for hitting the API too many times, but here you go.


HTML:
index.html
Code:
<script src="ajax.js"></script>
<script type="text/javascript">
refreshdiv();
</script>
<div id="pricediv"></div>

AJAX:
ajax.js
Code:


var seconds = 5;
var divid = "pricediv";
var url = "price.php";

function refreshdiv(){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}

fetch_unix_timestamp = function()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}

var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;

xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp.responseText;
setTimeout('refreshdiv()',seconds*1000);
}
}
xmlHttp.open("GET",nocacheurl,true);
xmlHttp.send(null);
}

var seconds;
window.onload = function startrefresh(){
setTimeout('refreshdiv()',seconds*1000);
}

PHP
price.php
Code:
$url = "https://coinbase.com/api/v1/prices/spot_rate";
$json = json_decode(file_get_contents($url), true);
$price = $json["amount"];
$addP = $price * 1.05; //add 5% to the current exchange rate
echo $addP;

pamamolf (OP)
Member
**
Offline Offline

Activity: 119
Merit: 10

My passion in life is to help people.


View Profile
November 29, 2015, 09:22:05 PM
 #9

Great thanks !!!

But:

Quote
Not a good idea, you'll get banned for hitting the API too many times, but here you go.

Is there any other way to make it work like preev (auto refresh)  ?
coinableS
Legendary
*
Offline Offline

Activity: 1442
Merit: 1179



View Profile WWW
November 30, 2015, 12:09:55 AM
 #10

Great thanks !!!

But:

Quote
Not a good idea, you'll get banned for hitting the API too many times, but here you go.

Is there any other way to make it work like preev (auto refresh)  ?

Yes, the way I do it is to set up a database to store the price/market value. Then set a cron job to run every N minutes to update the database with the updated rate.  This way you could have a million visitors and still never exceed the API limits, because you are just querying your own DB instead of hitting them with an API call for every visitor.

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!