daily pastebin goal
62%
SHARE
TWEET

Omega2+ Crypto Coin Lookup (PHP)

mrcbrown Aug 22nd, 2017 7 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /****
  4. coins.php (v.04a) by Chuck Brown (http://www.zagnu.com/coin-source.txt)
  5.  
  6. 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
  7. 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.
  8.  
  9.  
  10. ## Changelog
  11.  
  12. .01 -   First Release
  13. .02 -   Adjustments to code & calling methods.
  14.         Changed from XML output to plaintext for use of IMPORTDATA vs IMPORTXML
  15. .03 -   Removed dual posting of plaintext price for import & added amount conversion.
  16.         Commented code.
  17. .04 -   Added Conversion for ATM without Value Text for Onion pull - Also adding $ for easier formatting on Onion curl call.
  18. .04a -  This is the Omega2+ version, can then be gathered from CLI vs. Installing Apache.
  19. ***/
  20.  
  21.  
  22. //Get Data
  23. $url = file_get_contents("https://min-api.cryptocompare.com/data/price?fsym=".$argv[1]."&tsyms=".$argv[2]."");
  24. $json = json_decode($url,true);
  25. //Check for Amount to Convert
  26. if ($argv[3] != '') {
  27. $value = $argv[3] * $json[$argv[2]];
  28. $tvalue = round($value,2);
  29. echo "$".$tvalue;
  30. } else {
  31. //no amount? provide plaintext response for dollar amount.
  32. print $json[$argv[2]];
  33. }
  34. ?>
RAW Paste Data
Top