Bitcoin Forum
August 09, 2024, 06:39:23 PM *
News: Latest Bitcoin Core release: 27.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Need some Wordpress API help  (Read 1607 times)
jordant (OP)
Member
**
Offline Offline

Activity: 90
Merit: 10


View Profile
March 13, 2014, 08:18:23 PM
 #1

I'm building a new Crypto site, and want to call the price of Bitcoin and Litecoin using APIs.

I'd like to call the price for Bitcoin from this API https://bitcoinaverage.com/api.htm

And the Litecoin price from here: https://btc-e.com/api/documentation

How would I call this data on my Wordpress site?

Willing to send a tip to anyone who can help me get it up and running. It's for a new crypto website I am launching soon.

9inety7even
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
March 13, 2014, 10:16:34 PM
 #2

One easy way to do it would be to have the clients load the prices themselves, using javascript to get the data and put it where you want. An example is included below, just save the code as HTML and open it in your browser. This kind of thing is easy to just drop into an existing page. I set it up with the bitcoin price, if you tip me for that, I can help with the litecoin one also.

Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("https://api.bitcoinaverage.com/ticker/global/USD/", function(data){
            $("#BTCPrice").append("<center>BTC: $" + data["last"] + "</center>")
        })
    })
</script>
<div id="BTCPrice" style="height:40px;margin:auto;position:absolute;top:-20;left:0;bottom:0;right:0" />

jordant (OP)
Member
**
Offline Offline

Activity: 90
Merit: 10


View Profile
March 14, 2014, 07:43:02 AM
 #3

Thanks for that! It looks similar to what should work as far as I know, but it didn't display anything when I added it. I also tried changing it to this:

Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("https://api.bitcoinaverage.com/ticker/global/USD/", function(data){
            $("#BTCPrice").append("<center>BTC: $" + data["last"] + "</center>")
        })
    })
</script>
[b]<div id="BTCPrice" style="height:40px;margin:auto;position:absolute;top:-20;left:0;bottom:0;right:0"></div>[/b]


But that also didn't work.

I'd be happy to tip you for both if I can get them working.

mintodev
Newbie
*
Offline Offline

Activity: 56
Merit: 0


View Profile
March 14, 2014, 10:48:40 AM
 #4

Thanks for that! It looks similar to what should work as far as I know, but it didn't display anything when I added it. I also tried changing it to this:

Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("https://api.bitcoinaverage.com/ticker/global/USD/", function(data){
            $("#BTCPrice").append("<center>BTC: $" + data["last"] + "</center>")
        })
    })
</script>
[b]<div id="BTCPrice" style="height:40px;margin:auto;position:absolute;top:-20;left:0;bottom:0;right:0"></div>[/b]


But that also didn't work.

I'd be happy to tip you for both if I can get them working.

May i know how did you tried to added it?

And did you tried bitcoin ticker for wordpress. You can just download widget, and add widget to your website in simple steps.
skyzer
Newbie
*
Offline Offline

Activity: 27
Merit: 0


View Profile
March 14, 2014, 11:36:59 AM
 #5

Thanks for that! It looks similar to what should work as far as I know, but it didn't display anything when I added it. I also tried changing it to this:

Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("https://api.bitcoinaverage.com/ticker/global/USD/", function(data){
            $("#BTCPrice").append("<center>BTC: $" + data["last"] + "</center>")
        })
    })
</script>
[b]<div id="BTCPrice" style="height:40px;margin:auto;position:absolute;top:-20;left:0;bottom:0;right:0"></div>[/b]


But that also didn't work.

I'd be happy to tip you for both if I can get them working.
Try to write
alert("test"); after the document.ready line like that:

Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        alert("test");
        $.getJSON("https://api.bitcoinaverage.com/ticker/global/USD/", function(data){
            $("#BTCPrice").append("<center>BTC: $" + data["last"] + "</center>")
        })
    })
</script>
[b]<div id="BTCPrice" style="height:40px;margin:auto;position:absolute;top:-20;left:0;bottom:0;right:0"></div>[/b]

See if the alert popup will appear on page loading. If not, then this javascript code is not included in your page
What browser do you use, Chrome? Try opening Inspect Element (mose right-click) and see if there are any errors while loading website.
9inety7even
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
March 14, 2014, 03:30:40 PM
 #6

Thanks for that! It looks similar to what should work as far as I know, but it didn't display anything when I added it. I also tried changing it to this:

Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("https://api.bitcoinaverage.com/ticker/global/USD/", function(data){
            $("#BTCPrice").append("<center>BTC: $" + data["last"] + "</center>")
        })
    })
</script>
[b]<div id="BTCPrice" style="height:40px;margin:auto;position:absolute;top:-20;left:0;bottom:0;right:0"></div>[/b]


But that also didn't work.

I'd be happy to tip you for both if I can get them working.

Can you open the developer console of your browser and take a screenshot? It sounds like you might not be loading jquery, although I'm not 100% sure.

jordant (OP)
Member
**
Offline Offline

Activity: 90
Merit: 10


View Profile
March 14, 2014, 04:40:51 PM
 #7

Thanks for the help to all of you. I got the BTC call working, but now can't get the Litecoin one working. I tried copying the BTC code and changing it exactly to BTC-e, but it didn't work. I also tried combining the Java functions together which also didn't work.

I tried:
Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("https://api.bitcoinaverage.com/ticker/global/USD/", function(data){
            $("#BTCPrice").append("$" + data["last"] + "")
        })
    })
    
    $(document).ready(function() {
        $.getJSON("https://btc-e.com/api/2/ltc_usd/ticker", function(data){
            $("#LTCPrice").append("$" + data["last"] + "")
        })
    })
    
</script>

I also tried like this and couldn't get it to work
Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("https://btc-e.com/api/2/ltc_usd/ticker", function(data){
            $("#LTCPrice").append("$" + data["last"] + "")
        })
    })
</script>

with this code

Code:
<div class="coinprices">
<div class="ltcpricebox"><p>Litecoin</p>
<div id="LTCPrice"></div>
</div>
</div>

I tried the alert test and the Java is loading, it just won't get the Litecoin price.

Please post your tipping addresses so I can send some Bitcoin.


jordant (OP)
Member
**
Offline Offline

Activity: 90
Merit: 10


View Profile
March 14, 2014, 07:09:47 PM
 #8

Thanks for that! It looks similar to what should work as far as I know, but it didn't display anything when I added it. I also tried changing it to this:

Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("https://api.bitcoinaverage.com/ticker/global/USD/", function(data){
            $("#BTCPrice").append("<center>BTC: $" + data["last"] + "</center>")
        })
    })
</script>
[b]<div id="BTCPrice" style="height:40px;margin:auto;position:absolute;top:-20;left:0;bottom:0;right:0"></div>[/b]


But that also didn't work.

I'd be happy to tip you for both if I can get them working.

May i know how did you tried to added it?

And did you tried bitcoin ticker for wordpress. You can just download widget, and add widget to your website in simple steps.
I want to customize the look of the price. Also, I want the price in the header and not in a widget.

9inety7even
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
March 14, 2014, 07:33:48 PM
 #9

Thanks for the help to all of you. I got the BTC call working, but now can't get the Litecoin one working. I tried copying the BTC code and changing it exactly to BTC-e, but it didn't work. I also tried combining the Java functions together which also didn't work.

I tried:
Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("https://api.bitcoinaverage.com/ticker/global/USD/", function(data){
            $("#BTCPrice").append("$" + data["last"] + "")
        })
    })
    
    $(document).ready(function() {
        $.getJSON("https://btc-e.com/api/2/ltc_usd/ticker", function(data){
            $("#LTCPrice").append("$" + data["last"] + "")
        })
    })
    
</script>

I also tried like this and couldn't get it to work
Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("https://btc-e.com/api/2/ltc_usd/ticker", function(data){
            $("#LTCPrice").append("$" + data["last"] + "")
        })
    })
</script>

with this code

Code:
<div class="coinprices">
<div class="ltcpricebox"><p>Litecoin</p>
<div id="LTCPrice"></div>
</div>
</div>

I tried the alert test and the Java is loading, it just won't get the Litecoin price.

Please post your tipping addresses so I can send some Bitcoin.



Try this for the LTC price:

Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("http://whateverorigin.org/get?url=" + encodeURIComponent("https://btc-e.com/api/2/ltc_usd/ticker") + "&callback=?", function(data){
            $("#LTCPrice").append("$" + data["last"] + "")
        })
    })
</script>

My coffee fund address is 1Gk8nqr8W3FadcdawMrGzPXFnXcAZ9k6vL

jordant (OP)
Member
**
Offline Offline

Activity: 90
Merit: 10


View Profile
March 14, 2014, 09:30:01 PM
 #10

Thanks again for the help. Just sent a tip. 

I tried that, but it returns "$undefined"

9inety7even
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
March 14, 2014, 10:04:23 PM
 #11

Thanks again for the help. Just sent a tip. 

I tried that, but it returns "$undefined"

I appreciate it!

I managed to get the BTC-E API working; try this:

Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("http://whateverorigin.org/get?url=" + encodeURIComponent("https://btc-e.com/api/2/ltc_usd/ticker") + "&callback=?", function(data){
            $("#LTCPrice").append("<center>LTC: $" + $.parseJSON(data.contents)["ticker"]["last"] + "</center>")
})
    })
</script>
<div id="LTCPrice" style="height:40px;margin:auto;position:absolute;top:-20;left:0;bottom:0;right:0" />

jordant (OP)
Member
**
Offline Offline

Activity: 90
Merit: 10


View Profile
March 15, 2014, 12:10:23 AM
 #12

That worked! Thanks so much for all the help.

One more question. Right now, the prices load and the decimal place is always random. For BTC sometimes it displayed 620.2 if it's 620.20, and for LTC it will display things like 16.7893.

Is there a way to make it so there's always 2 decimal places?

9inety7even
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
March 15, 2014, 12:22:02 AM
 #13

That worked! Thanks so much for all the help.

One more question. Right now, the prices load and the decimal place is always random. For BTC sometimes it displayed 620.2 if it's 620.20, and for LTC it will display things like 16.7893.

Is there a way to make it so there's always 2 decimal places?

There sure is -- with the toFixed() method. The LTC code becomes:

Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("http://whateverorigin.org/get?url=" + encodeURIComponent("https://btc-e.com/api/2/ltc_usd/ticker") + "&callback=?", function(data){
            $("#LTCPrice").append("<center>LTC: $" + $.parseJSON(data.contents)["ticker"]["last"].toFixed(2) + "</center>")
})
    })
</script>
<div id="LTCPrice" style="height:40px;margin:auto;position:absolute;top:-20;left:0;bottom:0;right:0" />

And the BTC code is now:

Code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON("https://api.bitcoinaverage.com/ticker/global/USD/", function(data){
            $("#BTCPrice").append("<center>BTC: $" + data["last"].toFixed(2) + "</center>")
        })
    })
</script>
<div id="BTCPrice" style="height:40px;margin:auto;position:absolute;top:-20;left:0;bottom:0;right:0" />

GeorgeL
Full Member
***
Offline Offline

Activity: 220
Merit: 100


View Profile
February 26, 2015, 02:20:02 PM
 #14

Hello, can anyone help how to put this to Wordpress site?

http://blockexperts.com/api?coin=brit&action=getheight
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!