I'm currently using Chainlink's example HTTP GET code twice to pull Uniswap price and Uniswap supply from a CoinGecko API (see below). I'd like to pull both price and supply from the API in the same "request" and "fulfill" functions so that I can calculate market cap (market_cap = supply * price) within the "fulfill" function. (I realize I can just pull market cap from the API, but I'd like to calculate it for development reasons.)
Is there a way to change the below code to do this? Does Chainlink allow this?
pragma solidity ^0.6.0;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/master/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumer is ChainlinkClient {
uint256 public uniPrice;
uint256 public uniSupply;
//uint256 public uniMarketCap;
address private oracle;
bytes32 private jobId;
uint256 private fee;
/**
* Network: Kovan
* Chainlink - 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e
* Chainlink - 29fa9aa13bf1468788b7cc4a500a45b8
* Fee: 0.1 LINK
*/
constructor() public {
setPublicChainlinkToken();
oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e;
jobId = "29fa9aa13bf1468788b7cc4a500a45b8";
fee = 0.1 * 10 ** 18; // 0.1 LINK
}
//dont forget to fund contract with link
function requestUniPrice() public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfillUniPrice.selector);
request.add("get", "https://api.coingecko.com/api/v3/coins/markets?vs_currency=USD&ids=uniswap%2C%20sushi%2C%20pancakeswap-token&order=market_cap_desc&per_page=100&page=1&sparkline=false");
request.add("path","0.current_price");
return sendChainlinkRequestTo(oracle, request, fee);
}
function requestUniSupply() public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfillUniSupply.selector);
request.add("get", "https://api.coingecko.com/api/v3/coins/markets?vs_currency=USD&ids=uniswap%2C%20sushi%2C%20pancakeswap-token&order=market_cap_desc&per_page=100&page=1&sparkline=false");
request.add("path","0.circulating_supply");
return sendChainlinkRequestTo(oracle, request, fee);
}
function fulfillUniPrice(bytes32 _requestId, uint256 _uniPrice) public recordChainlinkFulfillment(_requestId)
{
uniPrice = _uniPrice;
}
function fulfillUniSupply(bytes32 _requestId, uint256 _uniSupply) public recordChainlinkFulfillment(_requestId)
{
uniSupply = _uniSupply;
}
function withdrawLink() external {
LinkTokenInterface linkToken = LinkTokenInterface(chainlinkTokenAddress());
require(linkToken.transfer(msg.sender, linkToken.balanceOf(address(this))), "Unable to transfer");
}