我使用带有 Google 应用引擎编辑器的 Cloud Shell 创建了自己的 API。这是在测试中运行良好的代码片段:
app.get('/fetch_ticker', (req, res) => {
(async() => {
let pair = req.param('pair', "BTC/ETH");
let ex = req.param('exchange', "coinmarketcap");
let myArr = [];
let exchange = await new ccxt[ex]();
let tickers = await exchange.fetchTicker(pair);
myArr.push(tickers);
//Send req
res.status(200).send(myArr);
})()
});
现在,当我在“Gcloud app deploy”之后尝试并在生产中运行它时,其他获取请求工作正常,但是当“ex”等于“coinmarketcap”时,它只是不断加载并最终给出 500 错误。
更新:
这是日志:
2018-11-03 11:43:50 default[20181103t163752] ==== JS stack trace =========================================
2018-11-03 11:43:50 default[20181103t163752]
2018-11-03 11:43:50 default[20181103t163752] Security context: 0x3e6826325879 <JSObject>
2018-11-03 11:43:50 default[20181103t163752] 1: indexBy(aka indexBy) [/srv/node_modules/ccxt/js/base/functions/generic.js:~82] [pc=0x30a50d2a5374](this=0x32f
9351022d1 <undefined>,/* anonymous */=0x1e7ccf12dc59 <JSArray[37746]>,/* anonymous */=0x32f935144e51 <String[2]: id>,/* anonymous */=0x32f9351022d1 <undefined>)
2018-11-03 11:43:50 default[20181103t163752] 2: arguments adaptor frame: 2->3
2018-11-03 11:43:50 default[20181103t163752] 3: set_markets(aka setMarkets) [/srv/node_modules/ccxt/js/base/Exchange.js:613] ...
2018-11-03 11:43:50 default[20181103t163752]
2018-11-03 11:43:50 default[20181103t163752] FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
2018-11-03 11:43:50 default[20181103t163752] 1: node::Abort() [node]
我尝试使用 node --max_old_space_size=4096 app.js 增加内存,但错误仍然存在。