Dashboards and graphs for cryptocurrency data using Node-RED: tutorial

Graphing cryptocurrency data using Node-RED

This is the second tutorial in a series on using the Binance cryptocurrency node we have developed. Take a look at the first tutorial if you haven’t already done so as it introduces you to the basics of the Binance node. This tutorial develops a simple dashboard showing bid and ask prices for symbol BTCUSDT and will look a little like this: Continue reading “Dashboards and graphs for cryptocurrency data using Node-RED: tutorial”

Cryptocurrency prices and data from Binance with Node-RED: tutorial

Getting and displaying basic cryptocurrency data using Node-RED

In this brief tutorial, we’ll introduce the STS Binance node set and some of its capabilities. A follow-on tutorial will show how to develop a dashboard using the nodes and a final tutorial will discuss some possibilities using the trading API that the nodes offer.

The Binance node

For those of you who aren’t familiar, Binance is one of the largest crypto trading platform (perhaps largest by volume), and importantly has a comprehensive and sophisticated API. The resident cryptocurrency expert, Ted, over at Sense Tecnic Systems (STS) recently decided to jump in and develop a new Node for accessing and using the Binance cryptocurrency platform.

Like all these tutorials and lectures, we use the FRED cloud Node-RED service to develop our flows as  Of course you can run Node-RED on your own machine. If you plan to use your own Node-RED installation, then you can download the Binance node from NPM download . If you are using FRED it’s already pre-loaded and can be activated by using the add/remove nodes button under tools on the management panel.  See left image below. This will add the Binance node set, see right image below.

 

 

A couple of caveats:

  1. you’ll need a paid FRED tall (or higher) account to really use the node – otherwise your ability to track in real-time won’t be great
  2. Use it at your own risk – while you can use it for trading, you do so entirely at your own risk. 

Simple flow to get market data

Before we discuss the details of the Binance node, let’s take a look at a simple flow that accesses market data. For this demo we’ll use the Binance getPrice node. In FRED, on a new blank canvas, drag and drop three nodes, an inject node, a Binance getPrice node and a debug node as shown below.

The Binance getPrice node takes a simple ticker pair as input and returns the current price for that ticker. For this example, we’ll use the Bitcoin to Tether USD ticker pair, which is BTCUSDT. We’ll use the inject node to send that to the getPrice node, so double click on the inject node, set the payload to an empty string, and set it’s topic  to BTCUSDT as shown below.

The getPrice node looks for a ticker pair on the incoming message topic and uses that to make an API call to the Binance platform, which returns the current price. Our simple flow then passes that to a debug node, which will show the results in the debug pane on the right side of Node-RED window.

Go ahead and wire up your flow as described, deploy it and then click on the inject node and you’ll see the current price in the debug pane as shown below.

Pretty simple eh! – play around with different ticker pairs to look at your favourite currencies.

Binance node main features

The Binance node set covers two main areas of functionality – accessing market data and account related functionality. The market info nodes all access public APIs on the Binance platform and don’t require an account. The account related nodes access balance and trading features and will require you to setup an account with Binance and to provide an API key. We’ll cover that in a later tutorial, for now we’ll stick with the nodes that use the public API.

Accessing market info

  • getPrice: Gets the latest price of a symbol. Takes a ticker pair as input and returns the current price
  • getAllPrices: Gets the latest price of all symbols. No input and returns an {object} map of all available ticker pairs and their current prices
  • getBookTicker: Gets the bid/ask prices for a symbol. Takes a ticker pair as input and returns an {object} info on latest book price
  • getDayStats: Get the 24hr ticker price change statistics for a symbol. Takes a tickerPair as input and returns the latest 24h stats
  • getCandlesticks: Get Kline/candlestick data for a symbol. Takes a tickerPair, time interval and start/ed times and returns an {array} of candlesticks/kline data specified by parameters

Balance and trading (we’ll explore these in a later tutorial)

  • getOrders: Get open orders for a symbol. Takes and API credential and a tickerPair. Returns an {array} of current orders for that tickerPair
  • getBalance:  Get a list of current balances.Takes and API credential and a tickerPair and returns an {object} map of ticker symbols and quantity on the account
  • cancelOrders: Cancel all open orders of a ticker pair. Takes and API credential and a tickerPair and returns an {object} with the binance API response
  • getTradeHistory: Get trade history of a ticker pair.Takes and API credential and a tickerPair and returns an {array} list of previous orders
  • buy: Create a limit or market buy order. USE AT YOUR OWN RISK.
  • sell: Create a limit or market sell order. USE AT YOUR OWN RISK

Simple flow to get all market data

Let’s continue our simple example shown above but extend it to get all market info. For that we’ll need the getAllPrices node which, as you’d expect, returns all the prices that Binance handles. It’s a long list and is returned as an object. However, we can display it in the debug pane, so let’s modify our original flow and replace the getPrice node with a getAllPrices node as shown below. Note that the inject node doesn’t need to set the topic – although its ignored if you do.

As you can see, you’ll get back a json object – which if you click on to expand lists all the ticker pairs that Binance trades.

Getting bid/ask prices

As a final example, let’s return to the BTCUSDT ticker pair and get the full book info for it using the getBookTicker node. Using the first flow that injects BTCUSDT as a message topic, replace the getPrices node with a getBookTicker node as shown below.

As you can see, the object returned in the message payload for BTCUSDT includes bid price and quantity as well as ask price and quantity.

You can make a simple substitution of the getDayStats node for the getBookTicker node in the flow above to get a full set of day statistics for BTCUSDT. This is quite comprehensive and covers opening prices, previous day close, low and high prices for the day as well as trading volumes etc.

The last node in the set of market access nodes is the getCandlesticks node which gets Kline/candlestick data for a symbol. This requires some knowledge of setting up UI elements and dashboards in Node-RED so we’ll cover that in our next tutorial.

Have fun!


About Sense TecnicSense Tecnic Systems Inc have been building IoT applications and services since 2010. We provide these lectures and FRED, cloud hosted Node-RED as a service to the community. We also offer a commercial version to our customers, as well as professional services. Learn more.

Smart City standards: an overview

Making sense of Smart City standardization activities

Update: For a fuller discussion of Smart City technologies, including standards, read Smart City Technology Trends


Last year I was asked to write an article on Smart City standards for the IEEE standards magazine. This blog post was the basis for that article, but also acts as an evolving document as I update it as standards activities evolve.

First step – get some sort of framework to understand where different standards fit

The amount of activity in Smart City standardization is truly overwhelming – this is partly due to the breadth and scope of Smart City activities – from water pipes to people – and partly because it is early in the process and the standards bodies are still trying to understand how best to contribute.

After spending several days drowning in standards, I decided to step back and try and find a way of categorizing the different standards. I came across a useful framework from the UK’s standards body, the British Standards Institute (BSI), which is part of an excellent (and free) report they’ve written on Smart Cities (PD 8100 Smart city overview)

The Framework categorizes standards into 3 main levels, Strategic, Process and Technical

  • Level 1: Strategic: These are smart city standards that aim to provide guidance to city leadership and other bodies on the “process of developing a clear and effective overall smart city strategy”. They include guidance in identifying priorities, how to develop a roadmap for implementation and how to effectively monitor and evaluate progress along the roadmap.
  • Level 2: Process: Standards in this category are focused on procuring and managing smart city projects – in particular those that cross both organizations and sectors. These essentially offer best practices and associated guidelines.
  • Level 3Technical: This level covers the myriad technical specifications that are needed to actually implement Smart City products and services so that they meet the overall objectives

As the BSI state: “Strategic-level standards are of most relevance to city leadership and process-level standards to people in management posts. However, even technical specifications are relevant to people in management posts as they need to know which standards they need to refer to when procuring technical products and services.”

Using the Framework to position and group standards activities

Once we have a usable framework, the process of trying to fit standards into the levels can begin. The BSI folks have made a useful start – highlighting a number of ongoing international activities that they, as the UK’s standards body, collaborate on – and placing them in the framework.

The main international bodies are:

  • ISO: International Organization for Standards . The main global body that national standards bodies work with and with which many of us are familiar with via “ISO certified”
  • CEN/CENELEC/ETSI: In Europe, standards are developed and agreed by the three officially recognized European Standardization Organisations: the European Committee for Standardization (CEN), the European Committee for Electrotechnical Standardization (CENELEC) and the European Telecommunications Standards Institute (ETSI).
  • ITU: ITU is the United Nations specialized agency for information and communication technologies – ICTs
  • IEC: Founded in 1906, the IEC (International Electrotechnical Commission) is the world’s leading organization for the preparation and publication of International Standards for all electrical, electronic and related technologies. These are known collectively as “electrotechnology”.

Placing major worldwide standards activities in BSI framework (Copyright BSI 2015)

It’s still a fairly daunting set of activities, but at least we now have a sense of where the major international standards groups are focused and we can begin to take a look at some of the more important activities. In the next section, I highlight a few activities that I’ve come across that I think are important and seem to have significant momentum. If you are looking for a more comprehensive list, then in the final section, I’ve listed up all the activities I’ve come across.

Note, most actual standards documents are expensive – unless you are a member of the standards body – so a casual browse isn’t an option. I’ve linked to official documents and summaries below and if I’ve come across a publicly accessible overview, I’ve added that – if you know of better public information, let me know.

If you are working on Smart Cities today – here’s some standards activities you should at least be aware of

STRATEGIC – AIMED AT THE PROCESS OF DEVELOPING A CLEAR AND EFFECTIVE OVERALL SMART CITY STRATEGY
  • ISO 37120 Sustainable development of communities — Indicators for city services and quality of life. This standard, part of a suite by ISO’s Technical Committee 268  identifies 100 indicators that cities should track to allow them to benchmark progress. Actually there are 17 areas, 46 core and 54 supporting indicators that cities either “shall” (core) or “should” (supporting) track and report. The World Council on City Data (WCCD) has been set up by cities to benchmark cities and has certified 17 global cities. Worth taking a look.
  • From the BSI, BS 8904 has a focus on sustainable communities and “provides a framework as recommendations and guidance that assist communities to improve. The recommendations and guidance are intended to be applied by communities of any size, structure and type.”
  • Two draft ISO standards also looking at sustainable communities are ISO 37101: Sustainable development & resilience of communities – Management systems – General principles & requirements  and ISO 37102: Sustainable development & resilience of communities – Vocabulary. An overview of this ongoing work is here
PROCESS – PROCURING AND MANAGING SMART CITY PROJECTS
  • The development by the BIS of a Smart city framework standard (PAS 181) falls into the Process category: “It provides practical, ‘how-to’ advice, reflecting current good practice as identified by a broad range of public, private and voluntary sector practitioners engaged in facilitating UK smart cities”
  • The development of a Data concept model for smart cities (PAS 182). This is probably worth a look at if you are interested in data hubs and data interoperability issues as it bases some of its work on the UK’s HyperCat IoT interoperability standard.
TECHNICAL – IMPLEMENTING SMART CITY PROJECTS
  • Two technical standards that are still under development, (from the ISO/IEC JTC1 group) but worth tracking are ISO/IEC AWI 30145  Information technology – Smart city ICT reference framework and the associated ISO/IEC AWI 30146  Information technology – Smart city ICT indicators which are both looking at the ICT infrastructure needed for Smart Cities. Need a publicly available overview for these. Draft versions of these documents are available here
  • ISO: Report from JTC1 – looking at ICT for smart cities: A 2014 document that lays out the Smart City space from a technical point of view. There’s a useful diagram (fig 4) that highlights the technical areas that ISO, IEC and ITU are working on as well as details of their standards work and of the overall activities of JTC1 – great info but heavy going.
  • IEEE P2413 (http://standards.ieee.org/develop/project/2413.html) is a developing standard from the Institute of Electrical and Electronic Engineers (IEEE) for an architectural framework for the Internet of Things (IoT). The standard is being designed, when completed, to offer a reference model defining relationships among various IoT verticals such as transportation and healthcare (the same verticals that are being transformed in the world’s transition to smart cities) and their common architecture elements.

It’s also worth taking a look at the full set of BSI standards for Smart Cities. Although these are national standards, the UK seems to have developed a comprehensive set of Smart City activities quite early and they appear to be feeding in to ongoing international organizations.

A somewhat more nascent effort by the US National Institute of Standards (NIST) can be found here – this seems to be more of a ‘call to action’ than actual NIST endorsed standards, but worth taking a look at if you are USA based.

A more comprehensive list of the standards activities in the various International groups

Don’t read any further if you are already feeling overwhelmed – but for those who care (or just like this stuff) here’s a more comprehensive list of standards I’ve come across – returning to the BSI framework:

Placing major worldwide standards activities in BSI framework (Copyright BSI 2015)

ISO activities

  • ISO 37120: Sustainable development & resilience of communities – Indicators for city services & quality of life
  • ISO/TR 37150: Smart community infrastructures – Review of existing activities relevant to metrics
  • ISO 37101: Sustainable development & resilience of communities – Management systems – General principles & requirements
  • ISO 37102: Sustainable development & resilience of communities – Vocabulary
  • ISO/TR 37121: Inventory & review of existing indicators on sustainable development & resilience in cities
  • ISO/TS 37151: Smart community infrastructure metrics – General principles & requirements 7.
  • ISO/TR 37152: Smart community infrastructures — Common framework for development & operation
  • A useful slide deck describing activities of ISO JTC1 – Working group on Smart Cities (WG 11) is here

IEC activities

  • IEC/SEG 1: Systems Evaluation Group on Smart Cities – Most of their activities seem to be working group reports, a list that reference ‘Smart Cities’ can be found here

ITU activities

  • ITU-T SG5 FG-SSC: Focus group on smart sustainable cities
    • SSC-0100-Rev 2: Smart Sustainable cities – Analysis of Definitions
    • SSC-0110: Technical Report on Standardization Activities and Gaps for SSC and suggestion to SG5, ITU-T
    • SSC 162: Key performance indicators (KPIs) definitions for smart sustainable cities

CEN-CENELE-ETSI (aka European) activities

Related Standards

While not directly related to Smart Cities, the following technical standards will play a part because they focus on constituent parts of the smart city:

  • General – IEEE has a document that lists up their standards that they think are related to Smart Cities – available here.
  • Security
    • The National Institute of Standards and Technology (NIST) released a preliminary discussion draft of its Framework for Cyber-Physical Systems. The draft has an ambitious goal: to create an integrated framework of standards that will form the blueprint for the creation of a massive interoperable network of cyber-physical systems (CPS), also known as the “Internet of Things.” In 2014, NIST established the cyber-physical systems public working group(CPS PWG)—an open public forum.

Updates

 You may be interested in my article on Technology Trends affecting Smart Cities which includes a discussion of Smart City Standards.

 This blog has been turned into an article for the IEEE standards online Magazine, read it here