File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const CoinGecko = {
2+ keyRange : 'priceKey' ,
3+ priceApi : 'https://pro-api.coingecko.com/api/v3/simple/price'
4+ } ;
5+
6+ /**
7+ * ack: https://www.coingecko.com/en/api/documentation
8+ */
9+ function FetchPrice ( token = 'agoric' , vs = 'usd' ) {
10+ console . warn ( 'AMBIENT: UrlFetchApp' ) ;
11+ const { fetch } = UrlFetchApp ;
12+ console . warn ( 'AMBIENT: SpreadsheetApp' ) ;
13+ const doc = SpreadsheetApp . getActive ( ) ;
14+ const apiKey = doc . getRangeByName ( CoinGecko . keyRange ) . getValue ( ) ;
15+
16+ const url = `${ CoinGecko . priceApi } ?ids=${ token } &vs_currencies=${ vs } &x_cg_pro_api_key=${ apiKey } ` ;
17+
18+ const resp = fetch ( url ,
19+ { headers : { accept : 'application/json' } } ) ;
20+ const data = JSON . parse ( resp . getContentText ( ) ) ;
21+ // console.log(data);
22+ const price = data [ token ] . usd ;
23+ return price ;
24+ }
You can’t perform that action at this time.
0 commit comments