-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetCoinbaseQuotes.gs
100 lines (82 loc) · 2.88 KB
/
getCoinbaseQuotes.gs
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
96
97
98
99
100
/**
* ____ _ _
* / ___|___ (_)_ __ | |__ __ _ ___ ___
* | | / _ \| | '_ \| '_ \ / _` / __|/ _ \
* | |__| (_) | | | | | |_) | (_| \__ \ __/
* \____\___/|_|_| |_|_.__/ \__,_|___/\___|
* ...for Google Sheets!
*
* This script is meant to fetch a quote from Coinbase and update a cell.
* You can also use the menu to view a current quote in between the one-minute updates.
*
* USAGE:
* Enter a function as you would with =SUM() or any other, selecting from:
* - BTC
* - ETH
* - LTC
*
* For example, if you would like a current quote for Bitcoin to appear in cell B52, edit
* that cell and insert:
*
* =BTC()
*
* This will return a floating point number which you can style with the currency formatting.
* All currencies returned are in USD ($) and are reported by the Coinbase API. USE AT YOUR
* OWN RISK! I am not liable or responsible for the accuracy, availability, or consequences
* of your usage of this app.
*
* @author David Christian Liedle <david.liedle@gmail.com>
* @link https://davidcanhelp.me/
* @license MIT
*/
function getBitcoinQuote() {
console.log("Running getBitcoinQuote()");
endpoint = "https://api.coinbase.com/v2/prices/BTC-USD/spot";
response = JSON.parse(UrlFetchApp.fetch(endpoint) );
amount = response.data.amount;
console.log(amount);
return amount;
} // End of function getBitcoinQuote()
function getEthereumQuote() {
console.log("Running getEthereumQuote()");
endpoint = "https://api.coinbase.com/v2/prices/ETH-USD/spot";
response = JSON.parse(UrlFetchApp.fetch(endpoint) );
amount = response.data.amount;
console.log(amount);
return amount;
} // End of function getEthereumQuote()
function getLitecoinQuote() {
console.log("Running getLitecoinQuote()");
endpoint = "https://api.coinbase.com/v2/prices/LTC-USD/spot";
response = JSON.parse(UrlFetchApp.fetch(endpoint) );
amount = response.data.amount;
console.log(amount);
return amount;
} // End of function getLitecoinQuote()
function getBTC(){
Browser.msgBox("Bitcoin", "Current USD Value of Bitcoin: $"+getBitcoinQuote().toString(), Browser.Buttons.OK);
}
function getETH(){
Browser.msgBox("Ethereum", "Current USD Value of Ethereum: $"+getEthereumQuote().toString(), Browser.Buttons.OK);
}
function getLTC(){
Browser.msgBox("Litecoin", "Current USD Value of Litecoin: $"+getLitecoinQuote().toString(), Browser.Buttons.OK);
}
function BTC(){
return getBitcoinQuote() * 1.0;
}
function ETH(){
return getEthereumQuote() * 1.0;
}
function LTC(){
return getLitecoinQuote() * 1.0;
}
function onOpen(){
var spreadsheet = SpreadsheetApp.getActive();
menuItems = [
{name: "Show Current BTC Quote", functionName: "getBTC"},
{name: "Show Current ETH Quote", functionName: "getETH"},
{name: "Show Current LTC Quote", functionName: "getLTC"}
];
spreadsheet.addMenu("Coinbase", menuItems);
}