Advertisement
Guest User

File/new script Name it 'Code.gs'

a guest
Mar 22nd, 2017
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. /**
  2. * Retrieves exchange rate from Poloniex ETH.
  3. */
  4. function updateETH()
  5. {
  6. var response = UrlFetchApp.fetch("https://poloniex.com/public?command=returnTicker");
  7. // TODO: set your sheet name here
  8. var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Current prices");
  9. var json = JSON.parse(response.getContentText());
  10. var rate = json.BTC_ETH.last;
  11.  
  12. // TODO: set column coordinates here in format (column, row); this is now set to A1
  13. sheet.getRange(2, 3).setValue(rate);
  14. }
  15. /**
  16. * Retrieves exchange rate from Poloniex ETH/ETC.
  17. */
  18. function updateETHETC()
  19. {
  20. var response = UrlFetchApp.fetch("https://poloniex.com/public?command=returnTicker");
  21. // TODO: set your sheet name here
  22. var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Current prices");
  23. var json = JSON.parse(response.getContentText());
  24. var rate = json.ETH_ETC.last;
  25.  
  26. // TODO: set column coordinates here in format (column, row); this is now set to A1
  27. sheet.getRange(2, 5).setValue(rate);
  28. }
  29. /**
  30. * Retrieves exchange rate from Poloniex for BTC.
  31. */
  32. function updateBTC()
  33. {
  34. var response = UrlFetchApp.fetch("https://poloniex.com/public?command=returnTicker");
  35. // TODO: set your sheet name here
  36. var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Current prices");
  37. var json = JSON.parse(response.getContentText());
  38. var rate = json.USDT_BTC.last;
  39.  
  40. // TODO: set column coordinates here in format (column, row); this is now set to A1
  41. sheet.getRange(1, 1).setValue(rate);
  42. }
  43.  
  44.  
  45. /**
  46. * Retrieves Steem exchange rate from Poloniex for STEEM.
  47. */
  48. function updateSteem()
  49. {
  50. var response = UrlFetchApp.fetch("https://poloniex.com/public?command=returnTicker");
  51. // TODO: set your sheet name here
  52. var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Current prices");
  53. var json = JSON.parse(response.getContentText());
  54. var rate = json.BTC_STEEM.last;
  55.  
  56. // TODO: set column coordinates here in format (column, row); this is now set to A1
  57. sheet.getRange(3, 3).setValue(rate);
  58. }
  59. /**
  60. * Retrieves exchange rate from Poloniex for ETC.
  61. */
  62. function updateETC()
  63. {
  64. var response = UrlFetchApp.fetch("https://poloniex.com/public?command=returnTicker");
  65. // TODO: set your sheet name here
  66. var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Current prices");
  67. var json = JSON.parse(response.getContentText());
  68. var rate = json.BTC_ETC.last;
  69.  
  70. // TODO: set column coordinates here in format (column, row); this is now set to A1
  71. sheet.getRange(1, 3).setValue(rate);
  72. }
  73. /**
  74. * Retrieves exchange rate from Bittrex for something.
  75. */
  76. function updatePIVX()
  77. {
  78. var response = UrlFetchApp.fetch("https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC");
  79. // TODO: set your sheet name here
  80. var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Current prices");
  81. var json = JSON.parse(response.getContentText());
  82. var rate = json.BTC-LTC.last;
  83.  
  84. // TODO: set column coordinates here in format (column, row); this is now set to A1
  85. sheet.getRange(3, 4).setValue(rate);
  86. }
  87.  
  88. /**
  89. * Retrieves exchange rate from Kraken not in current use.
  90. */
  91. function updateKraken()
  92. {
  93. var response = UrlFetchApp.fetch("https://api.kraken.com/0/public/Ticker?pair=ETHXBT");
  94. // TODO: set your sheet name here
  95. var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Current prices");
  96. var json = JSON.parse(response.getContentText());
  97. var rate = json.result.XETHXXBT.c[0];
  98.  
  99. // TODO: set column coordinates here in format (column, row); this is now set to A2
  100. sheet.getRange(2, 1).setValue(rate);
  101. }
  102. /**
  103. * Retrieves exchange rate from Kraken for ICN.
  104. */
  105. function updateICN()
  106. {
  107. var response = UrlFetchApp.fetch("https://api.kraken.com/0/public/Ticker?pair=ICNXBT");
  108. // TODO: set your sheet name here
  109. var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Current prices");
  110. var json = JSON.parse(response.getContentText());
  111. var rate = json.result.XICNXXBT.c[0];
  112.  
  113. // TODO: set column coordinates here in format (column, row); this is now set to A2
  114. sheet.getRange(1, 5).setValue(rate);
  115. }
  116. /**
  117. * Retrieves exchange rates from both exchanges.
  118. */
  119. function updateAll()
  120. {
  121. updateETH();
  122. updateSteem();
  123. updateBTC();
  124. updateETC();
  125. updateICN();
  126. updateETHETC();
  127. }
  128.  
  129. /**
  130. * Adds a custom menu to the active spreadsheet, containing a single menu item
  131. * for invoking the function specified above.
  132. * The onOpen() function, when defined, is automatically invoked whenever the
  133. * spreadsheet is opened.
  134. * For more information on using the Spreadsheet API, see
  135. * https://developers.google.com/apps-script/service_spreadsheet
  136. */
  137. function onOpen() {
  138. var sheet = SpreadsheetApp.getActiveSpreadsheet();
  139. var entries = [{
  140. name : "Update ETH",
  141. functionName : "updateETH"
  142. }, {
  143. name : "Update BTC",
  144. functionName : "updateBTC"
  145. }, {
  146. name : "Update Steem",
  147. functionName : "updateSteem"
  148. },{
  149. name : "Update ETH/ETC",
  150. functionName : "updateETHETC"
  151. }, {
  152. name : "Update ETC",
  153. functionName : "updateETC"
  154. }, {
  155. name : "Update ICN",
  156. functionName : "updateICN"
  157. }, {
  158. name : "Update all",
  159. functionName : "updateAll"
  160. }];
  161. sheet.addMenu("Scripts", entries);
  162. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement