GithubHelp home page GithubHelp logo

wukoo / bitshares-pricefeed Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zapata/bitshares-pricefeed

0.0 2.0 0.0 379 KB

Price Feed Script for BitShares

License: MIT License

Dockerfile 0.21% Makefile 0.60% Python 99.19%

bitshares-pricefeed's Introduction

Price Feed Script for BitShares

Installation

Installation using Docker

Build docker image:

cd ~
git clone https://github.com/Zapata/bitshares-pricefeed.git
cd bitshares-pricefeed
docker build -t bitshares-pricefeed .

Alternative manual installation on Ubuntu 16.04 LTS or similar.

Install globally:

cd ~
git clone https://github.com/Zapata/bitshares-pricefeed.git
cd bitshares-pricefeed
python setup.py install

Or in a dedicated virtualenv environment:

cd ~
git clone https://github.com/Zapata/bitshares-pricefeed.git
cd bitshares-pricefeed
pip install virtualenv 
virtualenv -p python3 wrappers_env/ 
source wrappers_env/bin/activate
python setup.py install

Create the configuration file:

You can generate a sample configuration file using:

bitshares-pricefeed create

Or copy one from the examples directory:

File Description
default Default configuration generated by create command. Use to publish all the main Bitshares assets.
bsip42 Sample configuration to publish a 'target price' compliant with BSIP42. See below for more information.
hero HERO asset publication configuration.
hertz HERTZ asset publication configuration.
XCD XCD asset publication configuration.
stocks Sample configuration to publish Bitshares NASDAQ stocks trackers.
composite Showcase the Composite source feature (see below)

Add a feed producer name to the config.yml file just created:

vim config.yml
# The producer name(s)
producer: your_witness_name

Manual publication

IF you use docker image you can run:

docker run -v /path/to/config.yml:/config/config.yml bitshares-pricefeed update --active-key=XXXXXXX

If you installed bitshares-pricefeed locally use:

bitshares-pricefeed update --active-key=XXXXXXX

See help for the full description of the command.

Above solution will pass active key credentials on the command line, if you want to reuse a pybitshares wallet see instruction in Use pybitshares encrypted wallet.

Schedule publication

Using cron:

$ crontab -e
ACTIVE_KEY="XXXXXXXXXXXXXXXX"

0,15,30,45 * * * * docker run -v /path/to/config.yaml:/config/config.yaml bitshares-pricefeed update --skip-critical --active-key=$ACTIVE_KEY

Help

$ bitshares-pricefeed --help
Usage: bitshares-pricefeed [OPTIONS] COMMAND [ARGS]...

Options:
  --configfile TEXT
  --node <wss://host:port>  Node to connect to
  --help                    Show this message and exit.

Commands:
  addkey  Add a private key to the wallet
  create  Create config file
  update  Update price feed for assets
$ bitshares-pricefeed update --help
Usage: bitshares-pricefeed update [OPTIONS] [ASSETS]...

  Update price feed for assets

Options:
  --dry-run                       Only compute prices and print result, no
                                  publication.
  --active-key WIF                Active key to be used to sign transactions.
  --confirm-warning / --no-confirm-warning
                                  Need for manual confirmation of warnings
  --skip-critical / --no-skip-critical
                                  Skip critical feeds
  --help                          Show this message and exit.

Sources

The following data sources are currently available:

Name Status Assets type API Key Description
AEX OK Crypto No last and volume (in quote currency) from CEX ticker api with 15 sec delay
AlphaVantage OK FIAT, Stocks, BTC Yes last from unknown source for currencies and from iex for stocks. volume only for stocks (in nb of shares).
Big.One OK Crypto Yes bid/ask average and volume (in quote currency) from bulk CEX ticker API.
Binance OK Crypto No last and volume (in quote currency) from CEX ticker api
BitcoinAverage OK Crypto No Use APIv2, get last and volume from an average of multiple exchanges.
Bitcoin Venezuela OK Crypto No ticker from api with 15 minutes delay, no volume
BitsharesFeed OK Crypto (MPA) No current feed price in Bitshares DEX, no volume.
Bitstamp OK Crypto No last and volume (in quote currency) from CEX ticker api
Bittrex OK Crypto No last and volume (in quote currency) from summary api (bulk)
Coinbase OK Crypto No Use Coinbase Pro (ex GDAX) ticker api to get last and 24h volume.
Coincap OK ALTCAP & ALTCAP.X No use provided market cap, no volume
CoinEgg OK Crypto No last and volume (in quote currency) from CEX ticker api
Coinmarketcap Warn Crypto No volume weighted average of all prices reported at each market, volume in USD, 5 minutes delay (see https://coinmarketcap.com/faq/). V1 API will be closed December 4th, 2018.
CoinmarketcapPro OK Crypto Yes volume weighted average of all prices reported at each market, volume in quote, 1 minutes delay. Use v2 api.
Currencylayer OK FIAT, BTC Yes ticker from api, only USD as base and hourly updated with free subscription, no volume info. From various source (https://currencylayer.com/faq)
CoinTiger OK Crypto No last and volume (in quote currency) from summary api (bulk)
Fixer OK FIAT Yes Very similar to CurrencyLayer, ticker from api, daily from European Central Bank, only EUR with free subscription, no volume info.
Graphene OK Crypto, FIAT, Stocks No last and volume (in quote currency) from Bitshares DEX in realtime
Huobi OK Crypto No close price and volume (in quote currency) from CEX API in realtime
IEX OK Stocks No last ("IEX real time price", "15 minute delayed price", "Close" or "Previous close") and volume.
IndoDax OK Crypto No last and volume (in quote currency) from CEX ticker API.
Kraken OK Crypto No last and volume (in quote currency) from CEX ticker API.
LBank OK Crypto No last and volume (in quote currency) from CEX API in realtime
MagicWallet OK BITCNY/CNY Yes BITCNY/CNY ratio from deposti/withdraw on MagicWallet.
OkCoin OK Crypto No last and volume (in quote currency) from CEX API in realtime
OpenExchangeRates OK FIAT, BTC Yes ticker from api, only USD as base and hourly updated with free subscription, no volume info. From unknown sources except Bitcoin wich is from CoinDesk (https://openexchangerates.org/faq#sources)
Poloniex OK Crypto No last and volume (in quote currency) from CEX API in realtime
Quantl OK Commodities Yes daily price from London Bullion Market Association (LBMA), no volume
RobinHood OK Stocks No last, no volume, from unknown source in real time
WorldCoinIndex OK Crypto Yes volume weighted price, sum of market volume.
ZB OK Crypto No last and volume (in quote currency) from CEX API in realtime

Special sources:

Manual

A manual source is available to inject some manually set / constand data to the source feed. This could be usefull for:

  • testing to avoid connection to a third party datasource.
  • inject a static rate like BitUSD/USD

Example:

exchanges:
  manual:
    klass: Manual
    feed:
      USD:
        BTS:
          price: 42
          volume: 1

Composite

A composite source could be used to group multiple sources together in order to aggregate them using a specific fomula.

Aggregation types formulas could be:

  • min: select the minimum value for each pairs
  • max: select the maximum value for each pairs
  • mean: compute the mean price of all the pairs and sum the volume.
  • weighted_mean: compute the volume weighted mean price of all the pairs and sum the volume.
  • median: compute the median price of all the pairs and sum the volume.
  • first_valid: select the first pairs where the source match an ordered list of sources.

The main use cases is if you want to retrieve a pair like BTC/USD from multiples sources (worldcoinindex, bitcoinaverage, coinmarketcap), but you want to use only one of the value in all your computations. The same apply for FIAT exchange rates from (fixer, currencylayer, openexchangerate, ...).

See example configuration.

Algorithm Based Assets

Some assets use a computed formula as price like HERO or HERTZ. Those are implemented with a source class that return the computed value, usually with USD as quote.

Target price mode (BSIP42)

In order to better maintain the peg of Smartcoins, it might be necessary to apply a negative feedback to the computed price. The published price is no more the market price but a target price. See BSIP42 for more information.

This could be enabled setting the target_price_algorithm option on an asset publication:

assets:
    CNY:
        target_price_algorithm: 'adjusted_feed_price'
        target_price_adjustment_scale: 1.2

The algorithm used and available are under constant development by Bitshares witnesses, so please look at examples/bsip42.yaml for the latest documentation on the possible algorithms and their parameters.

Use of encrypted wallet

Initialize wallet and enter credentials:

$ bitshares-pricefeed addkey

You will need to enter your cli wallet encryption passphrase. If you don't have a pybitshares wallet, yet, one will be created:

Wallet Encryption Passphrase:
Repeat for confirmation:

You will need to enter your Private Key (Active key) here. Hit enter the second time it asks you.

Private Key (wif) [Enter to quit]:

Then you can run the feed update without any argument, it will prompt for the Wallet Encryption Passphrase.

$ bitshares-pricefeed update
Current Wallet Passphrase:

If you don't want to type the Wallet Encryption Passphrase each time, use UNLOCK environment variable.

Example in cron:

$ crontab -e

SHELL=/bin/bash
PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
UNLOCK="PASSWD"

0,15,30,45 * * * * bitshares-pricefeed --configfile /home/ubuntu/config.yml --skip-critical --no-confirm-warning update >> /var/log/bitshares-pricefeed.log 2>&1

Or with Docker image:

docker run -v /path/to/config:/config -v /path/to/wallet:/root/.local/share/bitshares -e UNLOCK=PASS bitshares-pricefeed

Development

To run tests you need get API keys for the providers, and register them as environment variables:

export QUANDL_APIKEY=
export OPENEXCHANGERATE_APIKEY=
export FIXER_APIKEY=
export CURRENCYLAYER_APIKEY=
export ALPHAVANTAGE_APIKEY=
export WORLDCOININDEX_APIKEY= 
export MAGICWALLET_APIKEY=
export COINMARKETCAP_APIKEY=

To run all tests use: pytest.

To run a specific test: pytest -k bitcoinvenezuela.

IMPORTANT NOTE

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

bitshares-pricefeed's People

Contributors

grctest avatar ryanrfox avatar wmbutler avatar xeroc avatar zapata avatar

Watchers

 avatar  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.