是否能写一个定时查询股票收盘价的代码啊?

阅读次数 1144

因为没有stock函数(腾讯有),所以没法查询股票的收盘价格并更新相应单元格。所以就想到使用定时运行airscript来达到类似效果,但没编过代码,完全不知道应该怎么弄。我使用bing写了一段代码,但是一提示错误 SyntaxError:Unexpected token (5:20) at 未命名脚本(1).js:5:20
我也不知道怎么改,能麻烦大神改下吗?

// 定义一个函数,获取股票的收盘价
async function getClosePrice(symbol) {
  try {
    // 使用HTTP.fetch方法,向Bing的财经接口发送请求
    let response = await HTTP.fetch("https://bing.com/search?q=" + symbol + "收盘价");
    // 将响应转换为json格式
    let data = await response.json();
    // 从json数据中提取收盘价
    let closePrice = data["finance_results"][0]["data"]["Price"];
    // 打印结果
    console.log("贵州茅台的收盘价是:" + closePrice + "元/股");
  } catch (error) {
    // 处理错误
    console.error(error);
  }
};

// 调用函数,获取贵州茅台的收盘价
getClosePrice("600519");
2 Answers