问题描述
These are 2 urls
api[0] = "https://www.bitstamp.net/api/v2/ticker/ethusd/";
api[1] = "https://api.pro.coinbase.com/products/eth-usd/ticker";
The path for URL 0 is last and the path for URL 1 is price
我希望chainlink节点从这2个网址获取数据(最后和价格)并计算来自2个网址的数据中位数 即中位数 = {last+price)/2; 如何在Chainlink中为这个逻辑编写代码
解决方法
首先,您需要在 Chainlink 文档之后进行 2 个 API 调用。 https://docs.chain.link/docs/make-a-http-get-request/
类似于:
function makeAPICall() public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId,address(this),this.fulfill.selector);
request.add("get","https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
int timesAmount = 10**18;
request.addInt("times",timesAmount);
return sendChainlinkRequestTo(oracle,request,fee);
}
然后,在您的履行功能中,您将采用列表的中位数。
function fulfill(bytes32 _requestId,uint256 _volume) public recordChainlinkFulfillment(_requestId)
{
answers.push(_volume);
// loop through list and take median
}