Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
70 lines (60 sloc) 2.21 KB
pragma solidity ^0.4.24;
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "chainlink/contracts/Chainlinked.sol";
@dev Alpha Vantage documentation:
contract AlphaVantageConsumer is Chainlinked, Ownable {
// solium-disable-next-line zeppelin/no-arithmetic-operations
uint256 constant private ORACLE_PAYMENT = 1 * LINK;
bytes32 public jobId;
event RequestFulfilled(
bytes32 indexed requestId,
uint256 price
mapping(bytes32 => bytes32) requests;
mapping(bytes32 => uint256) public prices;
constructor(address _token, address _oracle, bytes32 _jobId) public {
jobId = _jobId;
@dev Request a currency exchange rate
@dev This includes Forex and Cryptocurrencies
@param _from The currency you want to use as the base
@param _to The currency to get in quote
function requestExchangeRate(string _from, string _to) public {
Chainlink.Request memory req = newRequest(jobId, this, this.fulfill.selector);
req.add("function", "CURRENCY_EXCHANGE_RATE");
req.add("from_currency", _from);
req.add("to_currency", _to);
string[] memory path = new string[](2);
path[0] = "Realtime Currency Exchange Rate";
path[1] = "5. Exchange Rate";
req.addStringArray("copyPath", path);
req.addInt("times", 100);
bytes32 requestId = chainlinkRequest(req, ORACLE_PAYMENT);
requests[requestId] = keccak256(abi.encodePacked(_from, _to));
function cancelRequest(
bytes32 _requestId,
uint256 _payment,
bytes4 _callbackFunctionId,
uint256 _expiration
cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);
function fulfill(bytes32 _requestId, uint256 _price)
emit RequestFulfilled(_requestId, _price);
prices[requests[_requestId]] = _price;
delete requests[_requestId];
You can’t perform that action at this time.