The Bitcoin Watcher
We already saw in the instructabe "Scroll a Message on a LED Matrix" how to get the up-to-date Bitcoin value through the paymium API.
We'll see here how to go a step further, and create alerts.
Get the Bitcoin Value
The paymium API proposes to get the Bitcoin value through the command
https://paymium.com/api/v1/data/eur/ticker
It results in the string :
{"high":371.99,"low":347.3,"volume":132.34887801,"bid":360.0,"ask":363.45,"midpoint":361.725,"vwap":356.8826159,"at":1457231721,"price":360.97,"open":368.99,"variation":-2.1735,"currency":"EUR","trade_id":"379f16ea-372b-4088-86dc-fd61e6e11136","size":0.00013851}
The interesting part here is ask, that gives the last known Bitcoin value. It will be stored in msg.payload.ask.
Display the Value
In order to display the value, we just have to put the msg.payload.ask value in a string stored in msg.payload :
msg.payload=(msg.payload.ask+"€");
When to Display?
We can decide when to display the Bitcoin value on the LED panel through the Inject node. In this example, we decide to display the value every 5 minutes.
Create Alerts and Notifications
What is interesting with Bitcoin is certainly to create alerts and notifications. We can imagine for example to play a sound, to send a mail or a SMS, but there are plenty of different ways to notify.
Let's take an example: we'll here send a sms if the running value goes above 400 euros, and display the value with different colors.
We first test the value with the following function:
if (msg.payload.ask >= 400) {
return [ msg, null ]; } else { return [ null, msg ]; }
And we launch the two different actions depending on the result of the test.
If condition is verified, we write the value in green, and send a sms with the value, and if not, we display the value in red.
Learn More!
Learn how to link things together with TimeSquAir (http://TimeSquAir.io) and IBM's Node-RED (http://nodered.org)
and discover the other Instructables: