The Bitcoin Watcher

by thethingbox in Circuits > Raspberry Pi

1099 Views, 10 Favorites, 0 Comments

The Bitcoin Watcher

bitcoin.JPG
FKDWVEOIKMXGLG4.LARGE.jpg

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

Capture_2.JPG

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

Capture_1.JPG
Capture_3.JPG

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?

Capture_4-1.JPG

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

Capture_4.JPG
Capture_5.JPG
Capture_6.JPG
Capture_7.JPG
Capture_8.JPG
Capture_9.JPG

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!

tsa.jpg