Advanced BCH Monitoring with Tasker (Part 5: Notifying price quotes on your phone)

0 266

Previous part 4:
Retrieving your data from the block explorer API

The IGui API

This interface will allow us to raise any kind of notification with our account and balance.

It needs two variables to keep the most recent balance and value quotes.

Its functions are as follows:

  • updateValue() : updates the last BCH value in the preferred currency. Might also notify relevant changes.

  • updateBalance() : updates the last BCH balance retrieved from querying the blockchain. Might also notify relevant changes.

  • notify() : Notifies the user about the current balance and it's value in the preferred currency.

entry:
    Goto(Type="Action Label", Label="function_updateValue", If(%par1 ~ "function_updateValue");
    Goto(Type="Action Label", Label="function_updateBalance", If(%par1 ~ "function_updateBalance");
    Goto(Type="Action Label", Label="function_notify", If(%par1 ~ "function_notify");
    Return(Value="ERROR", Stop="On");
function_updateValue:
    VariableSet(Name="%value", To="%par2");
    VariableSet(Name="%InputValue", To="%value");
    Return(Value="SUCCESS", Stop="On");
function_updateBalance:
    VariableSet(Name="%value", To="%par2");
    VariableSet(Name="%InputBalance", To="%value");
    Return(Value="SUCCESS", Stop="On");
function_notify:
    Return(Value="SUCCESS", Stop="On");

Implementing the interface, the native android push notification case

There are tons of devices that have tasker integration, millions of ways to notify the user, and many creative ways to show the user how are his assets going.

Here we will develop the native push notification for Android devices, which is the most accessible option.

The steps and implementation behavior here can be adjusted to your convenience.

Let's start with the classic Interface clone: IGui to PushNotificationGui.

Updating currency value quotes

The goal is: updating the last value quote and notifying differences greater than 5%.

entry:
    ( . . . )
function_updateValue:
    VariableSet(Name="%value", To="%par2");
    VariableSet(Name="%delta", To="%value - %PushNotificationGui_InputValue", DoMath="On", If="%PushNotificationGui_InputValue is Set");
    VariableSet(Name="%growth", To="( %delta * 100 ) / %PushNotificationGui_InputValue", DoMath="On", If="%PushNotificationGui_InputValue is S e t");
    Notify(Title="ALERT: BCH grew %growth %", Text="BCH to USD \n $%value ( $%delta )" If="%growth > 5 || %growth < -5");
    VariableSet(Name="%PushNotificationGui_InputValue", To="%value");
    Return(Value="SUCCESS", Stop="On");
function_updateBalance:
    ( . . . )
function_notify:
    ( . . . )

Step by step:

  • We calculate the difference between the current value and the last value (if any) and store it on the %delta variable

  • We calculate the percentage of growth between the current and last value and store it on the %growth variable

  • Then we notify the price movement if the growth is greater than 5%

Updating account balance

The goal is: Notifying when the balance changes more than 546 satoshis. I will also show the units in @Read.Cash Ror.

entry:
    ( . . . )
function_updateValue:
    ( . . . )
function_updateBalance:
    VariableSet(Name="%value", To="%par2");
    VariableSet(Name="%delta", To="%value - %PushNotificationGui_InputBalance", DoMath="On", If="%PushNotificationGui_InputBalance is _Set ");
    VariableSet(Name="%ror", To="%delta / 54600", DoMath="On", If="%PushNotificationGui_InputBalance is _Set");
    VariableSet(Name="%usd", To="(%delta * %PushNotificationGui_InputValue) / 100000000", DoMath="On", If="%PushNotificationGui_InputBalance is _Set");
    Notify(Title="BCH Tx %ror Ror ($%usd)", If="%delta < -546 || %delta > 546");
    VariableSet(Name="%PushNotificationGui_InputBalance", To="%value");
    Return(Value="SUCCESS", Stop="On");
function_notify:
    ( . . . )

Step by step:

  • We calculate the difference between the latest known balance and the new balance and store it in the %delta variable.

  • We translate this difference from satoshis to Ror (1 Ror = 54600 satoshi) and store it in the %ror variable.

  • We translate the difference from satoshis to USD ( %delta * %...InputValue / 100000000 ) and store it in the %usd variable.

  • Finally, we push an alert if the movement is greater than 0.01 Ror (or 546 satoshis)

Updating the permanent notification

The goal is to have a permanent notification where we can check with a single glance the most recent state of our addresses and the value of our assets. The main advantage of using a permanent notification is that the notification silently updates without triggering vibration nor notification sounds.

entry:
    ( . . . )
function_updateValue:
    ( . . . )
function_updateBalance:
    ( . . . )
function_notify:
    VariableSet(Name="%usd_balance", To="%PushNotificationGui_InputValue * ( %PushNotificationGui_InputBalance / 100000000 )", DoMath="On");
    VariableSet(Name="%ror_balance", To="%PushNotificationGui_InputBalance / 54600", DoMath="On");
    Notify(Title="BCH Balance", Text=
    "Balance:
     $%usd_balance
     Ror:
     %ror_balance
     BCHUSD
     $%PushNotificationGui_InputValue", Permament="On");
    Return(Value="SUCCESS", Stop="On");

Step by step:

  • Calculate the equivalent balance in USD with the formula ( value * (satoshi / 100000000) and store it on the local variable %usd_balance

  • Calculate the balance in Ror (more readable than BCH fractions) and store it on %ror_balance

  • Notify the user with a permanent notification.

Testing the notification builder

Time to test! (actually I use to write tests first and develop later, the thing is called Test Driven Development, leave a comment if you are interested in the matter!)

PushNotificationGui_setValueTwice_notifyOnce:
    VariableClear(Name="%PushNotificationGui_InputValue");
    PerformTask(Name="PushNotificationGui", Parameter1="function_updateValue", Parameter2="100", ReturnVariable="%retval");
    PerformTask(Name="PushNotificationGui", Parameter1="function_updateValue", Parameter2="200", ReturnVariable="%retval");
PushNotificationGui_setBalanceTwice_notifyOnce:
    VariableClear(Name="%PushNotificationGui_InputBalance");
    PerformTask(Name="PushNotificationGui", Parameter1="function_updateBalance", Parameter2="100000000", ReturnVariable="%retval");
    PerformTask(Name="PushNotificationGui", Parameter1="function_updateBalance", Parameter2="200000000", ReturnVariable="%retval");
PushNotificationGui_notify_notify:
    PerformTask(Name="PushNotificationGui", Parameter1="function_notify", Parameter2="", ReturnVariable="%retval");

The first test will show a notification telling you that BCH grew 100%, it's even useful to cheer up after a bad day trading. The second test will show a notification telling you that one of your addresses was credited 1 BCH (1831.50 Ror) and the third one will pop up the permanent notification.

In the next part we will be implementing the SDK for allowing you to use all this software we've been developing on any other tasker routine!

Sponsors of elrikpiro
empty
empty
empty

Special thanks to Blockchair.com for providing an API key.

Don't forget to subscribe, feedback will be appreciated!

Part 6: Bitcoin Cash SDK for tasker

2
$ 1.25
$ 0.50 from @btcfork
$ 0.50 from @unitedstatian
$ 0.25 from @Read.Cash

Comments