Giter VIP home page Giter VIP logo

kaiko-oracle's Introduction

Kaiko API Oracle Feed

Run locally

Requirements

Python3.7

Docker

PyTezos requires some libraries pre-installed. See their quickstart for instructions.

Kaiko API Key

Install Python Requirements

Create a virtual python environment and activate it.

? python3 -m venv .env
? source .env/bin/activate

(.env) ? which pip 
/kaiko/.env/bin/pip

Now you can install requirements without polluting your global python dependencies.Use source .env/bin activate to activate the environment every time you want to use the repo locally. To leave the environment, use deactivate.

(.env) ? pip install -r requirements.txt

Environment Variables

Your environment variables file can be used both for running locally and for running docker. See env-example. Note that for docker to parse the variables correctly, you cannot have whitespace or quotes.

Create one env file per feed.

Running Tezos Sandbox

To run the Tezos Sandbox to develop and test locally, use docker run -it -d -p 127.0.0.1:18731:18731 nomadiclabs/tezos-sandbox:py --time-between-blocks 7 and set ENV=http://localhost:18731 in your env file.

Oracle Contract

The contract included in contract/oracle_contract.tz stores values for each feed as a pair of timestamp and nat value. In api.py, you can see how the results are parsed, and the price value is transformed into nat. Other contract storage types and supporting other transformations than just btc -> satoshi or usd -> cents can be done in this file.

This contract was created using lorentz-contract-oracle

$ stack exec -- lorentz-contract-oracle Oracle print --valueType "(pair timestamp nat)" --oneline

To create a contract on your local sandbox, you can use lorentz-contract-oracle, replacing [bracketed values] with your own:

$ tezos-client --wait none originate contract BTCXTZ transferring 0 from "[public key]" running "$(<[path/to/repo]/contract/oracle_contract.tz)\" --init "$(stack exec -- lorentz-contract-oracle Oracle init --initialValueType "(pair timestamp nat)" --initialValue "(Pair 0 0)" --admin \"[public key]\")" --burn-cap 0.712

Save the KT1 contract address generated in your env file as ORACLE_ADDRESS=KT1...

Start Flask App

With env file created, you can start the flask app as follows:

(.env)$ export $(xargs <env)
(.env)$ flask run

The server should start, and you can make individual requests for oracle updates by hitting localhost:5000. A task that updates the oracle contract every 60 seconds with API data will also start.

Docker

Build

docker build -t kaiko-oracle:latest .

Run:

docker run -d -p 5000:5000 --env-file=[your-env-file] kaiko-oracle

Build and run:

docker build -t kaiko-oracle:latest . && docker run --rm -it -p 5000:5000 --env-file=[your-env-file] kaiko-oracle

For Mainnet deployments, you may want to think about using something more secure than environment variables for your secret keys. Docker swarm provides secrets that cannot be revealed inadvertently by logging the environment. https://docs.docker.com/engine/swarm/secrets/

kaiko-oracle's People

Contributors

sarahfowler73 avatar weaverine avatar

Stargazers

Gábor Mihálcz avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.