-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (37 loc) · 1.3 KB
/
index.js
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
const coinTicker = require('coin-ticker')
const DATA_TO_LOAD = [
{exchange: "poloniex", pair: "BTC_USD"},
{exchange: "poloniex", pair: "ETH_USD"},
{exchange: "poloniex", pair: "DASH_USD"},
{exchange: "poloniex", pair: "XRP_USD"},
{exchange: "poloniex", pair: "XMR_USD"},
{exchange: "poloniex", pair: "ETC_USD"},
{exchange: "poloniex", pair: "ZEC_USD"},
{exchange: "poloniex", pair: "LTC_USD"}
]
const config = require('./config.json')
const gcs = require('@google-cloud/storage')({
projectId: config.GOOGLE_STORAGE.PROJECT_ID,
keyFilename: config.GOOGLE_STORAGE.CREDENTIALS_FILE
})
const storeInGcs = require('./store-gcs')(config, gcs)
refresh = (exchange, pair) => coinTicker(exchange, pair)
loadData = () => {
const promises = []
for (i in DATA_TO_LOAD) {
const ex = DATA_TO_LOAD[i].exchange
const pair = DATA_TO_LOAD[i].pair
const p = refresh(ex, pair).then((result) => storeInGcs(result))
promises.push(p)
}
return Promise.all(promises)
}
/**
* @param {!Object} req Cloud Function request context.
* @param {!Object} res Cloud Function response context.
*/
exports.loadCryptocurrencyData = function loadCryptocurrencyData(req, res) {
loadData()
.then(() => res.status(200).send('Success!'))
.catch((err) => res.status(400).send('Error saving data to GCS'))
}