Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /****
- coins.php (v.04a) by Chuck Brown (http://www.zagnu.com/coin-source.txt)
- A simple API call to get the value of a coin in the user's desired currency, great for using in Google Sheets (Use: =IMPORTDATA("yoururl") or if you simply want to grab
- the current value of a certain coin. Currently geared towards USD, but hope in next version to add proper currency markings for the amount conversion.
- ## Changelog
- .01 - First Release
- .02 - Adjustments to code & calling methods.
- Changed from XML output to plaintext for use of IMPORTDATA vs IMPORTXML
- .03 - Removed dual posting of plaintext price for import & added amount conversion.
- Commented code.
- .04 - Added Conversion for ATM without Value Text for Onion pull - Also adding $ for easier formatting on Onion curl call.
- .04a - This is the Omega2+ version, can then be gathered from CLI vs. Installing Apache.
- ***/
- //Get Data
- $url = file_get_contents("https://min-api.cryptocompare.com/data/price?fsym=".$argv[1]."&tsyms=".$argv[2]."");
- $json = json_decode($url,true);
- //Check for Amount to Convert
- if ($argv[3] != '') {
- $value = $argv[3] * $json[$argv[2]];
- $tvalue = round($value,2);
- echo "$".$tvalue;
- } else {
- //no amount? provide plaintext response for dollar amount.
- print $json[$argv[2]];
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement