Pages:
Author

Topic: A little help with API's please (Read 2694 times)

legendary
Activity: 3444
Merit: 10558
July 15, 2017, 11:56:10 PM
#26
Can anyone tell me why this doesn't work?

https://novaexchange.com/remote/v2/markets/BTC

because that page does NOT exist! in other words novaexchange has not defined anything in that link. remove the /BTC from the end and it will work, giving you all the markets available then in your code loop through the JSON response and put an if for each of them checking to see if the "basecurrency" is equal to "BTC".

also please don't bump old topics to ask a different question Tongue
hero member
Activity: 960
Merit: 514
July 14, 2017, 11:57:04 AM
#25
Can anyone tell me why this doesn't work?

https://novaexchange.com/remote/v2/markets/BTC
hero member
Activity: 716
Merit: 501
May 29, 2017, 01:07:53 AM
#24
This is one I have working from coinmarketcap.com API request.

status.php
Code:

$ch 
curl_init();
curl_setopt($ch,CURLOPT_URL,'https://api.coinmarketcap.com/v1/ticker/bitquark/');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($ch,CURLOPT_TIMEOUT,10);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);

$result curl_exec($ch);
curl_close($ch);
$data json_decode($result,true);

$name $data[0]['name'];
$symbol $data[0]['symbol'];
$rank number_format($data[0]['rank']);
$priceBTC number_format($data[0]['price_btc'], 8);
$priceUSD number_format($data[0]['price_usd'], 4);
$dayVolume number_format($data[0]['24h_volume_usd'], 2);
$marketCap number_format($data[0]['market_cap_usd'], 2);
$totalSupply number_format($data[0]['total_supply'], 2);
$percentChange1Hr number_format($data[0]['percent_change_1h'], 2);
$percentChange24Hr number_format($data[0]['percent_change_24h'], 2);
$percentChange7Days number_format($data[0]['percent_change_7d'], 2);
$lastUpdated $data[0]['last_updated'];


?>

Name : echo "$name";?>


Symbol : echo "$symbol";?>


Ranking : echo "$rank";?>


Price BTC : echo "$priceBTC";?> BTC


Price USD : $echo "$priceUSD";?> USD


24hr Volume : $echo "$dayVolume";?> USD


Market Cap : $echo "$marketCap";?> USD


Total Supply : echo "$totalSupply";?> BTQ


Percent Change 1hr : echo "$percentChange1Hr";?> %


Percent Change 24hr : echo "$percentChange24Hr";?> %


Percent Change 7 Days: echo "$percentChange7Days";?> %


Last Updated : echo date('r'$lastUpdated);?>
hero member
Activity: 882
Merit: 533
February 28, 2017, 03:51:35 AM
#23
i guess you are learning php programming, you should learn to differ array from object and how to access them, php doc will be very usefull, you should have it on  hand
Yes, but it is easy to have detailled informations about the variables we use, var_dump(expression) is made for that, it gives the whole structure of the expression (can be a variable, but can be something else) with the type of each compenent, i use to debug using it.
So if you put var_dump each time you have a problem with a variable, you will know if it is an array, object, string, bool ...
Then you can easily walk into it. The previous example was to help you figure out how many types of variables you are crossing, but the class i sent you will directly return the required data.
sr. member
Activity: 378
Merit: 250
February 27, 2017, 09:10:09 PM
#22
i guess you are learning php programming, you should learn to differ array from object and how to access them, php doc will be very usefull, you should have it on  hand
hero member
Activity: 882
Merit: 533
February 27, 2017, 11:04:15 AM
#21
You should create classes like here: https://github.com/nemgun32/Exchange-API-Tutorial
And use them to query the prices, then you can easily querry annother API as the first one is contained inside the object.
Use the nova library, you will get all the informations you need, except private API.

In your case it is :

Code:
include('nova.php');

// First init the class
$nova = new nova();

//Now select the pairs you want
$pair = array('BTC_XRBC''BTC_POSIV');
$info $nova->getTickerData($pair);

var_dump($info); //you will have an idea of the data there

// Table now
echo '';
foreach (
$info[0][0] as $key => $value) {
echo '';
}
echo 
'';

// Note that it is possible to change the returned responce from getTickerData to form a nice Array with clear data, but it is not the aim of the repo
for ($i=0$i count($info) ; $i++) { 
echo '';
for ($e=0$e count($info[$i]); $e++) { 
foreach ($info[$i][$e] as $key => $value) {
echo '';
}
}
echo '';
}
echo 
'
'$key '
$value '
'
;


?>
legendary
Activity: 1176
Merit: 1005
crunck
February 27, 2017, 06:37:28 AM
#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:






// 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


// 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
hero member
Activity: 882
Merit: 533
February 02, 2017, 05:53:54 AM
#19
Thank you both so i nearly have it correct now using this:

Code:
// 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.
legendary
Activity: 1176
Merit: 1005
crunck
February 01, 2017, 07: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
legendary
Activity: 1176
Merit: 1005
crunck
February 01, 2017, 03:50:36 PM
#17
Thank you both so i nearly have it correct now using this:

Code:
// 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

hero member
Activity: 882
Merit: 533
February 01, 2017, 02:09:55 PM
#16
Code:
// 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
hero member
Activity: 762
Merit: 500
February 01, 2017, 12: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.
legendary
Activity: 1176
Merit: 1005
crunck
February 01, 2017, 12: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"
";
print_r($obj);
echo"
";
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
newbie
Activity: 1
Merit: 0
February 01, 2017, 11:44:34 AM
#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);
hero member
Activity: 762
Merit: 500
February 01, 2017, 11:38:03 AM
#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"
";
print_r($obj);
echo"
";
printf("%0.8f", $obj->markets[0]->bid);

Check out the values returned by print_r and you will understand more.
legendary
Activity: 1176
Merit: 1005
crunck
February 01, 2017, 11:03:16 AM
#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:
$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"
";
print_r ($obj);
echo"
";
*/


$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
legendary
Activity: 1176
Merit: 1005
crunck
January 31, 2017, 08:22:27 PM
#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
hero member
Activity: 762
Merit: 500
January 31, 2017, 07:39:42 PM
#9
Code:
$avg = sprintf("%0.8f", $obj->swing_btc->avg);
echo $avg;
http://php.net/manual/en/function.sprintf.php
legendary
Activity: 1176
Merit: 1005
crunck
January 31, 2017, 06: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

hero member
Activity: 762
Merit: 500
January 31, 2017, 12: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;
Pages:
Jump to: