Added dynamic percentage watcher options

This commit is contained in:
Llewellyn van der Merwe 2018-01-01 23:14:26 +02:00
parent 7ead918d33
commit f86bbd0f41
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
4 changed files with 98 additions and 49 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
notify
sms
smsto
factory
factory
dynamic

5
dynamic.txt Normal file
View File

@ -0,0 +1,5 @@
# here you can add many currency pairs you want to check in one run, one pair & target per line
# CurrencyToWatch TargetCurrecyToDisplay Percentage
# BTC USD 5
# ETH USD 3
# (remove this note and remove .txt from the file name ;)

View File

@ -18,39 +18,6 @@
# FUNCTIONS
#=================================================================================================================================
# workout the values based on percentage at which to send/show notice
function setPercentage () {
# get price if not already set
get_Price
# get the price value
local value="${CurrencyPair[${Currency}${Target}]}"
# check that we have a value
if [ "${value}" != "null" ]; then
# new value
COINnewValue="${Currency}${Target} $value"
# check if we have price set before
COINlineNr=$( awk "/${Currency}${Target}/{ print NR; exit }" "$COINvaluePath" )
re='^[0-9]+$'
# Update coin value keeper
if ! [[ $COINlineNr =~ $re ]] ; then
# set the price for the first time and send notice
echo "${COINnewValue}" >> "$COINvaluePath"
else
# set updater
COINupdate=1
# old price found
COINoldValue=$(sed -n "${COINlineNr}p" < "$COINvaluePath")
# get the keys
IFS=$' '
local oldArray=( $COINoldValue )
# set the value
value="${oldArray[1]}"
fi
# set the above below values
setAboveBelowValues "${value}"
fi
}
# run with the advance field options
function runFactory () {
# array of repos
@ -68,22 +35,39 @@ function runFactory () {
for cpairs in "${currencypairs[@]}"; do
# convert line to array
local currencypair=($cpairs)
# check number of values
if [ ${#currencypair[@]} == 4 ]; then
# set globals
Currency="${currencypair[0]}"
Target="${currencypair[1]}"
TargetValue="${currencypair[2]}"
TargetAll=1
if (( "${currencypair[3]}" == 1 )); then
AboveValue=1
# if percentage
if (( "$PercentSwitch" == 1 )); then
# check number of values
if [ ${#currencypair[@]} == 3 ]; then
# set globals
Currency="${currencypair[0]}"
Target="${currencypair[1]}"
Percentage="${currencypair[2]}"
# set percentages
setPercentage
# run the main functions
runMain
else
BelowValue=1
echoTweak "Line missing values, see example dynamic.txt file for details"
fi
# run the main functions
runMain
else
echoTweak "Line missing values, see example factory.txt file for details"
# check number of values
if [ ${#currencypair[@]} == 4 ]; then
# set globals
Currency="${currencypair[0]}"
Target="${currencypair[1]}"
TargetValue="${currencypair[2]}"
TargetAll=1
if (( "${currencypair[3]}" == 1 )); then
AboveValue=1
else
BelowValue=1
fi
# run the main functions
runMain
else
echoTweak "Line missing values, see example factory.txt file for details"
fi
fi
done
# display
@ -138,6 +122,39 @@ function runMain () {
getActiveCurrencyTarget
}
# workout the values based on percentage at which to send/show notice
function setPercentage () {
# get price if not already set
get_Price
# get the price value
local value="${CurrencyPair[${Currency}${Target}]}"
# check that we have a value
if [ "${value}" != "null" ]; then
# new value
COINnewValue="${Currency}${Target} $value"
# check if we have price set before
COINlineNr=$( awk "/${Currency}${Target}/{ print NR; exit }" "$COINvaluePath" )
re='^[0-9]+$'
# Update coin value keeper
if ! [[ $COINlineNr =~ $re ]] ; then
# set the price for the first time and send notice
echo "${COINnewValue}" >> "$COINvaluePath"
else
# set updater
COINupdate=1
# old price found
COINoldValue=$(sed -n "${COINlineNr}p" < "$COINvaluePath")
# get the keys
IFS=$' '
local oldArray=( $COINoldValue )
# set the value
value="${oldArray[1]}"
fi
# set the above below values
setAboveBelowValues "${value}"
fi
}
# get active currency target
function getActiveCurrencyTarget () {
# get price if not already set

View File

@ -79,8 +79,10 @@ Getting Coin Value in Fiat Currency at set price
Advance options (factory option)
======================================================
-f Path to file with multiple currency pair options
-f Path to file with multiple currency pair options (Fixed values)
(see example factory.txt file for details)
-P Path to file with multiple currency pair options (Percentages)
(see example dynamic.txt file for details)
Message options
======================================================
@ -106,7 +108,7 @@ exit 1
# http://mywiki.wooledge.org/BashFAQ/035
# http://wiki.bash-hackers.org/howto/getopts_tutorial
while getopts hc:C:o:v:B:A:baqtT:sS:M:lf:I:kp: opt; do
while getopts hc:C:o:v:B:A:baqtT:sS:M:lf:I:kp:P: opt; do
case $opt in
I)
if (( "$OPTARG" == 2 )); then
@ -133,6 +135,30 @@ while getopts hc:C:o:v:B:A:baqtT:sS:M:lf:I:kp: opt; do
Percentage=$OPTARG
PercentSwitch=1
;;
P)
FilePath=$OPTARG
# make sure we have a file
if [ ! -f "$FilePath" ]
then
echo "File path ($FilePath) does not exist, please add correct path"
show_help >&2
exit 1
fi
Factory=1
# reset all basic settings
Currency="BTC"
Target="USD"
TargetValue=0
TargetBelowValue=0
TargetAboveValue=0
TargetAll=0
TargetBelow=0
TargetAbove=0
BelowValue=0
AboveValue=0
# percentage switch
PercentSwitch=1
;;
v)
TargetValue=$OPTARG
TargetAll=1