www.webdeveloper.com
Results 1 to 7 of 7

Thread: Ticker

  1. #1
    Join Date
    Dec 2013
    Posts
    5

    Ticker

    Need help to get ticker from an API. At the moment this code is not working ofcourse. Someone could get this to work?

    <html><head><titleJavascript interface test</title>
    <script type="text/javascript" src="http://data.mtgox.com/api/2/BTCEUR/money/ticker_fast"></script>

    </head><body>
    <span class="property">display_short</span>
    <script type="text/javascript">
    window.onload = function() {
    document.getElementById("rate").innerHTML= display_short + " euros.";
    }
    </script>
    </body></html>

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,501
    For a start, the return from that url you are using as a script source is not returning a script, it returns a data object.

    PHP Code:
    <?php
        $data 
    file_get_contents("http://data.mtgox.com/api/2/BTCEUR/money/ticker_fast");

    ?>
    Then in your web page you would turn that in to an object that you can use

    HTML Code:
    <script>
    	dataObject = <?php echo $data; ?>
    </script>
    So... if you were to then do a window.onload event to make an alert( dataObject.result ); pop up a response, if loaded it should say Success... for your example it would be alert( dataObject.data.last_local.display_short );

    This is the simplest method I could think of to obtain the result you need, you should however note that it might be a better option to have your server scraper the data once every 5 or 10 minutes then you store and serve up that data because if the host on that domain you are scraping that data from wants to, they can simply bar your server by IP address or change the URL and then your script fails where as a periodical approach might be better option.
    Last edited by \\.\; 12-06-2013 at 05:42 PM.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    Dec 2013
    Posts
    5
    Why wouldnt it be possible to do this directly with javascript?

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,501
    Because its not.

    http://www.ibm.com/developerworks/library/wa-aj-jsonp1/

    to quote:
    Understanding the same-origin policy limitations
    The same-origin policy prevents a script loaded from one domain from getting or manipulating properties of a document from another domain. That is, the domain of the requested URL must be the same as the domain of the current Web page.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  5. #5
    Join Date
    Dec 2013
    Posts
    5
    Ok, still getting some problems. Could you post the complete code?

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,501
    Put the PHP in the head of the page, put the <script> within the head of your page and job done, you only need access the data by reference as explained.


    PHP Code:
    <?php 
        $data 
    file_get_contents("http://data.mtgox.com/api/2/BTCEUR/money/ticker_fast"); 

    ?>
    <!DOCTYPE>
     <HTML>
      <META http-equiv="Content-Type" content="text/html; charset=utf-8">
      <HEAD>
       <TITLE>Ticker</TITLE>
       <SCRIPT>
           dataObject = <?php echo $data?>
       </SCRIPT>
      </HEAD>

      <BODY>
      <SCRIPT>
        alert( dataObject.result );
      </SCRIPT>
      </BODY>
    </HTML>
    So what was your problem with doing the above? If you don't understand what processes are used then say so, asking for complete code to be frank is a bit rude as its not a code request site, we help people who try to help themselves, so if you have any code issues then please post the code you have and ask a question.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  7. #7
    Join Date
    Dec 2013
    Posts
    5
    I dont want to come over as rude. It's just that working with api's and grabbing this information is really hard to understand for a newbie. Im new to effery aspect of programming so its even harder. But just for your understanding i've spend 20 hours just getting to know how to get this ticker, without any succes. So I really needed this!

    So just a simple thank you!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles