Bitcoin Forum
June 16, 2024, 09:27:29 PM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: A little help with API's please  (Read 2696 times)
crunck (OP)
Legendary
*
Offline Offline

Activity: 1176
Merit: 1005


crunck


View Profile
January 31, 2017, 11: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:
<?php 
$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


.
.7 BTC  WELCOME BONUS!..
███████████████████████████
██████████▀▀▄▄▄▄▄ ▄▀▀██████
█████████▄██████ ████ ▀████
██████▀▀ ▄▄▄▄ ▀▀███▀▄██ ███
████▀   ██████   ▀██████ ██
███ ▄▄▄████████▄▄▄ ██▄▄▄ ██
██ █████▀    ▀█████ ████ ██
██  ▀██        ███▀ ███ ███
██   ▄██▄    ▄██▄   █▀▄████
███ ▄████████████▄ ████████
████▄▀███▀▀▀▀███▀▄█████████
██████▄▄      ▄▄███████████
███████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████▄▄▄█████▄▄▄████████████████████████████████████████████████████
██████████▄█████▄█▄███▄█▄██████████▄██▀▀▀████████████████████████████████████████████████████
██████████████▀████▄████▀██████████████████████████▄█████▄██▄█████▄████▄████▄████▄████████
█████████████████▐█████▌███████████▄█████▀███▀▀████████▀▀▀▀█████▀▀▀██████▀▀███▀▀███████████
██████████████▄████▀████▄██████████████████▄▄▄▄▄███▄▄▄▄█████▄▄▄████████████████████████
████████████████▀█▀███▀█▀██████████▀███████▀█████████▀█████▀██▀█████▀███████████████████████
██████████████████████████████▀▀▀████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████
████████▀▀  ▐█▌  ▀▀████████
██████▄     ▐█▌     ▄██████
████ ▀██▄▄███████▄▄██▀ ████
███    ██▀▀  ▄  ▀▀██    ███
██    ██   ▄███▄   ██    ██
████████  ███████  ████████
██    ██  ▀▀ █ ▀▀  ██    ██
███    ██▄▄ ▀▀▀ ▄▄██    ███
████ ▄██▀▀██████▀▀▀██▄ ████
██████▀     ▐█▌     ▀██████
████████▄▄  ▐█▌  ▄▄████████
███████████████████████████
.
.30+  ALTCOINS AVAILABLE..
sotisoti
Hero Member
*****
Offline Offline

Activity: 762
Merit: 500


View Profile
January 31, 2017, 11: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

Bitrated user: sotisoti.
crunck (OP)
Legendary
*
Offline Offline

Activity: 1176
Merit: 1005


crunck


View Profile
January 31, 2017, 12:03:53 PM
 #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

.
.7 BTC  WELCOME BONUS!..
███████████████████████████
██████████▀▀▄▄▄▄▄ ▄▀▀██████
█████████▄██████ ████ ▀████
██████▀▀ ▄▄▄▄ ▀▀███▀▄██ ███
████▀   ██████   ▀██████ ██
███ ▄▄▄████████▄▄▄ ██▄▄▄ ██
██ █████▀    ▀█████ ████ ██
██  ▀██        ███▀ ███ ███
██   ▄██▄    ▄██▄   █▀▄████
███ ▄████████████▄ ████████
████▄▀███▀▀▀▀███▀▄█████████
██████▄▄      ▄▄███████████
███████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████▄▄▄█████▄▄▄████████████████████████████████████████████████████
██████████▄█████▄█▄███▄█▄██████████▄██▀▀▀████████████████████████████████████████████████████
██████████████▀████▄████▀██████████████████████████▄█████▄██▄█████▄████▄████▄████▄████████
█████████████████▐█████▌███████████▄█████▀███▀▀████████▀▀▀▀█████▀▀▀██████▀▀███▀▀███████████
██████████████▄████▀████▄██████████████████▄▄▄▄▄███▄▄▄▄█████▄▄▄████████████████████████
████████████████▀█▀███▀█▀██████████▀███████▀█████████▀█████▀██▀█████▀███████████████████████
██████████████████████████████▀▀▀████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████
████████▀▀  ▐█▌  ▀▀████████
██████▄     ▐█▌     ▄██████
████ ▀██▄▄███████▄▄██▀ ████
███    ██▀▀  ▄  ▀▀██    ███
██    ██   ▄███▄   ██    ██
████████  ███████  ████████
██    ██  ▀▀ █ ▀▀  ██    ██
███    ██▄▄ ▀▀▀ ▄▄██    ███
████ ▄██▀▀██████▀▀▀██▄ ████
██████▀     ▐█▌     ▀██████
████████▄▄  ▐█▌  ▄▄████████
███████████████████████████
.
.30+  ALTCOINS AVAILABLE..
crunck (OP)
Legendary
*
Offline Offline

Activity: 1176
Merit: 1005


crunck


View Profile
January 31, 2017, 01:36:16 PM
 #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:
<?php 
$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


.
.7 BTC  WELCOME BONUS!..
███████████████████████████
██████████▀▀▄▄▄▄▄ ▄▀▀██████
█████████▄██████ ████ ▀████
██████▀▀ ▄▄▄▄ ▀▀███▀▄██ ███
████▀   ██████   ▀██████ ██
███ ▄▄▄████████▄▄▄ ██▄▄▄ ██
██ █████▀    ▀█████ ████ ██
██  ▀██        ███▀ ███ ███
██   ▄██▄    ▄██▄   █▀▄████
███ ▄████████████▄ ████████
████▄▀███▀▀▀▀███▀▄█████████
██████▄▄      ▄▄███████████
███████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████▄▄▄█████▄▄▄████████████████████████████████████████████████████
██████████▄█████▄█▄███▄█▄██████████▄██▀▀▀████████████████████████████████████████████████████
██████████████▀████▄████▀██████████████████████████▄█████▄██▄█████▄████▄████▄████▄████████
█████████████████▐█████▌███████████▄█████▀███▀▀████████▀▀▀▀█████▀▀▀██████▀▀███▀▀███████████
██████████████▄████▀████▄██████████████████▄▄▄▄▄███▄▄▄▄█████▄▄▄████████████████████████
████████████████▀█▀███▀█▀██████████▀███████▀█████████▀█████▀██▀█████▀███████████████████████
██████████████████████████████▀▀▀████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████
████████▀▀  ▐█▌  ▀▀████████
██████▄     ▐█▌     ▄██████
████ ▀██▄▄███████▄▄██▀ ████
███    ██▀▀  ▄  ▀▀██    ███
██    ██   ▄███▄   ██    ██
████████  ███████  ████████
██    ██  ▀▀ █ ▀▀  ██    ██
███    ██▄▄ ▀▀▀ ▄▄██    ███
████ ▄██▀▀██████▀▀▀██▄ ████
██████▀     ▐█▌     ▀██████
████████▄▄  ▐█▌  ▄▄████████
███████████████████████████
.
.30+  ALTCOINS AVAILABLE..
sotisoti
Hero Member
*****
Offline Offline

Activity: 762
Merit: 500


View Profile
January 31, 2017, 01:58:50 PM
 #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"<pre>";
print_r($obj);
echo"</pre>";
*/

echo $obj->result->Bid;


Bitrated user: sotisoti.
crunck (OP)
Legendary
*
Offline Offline

Activity: 1176
Merit: 1005


crunck


View Profile
January 31, 2017, 04:07:14 PM
 #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"<pre>";
print_r($obj);
echo"</pre>";
*/

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:
<?php 
$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"<pre>";
print_r($obj);
echo"</pre>";
*/

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

And

Code:
<?php 
$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

.
.7 BTC  WELCOME BONUS!..
███████████████████████████
██████████▀▀▄▄▄▄▄ ▄▀▀██████
█████████▄██████ ████ ▀████
██████▀▀ ▄▄▄▄ ▀▀███▀▄██ ███
████▀   ██████   ▀██████ ██
███ ▄▄▄████████▄▄▄ ██▄▄▄ ██
██ █████▀    ▀█████ ████ ██
██  ▀██        ███▀ ███ ███
██   ▄██▄    ▄██▄   █▀▄████
███ ▄████████████▄ ████████
████▄▀███▀▀▀▀███▀▄█████████
██████▄▄      ▄▄███████████
███████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████▄▄▄█████▄▄▄████████████████████████████████████████████████████
██████████▄█████▄█▄███▄█▄██████████▄██▀▀▀████████████████████████████████████████████████████
██████████████▀████▄████▀██████████████████████████▄█████▄██▄█████▄████▄████▄████▄████████
█████████████████▐█████▌███████████▄█████▀███▀▀████████▀▀▀▀█████▀▀▀██████▀▀███▀▀███████████
██████████████▄████▀████▄██████████████████▄▄▄▄▄███▄▄▄▄█████▄▄▄████████████████████████
████████████████▀█▀███▀█▀██████████▀███████▀█████████▀█████▀██▀█████▀███████████████████████
██████████████████████████████▀▀▀████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████
████████▀▀  ▐█▌  ▀▀████████
██████▄     ▐█▌     ▄██████
████ ▀██▄▄███████▄▄██▀ ████
███    ██▀▀  ▄  ▀▀██    ███
██    ██   ▄███▄   ██    ██
████████  ███████  ████████
██    ██  ▀▀ █ ▀▀  ██    ██
███    ██▄▄ ▀▀▀ ▄▄██    ███
████ ▄██▀▀██████▀▀▀██▄ ████
██████▀     ▐█▌     ▀██████
████████▄▄  ▐█▌  ▄▄████████
███████████████████████████
.
.30+  ALTCOINS AVAILABLE..
sotisoti
Hero Member
*****
Offline Offline

Activity: 762
Merit: 500


View Profile
January 31, 2017, 04:38:06 PM
 #7

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


Code:
{"swing_btc":{"high":0.0000585,"low":0.00004717,"avg":0.00005283,"vol":0.17922473,"vol_cur":3646.92318916,"last":0.00004717,"buy":0.00004717,"sell":0.00005800,"updated":1485880252}}

swing_btc is a JSON key so you'd need it to access the property.

Code:
echo $obj->swing_btc->high;

Bitrated user: sotisoti.
crunck (OP)
Legendary
*
Offline Offline

Activity: 1176
Merit: 1005


crunck


View Profile
January 31, 2017, 10:09:28 PM
 #8

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


Code:
{"swing_btc":{"high":0.0000585,"low":0.00004717,"avg":0.00005283,"vol":0.17922473,"vol_cur":3646.92318916,"last":0.00004717,"buy":0.00004717,"sell":0.00005800,"updated":1485880252}}

swing_btc is a JSON key so you'd need it to access the property.

Code:
echo $obj->swing_btc->high;

Again many thanks for spending time answering my questions its appreciated, I have it working sort of but it displays wrong Sad

http://megahash.co.uk/test1.php

Instead of a normal price it is showing "5.85E-5"

Guess I need to stick to html lol


.
.7 BTC  WELCOME BONUS!..
███████████████████████████
██████████▀▀▄▄▄▄▄ ▄▀▀██████
█████████▄██████ ████ ▀████
██████▀▀ ▄▄▄▄ ▀▀███▀▄██ ███
████▀   ██████   ▀██████ ██
███ ▄▄▄████████▄▄▄ ██▄▄▄ ██
██ █████▀    ▀█████ ████ ██
██  ▀██        ███▀ ███ ███
██   ▄██▄    ▄██▄   █▀▄████
███ ▄████████████▄ ████████
████▄▀███▀▀▀▀███▀▄█████████
██████▄▄      ▄▄███████████
███████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████▄▄▄█████▄▄▄████████████████████████████████████████████████████
██████████▄█████▄█▄███▄█▄██████████▄██▀▀▀████████████████████████████████████████████████████
██████████████▀████▄████▀██████████████████████████▄█████▄██▄█████▄████▄████▄████▄████████
█████████████████▐█████▌███████████▄█████▀███▀▀████████▀▀▀▀█████▀▀▀██████▀▀███▀▀███████████
██████████████▄████▀████▄██████████████████▄▄▄▄▄███▄▄▄▄█████▄▄▄████████████████████████
████████████████▀█▀███▀█▀██████████▀███████▀█████████▀█████▀██▀█████▀███████████████████████
██████████████████████████████▀▀▀████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████
████████▀▀  ▐█▌  ▀▀████████
██████▄     ▐█▌     ▄██████
████ ▀██▄▄███████▄▄██▀ ████
███    ██▀▀  ▄  ▀▀██    ███
██    ██   ▄███▄   ██    ██
████████  ███████  ████████
██    ██  ▀▀ █ ▀▀  ██    ██
███    ██▄▄ ▀▀▀ ▄▄██    ███
████ ▄██▀▀██████▀▀▀██▄ ████
██████▀     ▐█▌     ▀██████
████████▄▄  ▐█▌  ▄▄████████
███████████████████████████
.
.30+  ALTCOINS AVAILABLE..
sotisoti
Hero Member
*****
Offline Offline

Activity: 762
Merit: 500


View Profile
January 31, 2017, 11:39:42 PM
 #9

Code:
$avg = sprintf("%0.8f", $obj->swing_btc->avg);
echo $avg;
http://php.net/manual/en/function.sprintf.php

Bitrated user: sotisoti.
crunck (OP)
Legendary
*
Offline Offline

Activity: 1176
Merit: 1005


crunck


View Profile
February 01, 2017, 12:22:27 AM
 #10

Code:
$avg = sprintf("%0.8f", $obj->swing_btc->avg);
echo $avg;
http://php.net/manual/en/function.sprintf.php

Your a star - Many Thanks

You will be please to know i figured out the cryptopia and nova API thanks to a mixture of your above help

I will be sure to share what I am upto with you once i am a little further down the line with the website

Thanks for the time you have spent here with me:)

Crunck

.
.7 BTC  WELCOME BONUS!..
███████████████████████████
██████████▀▀▄▄▄▄▄ ▄▀▀██████
█████████▄██████ ████ ▀████
██████▀▀ ▄▄▄▄ ▀▀███▀▄██ ███
████▀   ██████   ▀██████ ██
███ ▄▄▄████████▄▄▄ ██▄▄▄ ██
██ █████▀    ▀█████ ████ ██
██  ▀██        ███▀ ███ ███
██   ▄██▄    ▄██▄   █▀▄████
███ ▄████████████▄ ████████
████▄▀███▀▀▀▀███▀▄█████████
██████▄▄      ▄▄███████████
███████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████▄▄▄█████▄▄▄████████████████████████████████████████████████████
██████████▄█████▄█▄███▄█▄██████████▄██▀▀▀████████████████████████████████████████████████████
██████████████▀████▄████▀██████████████████████████▄█████▄██▄█████▄████▄████▄████▄████████
█████████████████▐█████▌███████████▄█████▀███▀▀████████▀▀▀▀█████▀▀▀██████▀▀███▀▀███████████
██████████████▄████▀████▄██████████████████▄▄▄▄▄███▄▄▄▄█████▄▄▄████████████████████████
████████████████▀█▀███▀█▀██████████▀███████▀█████████▀█████▀██▀█████▀███████████████████████
██████████████████████████████▀▀▀████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████
████████▀▀  ▐█▌  ▀▀████████
██████▄     ▐█▌     ▄██████
████ ▀██▄▄███████▄▄██▀ ████
███    ██▀▀  ▄  ▀▀██    ███
██    ██   ▄███▄   ██    ██
████████  ███████  ████████
██    ██  ▀▀ █ ▀▀  ██    ██
███    ██▄▄ ▀▀▀ ▄▄██    ███
████ ▄██▀▀██████▀▀▀██▄ ████
██████▀     ▐█▌     ▀██████
████████▄▄  ▐█▌  ▄▄████████
███████████████████████████
.
.30+  ALTCOINS AVAILABLE..
crunck (OP)
Legendary
*
Offline Offline

Activity: 1176
Merit: 1005


crunck


View Profile
February 01, 2017, 03:03:16 PM
 #11


Back again looking for the genius that is "sotisoti"

I am having issues with Nova API

The url is https://novaexchange.com/remote/v2/market/info/BTC_AUR/

and outputs as :
Code:
{"status": "success", "message": "Info for market: BTC_AUR", "markets": [{"bid": "0.00009608", "last_price": "0.00009528", "volume24h": "0.000", "marketid": 40, "currency": "AUR", "marketname": "BTC_AUR", "ask": "0.00013201", "low24h": "0.00009528", "change24h": "0.0", "high24h": "0.00009528", "basecurrency": "BTC"}]}

So there for my code looks like this:

Code:
<?php 
$ch 
curl_init();
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_URL'https://novaexchange.com/remote/v2/market/info/BTC_AUR');
$result curl_exec($ch);
curl_close($ch);

$obj json_decode($result);

/*
echo"<pre>";
print_r ($obj);
echo"</pre>";
*/


$bid sprintf("%0.8f"$obj->markets->bid);
echo 
$bid;

?>

But it returns an output of "0.00000000"

I think it has something to do with this : (in red)

{"status": "success", "message": "Info for market: BTC_AUR", "markets": [{"bid": "0.00009608",

As I have not seen this before.

AM i on the right lines and how do i get around it ?

Many Thanks again

Crunck

.
.7 BTC  WELCOME BONUS!..
███████████████████████████
██████████▀▀▄▄▄▄▄ ▄▀▀██████
█████████▄██████ ████ ▀████
██████▀▀ ▄▄▄▄ ▀▀███▀▄██ ███
████▀   ██████   ▀██████ ██
███ ▄▄▄████████▄▄▄ ██▄▄▄ ██
██ █████▀    ▀█████ ████ ██
██  ▀██        ███▀ ███ ███
██   ▄██▄    ▄██▄   █▀▄████
███ ▄████████████▄ ████████
████▄▀███▀▀▀▀███▀▄█████████
██████▄▄      ▄▄███████████
███████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████▄▄▄█████▄▄▄████████████████████████████████████████████████████
██████████▄█████▄█▄███▄█▄██████████▄██▀▀▀████████████████████████████████████████████████████
██████████████▀████▄████▀██████████████████████████▄█████▄██▄█████▄████▄████▄████▄████████
█████████████████▐█████▌███████████▄█████▀███▀▀████████▀▀▀▀█████▀▀▀██████▀▀███▀▀███████████
██████████████▄████▀████▄██████████████████▄▄▄▄▄███▄▄▄▄█████▄▄▄████████████████████████
████████████████▀█▀███▀█▀██████████▀███████▀█████████▀█████▀██▀█████▀███████████████████████
██████████████████████████████▀▀▀████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████
████████▀▀  ▐█▌  ▀▀████████
██████▄     ▐█▌     ▄██████
████ ▀██▄▄███████▄▄██▀ ████
███    ██▀▀  ▄  ▀▀██    ███
██    ██   ▄███▄   ██    ██
████████  ███████  ████████
██    ██  ▀▀ █ ▀▀  ██    ██
███    ██▄▄ ▀▀▀ ▄▄██    ███
████ ▄██▀▀██████▀▀▀██▄ ████
██████▀     ▐█▌     ▀██████
████████▄▄  ▐█▌  ▄▄████████
███████████████████████████
.
.30+  ALTCOINS AVAILABLE..
sotisoti
Hero Member
*****
Offline Offline

Activity: 762
Merit: 500


View Profile
February 01, 2017, 03:38:03 PM
 #12

AM i on the right lines and how do i get around it ?

That's because novaexchange uses array in its market element so you have to access the first index (markets[0]) like the following:

Code:
echo"<pre>";
print_r($obj);
echo"</pre>";
printf("%0.8f", $obj->markets[0]->bid);

Check out the values returned by print_r and you will understand more.

Bitrated user: sotisoti.
serversmc
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
February 01, 2017, 03:44:34 PM
 #13

I'm not sure if you are going to run into problems with it but when trying to find then answer that was already given there api was redirecting which breaks your php because it doesn't follow redirects consider adding something like.

Code:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
crunck (OP)
Legendary
*
Offline Offline

Activity: 1176
Merit: 1005


crunck


View Profile
February 01, 2017, 04:04:58 PM
 #14

AM i on the right lines and how do i get around it ?

That's because novaexchange uses array in its market element so you have to access the first index (markets[0]) like the following:

Code:
echo"<pre>";
print_r($obj);
echo"</pre>";
printf("%0.8f", $obj->markets[0]->bid);

Check out the values returned by print_r and you will understand more.

Ok so i get print_r makes it readable to us mere mortals, but i dont get the >markets[0]-> where is the
Code:
[0]
coming from

I have played around with it it using http://php.net/manual/en/function.print-r.php and similar for reference but cant get it to budge from its 0.0000000 output Sad

.
.7 BTC  WELCOME BONUS!..
███████████████████████████
██████████▀▀▄▄▄▄▄ ▄▀▀██████
█████████▄██████ ████ ▀████
██████▀▀ ▄▄▄▄ ▀▀███▀▄██ ███
████▀   ██████   ▀██████ ██
███ ▄▄▄████████▄▄▄ ██▄▄▄ ██
██ █████▀    ▀█████ ████ ██
██  ▀██        ███▀ ███ ███
██   ▄██▄    ▄██▄   █▀▄████
███ ▄████████████▄ ████████
████▄▀███▀▀▀▀███▀▄█████████
██████▄▄      ▄▄███████████
███████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████▄▄▄█████▄▄▄████████████████████████████████████████████████████
██████████▄█████▄█▄███▄█▄██████████▄██▀▀▀████████████████████████████████████████████████████
██████████████▀████▄████▀██████████████████████████▄█████▄██▄█████▄████▄████▄████▄████████
█████████████████▐█████▌███████████▄█████▀███▀▀████████▀▀▀▀█████▀▀▀██████▀▀███▀▀███████████
██████████████▄████▀████▄██████████████████▄▄▄▄▄███▄▄▄▄█████▄▄▄████████████████████████
████████████████▀█▀███▀█▀██████████▀███████▀█████████▀█████▀██▀█████▀███████████████████████
██████████████████████████████▀▀▀████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████
████████▀▀  ▐█▌  ▀▀████████
██████▄     ▐█▌     ▄██████
████ ▀██▄▄███████▄▄██▀ ████
███    ██▀▀  ▄  ▀▀██    ███
██    ██   ▄███▄   ██    ██
████████  ███████  ████████
██    ██  ▀▀ █ ▀▀  ██    ██
███    ██▄▄ ▀▀▀ ▄▄██    ███
████ ▄██▀▀██████▀▀▀██▄ ████
██████▀     ▐█▌     ▀██████
████████▄▄  ▐█▌  ▄▄████████
███████████████████████████
.
.30+  ALTCOINS AVAILABLE..
sotisoti
Hero Member
*****
Offline Offline

Activity: 762
Merit: 500


View Profile
February 01, 2017, 04:09:11 PM
 #15

http://stackoverflow.com/questions/30680938/how-can-i-access-an-array-object

This page gets most upvotes and I heartily suggest having a look at it.

Bitrated user: sotisoti.
nemgun
Hero Member
*****
Offline Offline

Activity: 882
Merit: 533



View Profile WWW
February 01, 2017, 06:09:55 PM
 #16

Code:
<?php
// Set the JSON header
header("Content-type: text/json");

//Create a function to make things easyer
function getPrice($url){
$decode file_get_contents($url);
return json_decode($decodetrue);
}

// $y is the request URL
$y getPrice('https://novaexchange.com/remote/v2/market/info/BTC_AUR/');

// $z is the first array
$z $y['markets']; 

//$p is the object in $z array
$p $z[0]['last_price'];

echo 
json_encode($z);
echo 
json_encode($p);
?>

It works like a charm for me

Now for your code :

Code:
printf("%0.8f", $obj->markets[0]->bid);

i guess you should split it in several parts as "->" is for objects, and you require and array in the middle of an object.

first get the object then access market
second access to market array
third walk inside
crunck (OP)
Legendary
*
Offline Offline

Activity: 1176
Merit: 1005


crunck


View Profile
February 01, 2017, 07:50:36 PM
 #17

Thank you both so i nearly have it correct now using this:

Code:
<?php
// Set the JSON header
header("Content-type: text/json");

//Create a function to make things easyer
function getPrice($url){
$decode file_get_contents($url);
return json_decode($decodetrue);
}

// $y is the request URL
$y getPrice('https://novaexchange.com/remote/v2/market/info/BTC_AUR/');

// $z is the first array
$z $y['markets']; 

//$p is the object in $z array
$p $z[0]['bid'];


echo 
json_encode($p);
?>

It is now delivering the correct part, but it has inverted comma's wrapped around it - output with above code is :

Code:
"0.00009608"

I cant believe how confusing this is, but i'm learning Smiley

Crunck


.
.7 BTC  WELCOME BONUS!..
███████████████████████████
██████████▀▀▄▄▄▄▄ ▄▀▀██████
█████████▄██████ ████ ▀████
██████▀▀ ▄▄▄▄ ▀▀███▀▄██ ███
████▀   ██████   ▀██████ ██
███ ▄▄▄████████▄▄▄ ██▄▄▄ ██
██ █████▀    ▀█████ ████ ██
██  ▀██        ███▀ ███ ███
██   ▄██▄    ▄██▄   █▀▄████
███ ▄████████████▄ ████████
████▄▀███▀▀▀▀███▀▄█████████
██████▄▄      ▄▄███████████
███████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████▄▄▄█████▄▄▄████████████████████████████████████████████████████
██████████▄█████▄█▄███▄█▄██████████▄██▀▀▀████████████████████████████████████████████████████
██████████████▀████▄████▀██████████████████████████▄█████▄██▄█████▄████▄████▄████▄████████
█████████████████▐█████▌███████████▄█████▀███▀▀████████▀▀▀▀█████▀▀▀██████▀▀███▀▀███████████
██████████████▄████▀████▄██████████████████▄▄▄▄▄███▄▄▄▄█████▄▄▄████████████████████████
████████████████▀█▀███▀█▀██████████▀███████▀█████████▀█████▀██▀█████▀███████████████████████
██████████████████████████████▀▀▀████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████
████████▀▀  ▐█▌  ▀▀████████
██████▄     ▐█▌     ▄██████
████ ▀██▄▄███████▄▄██▀ ████
███    ██▀▀  ▄  ▀▀██    ███
██    ██   ▄███▄   ██    ██
████████  ███████  ████████
██    ██  ▀▀ █ ▀▀  ██    ██
███    ██▄▄ ▀▀▀ ▄▄██    ███
████ ▄██▀▀██████▀▀▀██▄ ████
██████▀     ▐█▌     ▀██████
████████▄▄  ▐█▌  ▄▄████████
███████████████████████████
.
.30+  ALTCOINS AVAILABLE..
crunck (OP)
Legendary
*
Offline Offline

Activity: 1176
Merit: 1005


crunck


View Profile
February 01, 2017, 11:36:57 PM
 #18

Well I cant get Nova working correctly but I will keep trying Smiley

And for those that have helped this is what I have been upto  http://megahash.co.uk/price

And a huge thanks for the help received its been appreciated and I have learnt a lot.

Crunck

.
.7 BTC  WELCOME BONUS!..
███████████████████████████
██████████▀▀▄▄▄▄▄ ▄▀▀██████
█████████▄██████ ████ ▀████
██████▀▀ ▄▄▄▄ ▀▀███▀▄██ ███
████▀   ██████   ▀██████ ██
███ ▄▄▄████████▄▄▄ ██▄▄▄ ██
██ █████▀    ▀█████ ████ ██
██  ▀██        ███▀ ███ ███
██   ▄██▄    ▄██▄   █▀▄████
███ ▄████████████▄ ████████
████▄▀███▀▀▀▀███▀▄█████████
██████▄▄      ▄▄███████████
███████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████▄▄▄█████▄▄▄████████████████████████████████████████████████████
██████████▄█████▄█▄███▄█▄██████████▄██▀▀▀████████████████████████████████████████████████████
██████████████▀████▄████▀██████████████████████████▄█████▄██▄█████▄████▄████▄████▄████████
█████████████████▐█████▌███████████▄█████▀███▀▀████████▀▀▀▀█████▀▀▀██████▀▀███▀▀███████████
██████████████▄████▀████▄██████████████████▄▄▄▄▄███▄▄▄▄█████▄▄▄████████████████████████
████████████████▀█▀███▀█▀██████████▀███████▀█████████▀█████▀██▀█████▀███████████████████████
██████████████████████████████▀▀▀████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████
████████▀▀  ▐█▌  ▀▀████████
██████▄     ▐█▌     ▄██████
████ ▀██▄▄███████▄▄██▀ ████
███    ██▀▀  ▄  ▀▀██    ███
██    ██   ▄███▄   ██    ██
████████  ███████  ████████
██    ██  ▀▀ █ ▀▀  ██    ██
███    ██▄▄ ▀▀▀ ▄▄██    ███
████ ▄██▀▀██████▀▀▀██▄ ████
██████▀     ▐█▌     ▀██████
████████▄▄  ▐█▌  ▄▄████████
███████████████████████████
.
.30+  ALTCOINS AVAILABLE..
nemgun
Hero Member
*****
Offline Offline

Activity: 882
Merit: 533



View Profile WWW
February 02, 2017, 09:53:54 AM
 #19

Thank you both so i nearly have it correct now using this:

Code:
<?php
// Set the JSON header
header("Content-type: text/json");

//Create a function to make things easyer
function getPrice($url){
$decode file_get_contents($url);
return json_decode($decodetrue);
}

// $y is the request URL
$y getPrice('https://novaexchange.com/remote/v2/market/info/BTC_AUR/');

// $z is the first array
$z $y['markets']; 

//$p is the object in $z array
$p $z[0]['bid'];


echo 
json_encode($p);
?>

It is now delivering the correct part, but it has inverted comma's wrapped around it - output with above code is :

Code:
"0.00009608"

I cant believe how confusing this is, but i'm learning Smiley

Crunck



change : echo json_encode($p); // this line says echo $p in json format
to : echo $p; // this line says echo $p in plain format

This is just one of the several ways to do it, you can play by mixing both my code and your code, but why don't you do it using javascript ? it may be better if you want to use back these infos in the page for display and dynamics.
crunck (OP)
Legendary
*
Offline Offline

Activity: 1176
Merit: 1005


crunck


View Profile
February 27, 2017, 10:37:28 AM
Last edit: February 27, 2017, 11:46:57 AM by crunck
 #20

Ok here goes again, I'm pushing my luck now i know, but is this possible ?

Can I multiply an api out put by another api out put ?

it may be easier to show you:

If you look here http://www.posinvestment.com you will see that my deamon tells me i have 500 Swing coins and the exchange tells me they are 0.00005001BTC each.

Is it possible to multiply the 500 by 0.00005001 to give me a total value of holdings ?

Again thanks for any advice given.

Crunck


EDIT

Also I see I cant have two instances of calling api's from the same src even though the coins are different

Example:

Code:
<table>
<td>
<?php
// Set the JSON header
header("Content-type: text");

//Create a function to make things easyer
function getPrice($url){
$decode file_get_contents($url);
return json_decode($decodetrue);
}

// $y is the request URL
$y getPrice('https://novaexchange.com/remote/v2/market/info/BTC_XRBC/');

// $z is the first array
$z $y['markets']; 

//$p is the object in $z array
$p $z[0]['bid'];


echo (
$p);
?>
BTC
</td>
<tr>
<td>
<td>
<?php
// Set the JSON header
header("Content-type: text");

//Create a function to make things easyer
function getPrice($url){
$decode file_get_contents($url);
return json_decode($decodetrue);
}

// $y is the request URL
$y getPrice('https://novaexchange.com/remote/v2/market/info/BTC_POSIV/');

// $z is the first array
$z $y['markets']; 

//$p is the object in $z array
$p $z[0]['bid'];


echo (
$p);
?>
BTC
</td>
</td>
</table>

.
.7 BTC  WELCOME BONUS!..
███████████████████████████
██████████▀▀▄▄▄▄▄ ▄▀▀██████
█████████▄██████ ████ ▀████
██████▀▀ ▄▄▄▄ ▀▀███▀▄██ ███
████▀   ██████   ▀██████ ██
███ ▄▄▄████████▄▄▄ ██▄▄▄ ██
██ █████▀    ▀█████ ████ ██
██  ▀██        ███▀ ███ ███
██   ▄██▄    ▄██▄   █▀▄████
███ ▄████████████▄ ████████
████▄▀███▀▀▀▀███▀▄█████████
██████▄▄      ▄▄███████████
███████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████▄▄▄█████▄▄▄████████████████████████████████████████████████████
██████████▄█████▄█▄███▄█▄██████████▄██▀▀▀████████████████████████████████████████████████████
██████████████▀████▄████▀██████████████████████████▄█████▄██▄█████▄████▄████▄████▄████████
█████████████████▐█████▌███████████▄█████▀███▀▀████████▀▀▀▀█████▀▀▀██████▀▀███▀▀███████████
██████████████▄████▀████▄██████████████████▄▄▄▄▄███▄▄▄▄█████▄▄▄████████████████████████
████████████████▀█▀███▀█▀██████████▀███████▀█████████▀█████▀██▀█████▀███████████████████████
██████████████████████████████▀▀▀████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████
████████▀▀  ▐█▌  ▀▀████████
██████▄     ▐█▌     ▄██████
████ ▀██▄▄███████▄▄██▀ ████
███    ██▀▀  ▄  ▀▀██    ███
██    ██   ▄███▄   ██    ██
████████  ███████  ████████
██    ██  ▀▀ █ ▀▀  ██    ██
███    ██▄▄ ▀▀▀ ▄▄██    ███
████ ▄██▀▀██████▀▀▀██▄ ████
██████▀     ▐█▌     ▀██████
████████▄▄  ▐█▌  ▄▄████████
███████████████████████████
.
.30+  ALTCOINS AVAILABLE..
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!