Bitcoin Forum

Bitcoin => Project Development => Topic started by: deliveryman on February 11, 2016, 12:12:49 PM



Title: need help with price ticker , im noob :)
Post by: deliveryman on February 11, 2016, 12:12:49 PM
Below is the code im using to show price ticker on my wix.com site.

Now I'd like to add +5% to the ticker (which is my fee for my service).

How can i print: btc price + extra 5%? and how can i print -5%?

Also this ticker only works when i refresh the website, is it also possible to do it real time?

Thanks :)


Quote
<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>USD/BTC " + data["last"].toFixed(2) + "</center>")
        })
    })
</script>
<div id="BTCPrice" style="height:20px;margin:auto;font-family: verdana;font-size: 13;font-weight: bold;position:absolute;color: white;top:10;left:0;bottom:0;right:0" />


Title: Re: need help with price ticker , im noob :)
Post by: Emerge on February 11, 2016, 03:07:06 PM
1. I recommend you don't use wix.com

2. Try using setInterval() for updating the price
read up on it on W3Schools.com or something

3. data["last"].toFixed(2) this gets the data from

https://api.bitcoinaverage.com/ticker/global/USD/
Code:
{
  "24h_avg": 381.58,
  "ask": 378.13,
  "bid": 377.6,
  "last": 378.0, // The data here is used (data["last"])
  "timestamp": "Thu, 11 Feb 2016 15:04:41 -0000",
  "volume_btc": 73598.5,
  "volume_percent": 76.12
}

now you have that, you get that value, + 5%

1 = 100%
0.01 = 1%

Therefore the value + 5% is = value * 1.05

I don't want to give you the actual code, so you can learn :)

Regards,
JM Erestain


Title: Re: need help with price ticker , im noob :)
Post by: deliveryman on February 11, 2016, 10:40:05 PM
1. I recommend you don't use wix.com

2. Try using setInterval() for updating the price
read up on it on W3Schools.com or something

3. data["last"].toFixed(2) this gets the data from

https://api.bitcoinaverage.com/ticker/global/USD/
Code:
{
  "24h_avg": 381.58,
  "ask": 378.13,
  "bid": 377.6,
  "last": 378.0, // The data here is used (data["last"])
  "timestamp": "Thu, 11 Feb 2016 15:04:41 -0000",
  "volume_btc": 73598.5,
  "volume_percent": 76.12
}

now you have that, you get that value, + 5%

1 = 100%
0.01 = 1%

Therefore the value + 5% is = value * 1.05

I don't want to give you the actual code, so you can learn :)

Regards,
JM Erestain

i know its * 1.05 i just dont know where to put it in the code ;(


Title: Re: need help with price ticker , im noob :)
Post by: deliveryman on February 11, 2016, 11:08:41 PM
ok i managed to set the 5% but how do i set the interval :O


Title: Re: need help with price ticker , im noob :)
Post by: 1000000 on February 11, 2016, 11:24:03 PM
ok i managed to set the 5% but how do i set the interval :O
http://www.w3schools.com/jsref/met_win_setinterval.asp ;)


Title: Re: need help with price ticker , im noob :)
Post by: Emerge on February 12, 2016, 12:16:17 PM
ok i managed to set the 5% but how do i set the interval :O
http://www.w3schools.com/jsref/met_win_setinterval.asp ;)

Code:
setInterval(function(){ 
 INSERT CODE HERE
 }, 2000);


Title: Re: need help with price ticker , im noob :)
Post by: Embat on February 12, 2016, 09:28:36 PM
You can use this example code in php:

<?php
      function getPrice($url) {
      $decode = file_get_contents($url);
      return json_decode($decode, true);
                              }

      $btcUSD = getPrice('https://api.kraken.com/0/public/Ticker?pair=XXBTZUSD');
      $btcPrice = $btcUSD["result"]["XXBTZUSD"]["c"][0];
      echo number_format (($btcPrice ), 2)." ". "USD" ;
      ?>

it follows Kraken market price for BTC if you want to do some changes in current price in USD dollars you can just write in ($btcPrice - or + how much you want to reduce or higher the price) and you are ready. It updates itself live and you have a ticker


Title: Re: need help with price ticker , im noob :)
Post by: Emerge on February 13, 2016, 03:15:24 AM
You can use this example code in php:

<?php
      function getPrice($url) {
      $decode = file_get_contents($url);
      return json_decode($decode, true);
                              }

      $btcUSD = getPrice('https://api.kraken.com/0/public/Ticker?pair=XXBTZUSD');
      $btcPrice = $btcUSD["result"]["XXBTZUSD"]["c"][0];
      echo number_format (($btcPrice ), 2)." ". "USD" ;
      ?>

it follows Kraken market price for BTC if you want to do some changes in current price in USD dollars you can just write in ($btcPrice - or + how much you want to reduce or higher the price) and you are ready. It updates itself live and you have a ticker

I learned that PHP isn't the best and the most secure thing you could use.. Much better to keep up with technology and just use the javascript since it's a frontend language you could learn to use with other backend technologies :)