Skip to content

Instantly share code, notes, and snippets.

@Mobelis
Forked from anonymous/KrakenPriceTicker.sol
Created January 11, 2018 00:43
Show Gist options
  • Save Mobelis/8934bd1f72b59f00b5ce1e5f01ab8c91 to your computer and use it in GitHub Desktop.
Save Mobelis/8934bd1f72b59f00b5ce1e5f01ab8c91 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Jan 11, 2018.
    41 changes: 41 additions & 0 deletions KrakenPriceTicker.sol
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    /*
    Kraken-based ETH/XBT price ticker
    This contract keeps in storage an updated ETH/XBT price,
    which is updated every ~60 seconds.
    */

    pragma solidity ^0.4.0;
    import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";

    contract KrakenPriceTicker is usingOraclize {

    uint8 public ETHXBT;

    event newOraclizeQuery(string description);
    event newKrakenPriceTicker(uint8 price);


    function KrakenPriceTicker() public {
    oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS);
    ETHXBT = 0;
    update();
    }

    function __callback(bytes32 myid, string result, bytes proof) public {
    if (msg.sender != oraclize_cbAddress()) throw;
    ETHXBT = ETHXBT + 1;
    newKrakenPriceTicker(ETHXBT);
    update();
    }

    function update() payable public {
    if (oraclize.getPrice("URL") > this.balance) {
    newOraclizeQuery("Oraclize query was NOT sent, please add some ETH to cover for the query fee");
    } else {
    newOraclizeQuery("Oraclize query counter");
    oraclize_query(60, "URL", "");
    }
    }

    }