Coder Social home page Coder Social logo

mattiapazienti / bitcoin-prices Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miohtama/bitcoin-prices

0.0 2.0 0.0 324 KB

Display bitcoin prices in human-friendly manner in fiat currency using bitcoinaverage.com market data

License: MIT License

bitcoin-prices's Introduction

bitcoinprices.js is a Javascript library for presenting Bitcoin prices in human-friendly manner.

Example:

https://raw.github.com/miohtama/bitcoin-prices/master/example.gif

Demo with clickable bitcoin prices, bitcoin price menu and manu bitcoin price conversion.

No server-side components needed.

You must have jQuery (version 1.9 or later) installed.

Put bitcoinprices.js in your application.

You manually need to call bitcoinprices.init() to trigger the loading of exchange rate data and making price switching logic to work:

<script src="bitcoinprices.js"></script>
<script>
    $(document).ready(function() {
        bitcoinprices.init({

            // Where we get bitcoinaverage data
            url: "https://api.bitcoinaverage.com/ticker/all",

            // Which of bitcoinaverages value we use to present prices
            marketRateVariable: "24h_avg",

            // Which currencies are in shown to the user
            currencies: ["BTC", "USD", "EUR", "CNY"],

            // Special currency symbol artwork
            symbols: {
                "BTC": "<i class='fa fa-btc'></i>"
            },

            // Which currency we show user by the default if
            // no currency is selected
            defaultCurrency: "BTC",

            // How the user is able to interact with the prices
            ux : {
                // Make everything with data-btc-price HTML attribute clickable
                clickPrices : true,

                // Build Bootstrap dropdown menu for currency switching
                menu : true,
            }
        });
    });
</script>

Your templating language must output Bitcoin prices with data-btc-price attribute:

<p>
    <div>Example price: <span data-btc-price="1.0">1.0 BTC</span></div>
</p>
  • You manually initialize the library with bitcoinprices.init() and give it a config you want to use, including bitcoinaverage.com API URL. See the demo for an example.
  • bitcoinprices.init() fires HTML document marketdataavailable event when the script manages to load exchange rates
  • Whenever the user changes price presentation format HTML document activecurrencychange event is fired
  • You can manually call bitcoinprices.convert() to convert between any currencies supported by bitcoinaverage.com
  • You can manually call call bitcoinprices.updatePrices() if your own JavaScripts sets the active currency and all prices on the page are updatd.

It is suggested that you cache bitcoinaverage.com API output on a local server with proper cache headers. This may considerably speed up your site and reduces bitcoinaverage.com load.

See also server-side Python implementation for converting Bitcoin prices.

Mikko Ohtamaa (blog, Facebook, Twitter, Google+)

Contact for work and consulting offers.

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.