Coinbase currency exchange error

0 votes

Accessing the coinbase API https://coinbase.com/api/doc/1.0/currencies/exchange_rates.html In my case i have text boxes with Bitcoin field and other currencies field(usd,gbp,eur etc..) Code:

 <h6>BTC</h6>
 <input type="text" id ="coin"/>
 <div class="row">
    <h6>USD</h6>
    <input type="text" id='usd'/>
 </div>
 <div class="row">
    <h6>GBP</h6>
    <input type="text" id="gbp"/>
 </div>

javascript

$(document).ready(function () {
    $('#coin').keyup(function () {
        var url = 'https://coinbase.com/api/v1/currencies/exchange_rates?callback=?';
        $.getJSON(url, function (data) {
        });
    });
});

Error

SyntaxError: missing ; before statement

{"vnd_to_usd":"4.7e-05","ars_to_btc":"0.00021","mmk_to_btc":"2.0e-06","ye..
Aug 30, 2018 in Blockchain by slayer
• 29,370 points
1,035 views

1 answer to this question.

0 votes

This is the fix:

 $(document).ready(function () {
       $('#coin').keyup(function () {           
         var btc = $('#coin').val();
         $.ajax({
              url: "<?php echo site_url("buy/exchange_rates"); ?>",
              type: "POST",
              data: {
                 btc:btc
              },
              dataType: 'json',
              success: function (data, textStatus, xhr) {
                $('#usd').val(data.usd);
                $('#gbp').val(data.gbp);
              },
              async: false,
              error: function (xhr, textStatus, errorThrown) {
              }
           });
        }); 



 function exchange_rates()
    {
    $btc = $this->input->post('btc');
    if ($btc != "")
        {
        $data = json_decode(file_get_contents("https://coinbase.com/api/v1/currencies/exchange_rates"), 'TRUE');
        $usd = round($data['btc_to_usd']);
        $gbp = round($data['btc_to_gbp']);
        $obj = array();
        $obj['usd'] = $usd; 
        $obj['gbp'] = $gbp;  
        echo json_encode($obj);
        }
    }
answered Aug 30, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

Coinbase spot price SSL Error: does not support SSL at Request

Add 'strictSSL': false to the new client: var btcClient = ...READ MORE

answered Sep 6, 2018 in Blockchain by digger
• 26,740 points
776 views
+1 vote
1 answer

Error while deploying chaincode in IBM Blockchain. Please help.

Try stripping out the 'tree/master' portion of ...READ MORE

answered Apr 26, 2018 in Blockchain by Christine
• 15,790 points
896 views
0 votes
1 answer

Unknown MSP DEFAULT error query chaincode

./byfn.sh -m up After running the above command, ...READ MORE

answered Jun 8, 2018 in Blockchain by Christine
• 15,790 points
807 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,922 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,218 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
885 views
0 votes
1 answer

403 forbidden error coinbase api

I had a similiar issue connecting this API, ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 26,740 points
2,638 views
0 votes
2 answers

Coinbase-php createButton() throws 401 error

I found the explanation for this on ...READ MORE

answered Aug 30, 2018 in Blockchain by Naman
1,059 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP