Pages:
Author

Topic: A little help with API's please - page 2. (Read 2734 times)

legendary
Activity: 1176
Merit: 1005
crunck
January 31, 2017, 11:07:14 AM
#6
This just delivers a blank page.
The API returns JSON output, so naturally you'd need to decode the output in order to access the nested object property:

Code:
$obj = json_decode($result);

/*
echo"
";
print_r($obj);
echo"
";
*/

echo $obj->result->Bid;


Great thank you that worked, if I could though one more question :

What is the difference between this out put https://yobit.net/api/3/ticker/swing_btc and the trex one ?

Your answer worked perfectly for trex but not for yobit :

Code:
$ch curl_init();
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_URL'https://yobit.net/api/3/ticker/swing_btc');
$result curl_exec($ch);
curl_close($ch);

$obj json_decode($result);

/*
echo"
";
print_r($obj);
echo"
";
*/

echo $obj->result->high;
?>

And

Code:
$ch curl_init();
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_URL'https://yobit.net/api/3/ticker/swing_btc');
$result curl_exec($ch);
curl_close($ch);

echo 
$obj[0]->high;
?>

I understand the Trex being json format but the Yobit one isnt ( is it ? ) so in my mind your original answer from coinmarketcap should have worked

Thanks again
hero member
Activity: 762
Merit: 500
January 31, 2017, 08:58:50 AM
#5
This just delivers a blank page.
The API returns JSON output, so naturally you'd need to decode the output in order to access the nested object property:

Code:
$obj = json_decode($result);

/*
echo"
";
print_r($obj);
echo"
";
*/

echo $obj->result->Bid;

legendary
Activity: 1176
Merit: 1005
crunck
January 31, 2017, 08:36:16 AM
#4
This is confusing

So using the very helpful reply above I have tried using it to retrieve a coin price from Trex

API link
https://bittrex.com/api/v1.1/public/getticker/?market=btc-swing

Gives me a response of

Code:
{"success":true,"message":"","result":{"Bid":0.00004331,"Ask":0.00004963,"Last":0.00004331}}

So based on my now working code for the MarketCap ( Thanks sotisoti ) my logic would tell me i can use the same code for Trex .... But no that would be too simple, so what have i done wrong here:

Code:
$ch curl_init();
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_URL'https://bittrex.com/api/v1.1/public/getticker/?market=btc-swing');
$result curl_exec($ch);
curl_close($ch);

echo 
$obj[0]->Bid;
?>

This just delivers a blank page.

Thanks again for any help, I will get my head around this API stuff lol

Crunck

legendary
Activity: 1176
Merit: 1005
crunck
January 31, 2017, 07:03:53 AM
#3
Try
echo $obj[0]->market_cap_usd;

Or
Code:
$array = json_decode($result, true);
echo $array[0]['market_cap_usd'];

if you want array

That worked perfect - Thank You


Crunck
hero member
Activity: 762
Merit: 500
January 31, 2017, 06:59:27 AM
#2
Try
Code:
echo $obj[0]->market_cap_usd;

Or
Code:
$array = json_decode($result, true);
echo $array[0]['market_cap_usd'];

if you want array
legendary
Activity: 1176
Merit: 1005
crunck
January 31, 2017, 06:45:23 AM
#1
Can someone tell me how I can display just the market cap on a webpage using this API

https://api.coinmarketcap.com/v1/ticker/swing

So you will see that returns :
Code:
[
    {
        "id": "swing",
        "name": "Swing",
        "symbol": "SWING",
        "rank": "236",
        "price_usd": "0.0453786",
        "price_btc": "0.00004855",
        "24h_volume_usd": "225.625",
        "market_cap_usd": "87028.0",
        "available_supply": "1917815.0",
        "total_supply": "1917815.0",
        "percent_change_1h": "5.99",
        "percent_change_24h": "-0.35",
        "percent_change_7d": "-9.67",
        "last_updated": "1485862761"
    }
]

But the only bit I want to display is "market_cap_usd"

Ive tried all sorts such as https://api.coinmarketcap.com/v1/ticker/swing?market_cap_usd

and things like this:


Code:
$ch curl_init();
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_URL'https://api.coinmarketcap.com/v1/ticker/swing/');
$result curl_exec($ch);
curl_close($ch);

$obj json_decode($result);
echo 
$result->market_cap_usd;


?>

But cant make it work

Many Thanks for answers


Crunck

Pages:
Jump to: