mirror of
https://github.com/Llewellynvdm/CoinRate.git
synced 2024-11-21 18:45:10 +00:00
Added dynamic percentage watcher options
This commit is contained in:
parent
7ead918d33
commit
f86bbd0f41
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ notify
|
|||||||
sms
|
sms
|
||||||
smsto
|
smsto
|
||||||
factory
|
factory
|
||||||
|
dynamic
|
5
dynamic.txt
Normal file
5
dynamic.txt
Normal 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 ;)
|
109
functions.sh
109
functions.sh
@ -18,39 +18,6 @@
|
|||||||
# FUNCTIONS
|
# 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
|
# run with the advance field options
|
||||||
function runFactory () {
|
function runFactory () {
|
||||||
# array of repos
|
# array of repos
|
||||||
@ -68,22 +35,39 @@ function runFactory () {
|
|||||||
for cpairs in "${currencypairs[@]}"; do
|
for cpairs in "${currencypairs[@]}"; do
|
||||||
# convert line to array
|
# convert line to array
|
||||||
local currencypair=($cpairs)
|
local currencypair=($cpairs)
|
||||||
# check number of values
|
# if percentage
|
||||||
if [ ${#currencypair[@]} == 4 ]; then
|
if (( "$PercentSwitch" == 1 )); then
|
||||||
# set globals
|
# check number of values
|
||||||
Currency="${currencypair[0]}"
|
if [ ${#currencypair[@]} == 3 ]; then
|
||||||
Target="${currencypair[1]}"
|
# set globals
|
||||||
TargetValue="${currencypair[2]}"
|
Currency="${currencypair[0]}"
|
||||||
TargetAll=1
|
Target="${currencypair[1]}"
|
||||||
if (( "${currencypair[3]}" == 1 )); then
|
Percentage="${currencypair[2]}"
|
||||||
AboveValue=1
|
# set percentages
|
||||||
|
setPercentage
|
||||||
|
# run the main functions
|
||||||
|
runMain
|
||||||
else
|
else
|
||||||
BelowValue=1
|
echoTweak "Line missing values, see example dynamic.txt file for details"
|
||||||
fi
|
fi
|
||||||
# run the main functions
|
|
||||||
runMain
|
|
||||||
else
|
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
|
fi
|
||||||
done
|
done
|
||||||
# display
|
# display
|
||||||
@ -138,6 +122,39 @@ function runMain () {
|
|||||||
getActiveCurrencyTarget
|
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
|
# get active currency target
|
||||||
function getActiveCurrencyTarget () {
|
function getActiveCurrencyTarget () {
|
||||||
# get price if not already set
|
# get price if not already set
|
||||||
|
30
getPrice.sh
30
getPrice.sh
@ -79,8 +79,10 @@ Getting Coin Value in Fiat Currency at set price
|
|||||||
|
|
||||||
Advance options (factory option)
|
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)
|
(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
|
Message options
|
||||||
======================================================
|
======================================================
|
||||||
@ -106,7 +108,7 @@ exit 1
|
|||||||
# http://mywiki.wooledge.org/BashFAQ/035
|
# http://mywiki.wooledge.org/BashFAQ/035
|
||||||
# http://wiki.bash-hackers.org/howto/getopts_tutorial
|
# 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
|
case $opt in
|
||||||
I)
|
I)
|
||||||
if (( "$OPTARG" == 2 )); then
|
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
|
Percentage=$OPTARG
|
||||||
PercentSwitch=1
|
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)
|
v)
|
||||||
TargetValue=$OPTARG
|
TargetValue=$OPTARG
|
||||||
TargetAll=1
|
TargetAll=1
|
||||||
|
Loading…
Reference in New Issue
Block a user