Bitcoin Forum
September 18, 2019, 04:31:49 AM *
News: If you like a topic and you see an orange "bump" link, click it. More info.
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: need help with price ticker , im noob :)  (Read 844 times)
deliveryman
Sr. Member
****
Offline Offline

Activity: 339
Merit: 250


View Profile
February 11, 2016, 12:12:49 PM
 #1

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 Smiley


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" />
1568781109
Hero Member
*
Offline Offline

Posts: 1568781109

View Profile Personal Message (Offline)

Ignore
1568781109
Reply with quote  #2

1568781109
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1568781109
Hero Member
*
Offline Offline

Posts: 1568781109

View Profile Personal Message (Offline)

Ignore
1568781109
Reply with quote  #2

1568781109
Report to moderator
1568781109
Hero Member
*
Offline Offline

Posts: 1568781109

View Profile Personal Message (Offline)

Ignore
1568781109
Reply with quote  #2

1568781109
Report to moderator
Emerge
Legendary
*
Offline Offline

Activity: 854
Merit: 1000



View Profile
February 11, 2016, 03:07:06 PM
 #2

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 Smiley

Regards,
JM Erestain
deliveryman
Sr. Member
****
Offline Offline

Activity: 339
Merit: 250


View Profile
February 11, 2016, 10:40:05 PM
 #3

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 Smiley

Regards,
JM Erestain

i know its * 1.05 i just dont know where to put it in the code ;(
deliveryman
Sr. Member
****
Offline Offline

Activity: 339
Merit: 250


View Profile
February 11, 2016, 11:08:41 PM
 #4

ok i managed to set the 5% but how do i set the interval :O
1000000
Full Member
***
Offline Offline

Activity: 151
Merit: 100



View Profile
February 11, 2016, 11:24:03 PM
 #5

ok i managed to set the 5% but how do i set the interval :O
http://www.w3schools.com/jsref/met_win_setinterval.asp Wink

“The Times 03/Jan/2009 Chancellor on brink of second bailout for banks”
Emerge
Legendary
*
Offline Offline

Activity: 854
Merit: 1000



View Profile
February 12, 2016, 12:16:17 PM
 #6


Code:
setInterval(function(){
 INSERT CODE HERE
 }, 2000);
Embat
Hero Member
*****
Offline Offline

Activity: 1022
Merit: 501



View Profile WWW
February 12, 2016, 09:28:36 PM
 #7

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



     ▄██    ▐███████▄▄▄       ▄▄█████▄▄      ▄██▄      ▐██▄    ▒▓▓▄      ▄▓▓▒
     ███    ▐██▌▀▀▀▀▀███▄    ███▀▀▀▀▀███▄    ████▄     ▐██▌  ▐▓▄ ▀▓▓▄  ▄▓▓▀ ▄▓▌
     ███    ▐██▌      ███   ███▌      ███▌   ██████    ▐██▌   ▀▓▓▄ ▀▓▓▓▓▀ ▄▓▓▀
     ███    ▐██▌    ▄████  ▐███▌      ▐██▌   ███ ███▄  ▐██▌     ▀▓▓▄ ▀▀ ▄▓▓▀
     ███    ▐█████████▀▀   ▐███▌      ▐██▌   ███  ▀███ ▐██▌      ▓▓▓    ▓▓▓
     ███    ▐██▌   ▀███     ███▌      ███▌   ███    ██████▌   ▄▓▓▀ ▄▓▓▓▓▄ ▓▓▓▄
     ███    ▐██▌     ███    ▀███▄▄▄▄▄████    ███     ▀████▌  ▐▓▀ ▄▓▓▀  ▀▓▓▄ ▀▓▌
     ███    ▐██▌      ███     ▀▀██████▀▀     ███       ███▌    ▄▓▓▀      ▀▓▓▄
                  ▄▄▄█████▄▄▄▄
             ▄▄█▓▓▓▓▓█▀▀▀▀█▓▓▓▓▓█▄
           ▄▓▓▓█▀▀            ▀▀█▓▓█▄
         ▓▓▓█▀                    ▀▓▓█▄
       ▄▓▓▓▀                        ▀▓▓█
      ▄▓▓█                            █▓▓
      ▓▓▓                    ▄██▄     ▐▓▓█
     ▓▓▓                   ▄█▓▓▀       ▐▓▓▌
     ▓▓▓                 ▄█▓▓▀          ▓▓▓
     ▓▓▓       ▓▓▓▄    ▓▓▓▓▀            ▓▓▓
     ▓▓▓        ▀▓▓▓▄█▓▓▓▀             ▐▓▓▌
     ▀▓▓▓         ▀█▓▓█▀               █▓▓
      ▓▓▓▄                            ▓▓▓▌
       ▓▓▓█                         ▄█▓▓▀
        ▀▓▓█▄                     ▄▓▓▓█▀
          ▀▓▓▓█▄               ▄▄█▓▓█▀
            ▀▀█▓▓▓█▄▄▄▄▄▄▄▄▄▄█▓▓▓█▀
                ▀▀██▓▓▓▓▓▓▓███▀▀
Emerge
Legendary
*
Offline Offline

Activity: 854
Merit: 1000



View Profile
February 13, 2016, 03:15:24 AM
 #8

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 Smiley
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!