forked from inozemtsev-roman/digital-asset-price
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwap.php
95 lines (87 loc) · 2.82 KB
/
wap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* Plugin Name: Waves Tokens Info
* Plugin URI: http://megacrypto.online
* Description: This plugin allows you to get some info about all tokens created on waves platform! Price, Decimals, Total Supply, AND MORE!
* Version: 1.0
* Author: Mahdi Maymandi-Nejad
* Author URI: https://maymandi.com/
* License: MIT
*/
function waves_asset( $atts ) {
extract( shortcode_atts( array(
'id' => '',
'priceid' => '',
'fiat' => '',
), $atts, 'asset' ) );
$demolph_output = waves_show( $id,$fiat,$priceid );
return $demolph_output;
}
add_shortcode( "asset", "waves_asset" );
function waves_show( $id,$fiat,$priceid ) {
$response = wp_remote_get( "http://marketdata.wavesplatform.com/api/ticker/$id/$priceid" );
$body = wp_remote_retrieve_body( $response );
$data = json_decode($body, TRUE);
$cmcap = wp_remote_get("https://api.coinmarketcap.com/v1/ticker/waves/?convert=EUR");
$cmbody = wp_remote_retrieve_body($cmcap);
$cmdata = json_decode($cmbody, TRUE);
$asset = array_search("$id", array_column($data, 'amountAssetID'));
$price = $data['24h_close'];
$pricein = $data["priceAssetID"];
$pricename = $data["priceAssetName"];
$wprice = $cmdata[0]["price_usd"];
$btcprice = $cmdata[0]["price_btc"];
$eurprice = $cmdata[0]["price_eur"];
if ($pricein == "WAVES"){
if($fiat == "waves"){
return $price;
} elseif ($fiat == "btc"){
return number_format($price*$btcprice, 10);
} elseif ($fiat == "eur"){
return number_format($price*$eurprice, 10);
}
else{
return number_format($price*$wprice, 10);
}
} else {
return "$price $pricename";
}
}
function waves_tinfo( $atts ) {
extract( shortcode_atts( array(
'id' => '',
'priceid' => '',
'type' => '',
), $atts, 'tinfo' ) );
$demolph_output = waves_shinfo( $id,$type,$priceid );
return $demolph_output;
}
add_shortcode( "tinfo", "waves_tinfo" );
function waves_shinfo( $id,$type,$priceid ) {
$rinfo = wp_remote_get( "http://marketdata.wavesplatform.com/api/ticker/$id/$priceid" );
$binfo = wp_remote_retrieve_body( $rinfo );
$dinfo = json_decode($binfo, TRUE);
$decimals = $dinfo["priceAssetDecimals"];
$volume24h = $dinfo["24h_volume"];
$totalsupply = $dinfo["amountAssetTotalSupply"];
$circusupply = $dinfo["amountAssetCirculatingSupply"];
$maxsupply = $dinfo["amountAssetMaxSupply"];
$low24h = $dinfo["24h_low"];
$high24h = $dinfo["24h_high"];
if ($type == "decimals"){
return $decimals;
} elseif ($type == "24hvolume"){
return $volume24h;
} elseif ($type == "totalsupply"){
return $totalsupply;
} elseif ($type == "circulatingsupply"){
return $circusupply;
} elseif ($type == "maxsupply"){
return $maxsupply;
} elseif ($type == "24hlow"){
return $low24h;
} elseif ($type == "24hhigh"){
return $high24h;
}
}
?>