mirror of
https://github.com/Llewellynvdm/CoinRate.git
synced 2024-11-28 13:06:28 +00:00
Added two more API options bitfinex.com, gate.io
This commit is contained in:
parent
629c5eb526
commit
b77b427f18
69
functions.sh
69
functions.sh
@ -37,7 +37,7 @@ function runFactory () {
|
|||||||
local currencypair=($cpairs)
|
local currencypair=($cpairs)
|
||||||
# if percentage
|
# if percentage
|
||||||
if (( "$PercentSwitch" == 1 )); then
|
if (( "$PercentSwitch" == 1 )); then
|
||||||
# always rest updater (since it per currency pair
|
# always rest updater (since it per currency pair)
|
||||||
COINupdate=0
|
COINupdate=0
|
||||||
# check number of values
|
# check number of values
|
||||||
if [ ${#currencypair[@]} == 3 ]; then
|
if [ ${#currencypair[@]} == 3 ]; then
|
||||||
@ -48,7 +48,11 @@ function runFactory () {
|
|||||||
# set percentages
|
# set percentages
|
||||||
setPercentage
|
setPercentage
|
||||||
# run the main functions
|
# run the main functions
|
||||||
runMain
|
if (( "$BelowValue" == 0 && "$AboveValue" == 0 )); then
|
||||||
|
echoTweak "${Currency}${Target} returned no value"
|
||||||
|
else
|
||||||
|
runMain
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echoTweak "Line missing values, see example dynamic.txt file for details"
|
echoTweak "Line missing values, see example dynamic.txt file for details"
|
||||||
fi
|
fi
|
||||||
@ -368,7 +372,7 @@ function sendMessages () {
|
|||||||
if [ ${#Messages[@]} -gt 0 ]; then
|
if [ ${#Messages[@]} -gt 0 ]; then
|
||||||
# load the API being targeted
|
# load the API being targeted
|
||||||
if (( "$API_show" == 1 )); then
|
if (( "$API_show" == 1 )); then
|
||||||
Messages+=("(${API_target})")
|
Messages+=("(${API_urlname})")
|
||||||
fi
|
fi
|
||||||
# set to string
|
# set to string
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
@ -491,45 +495,54 @@ function get_Price () {
|
|||||||
if (( "$Factory" == 1 )); then
|
if (( "$Factory" == 1 )); then
|
||||||
echoTweak "Getting the current price of $Currency in $Target"
|
echoTweak "Getting the current price of $Currency in $Target"
|
||||||
fi
|
fi
|
||||||
# get price from API
|
# get URL
|
||||||
if [ "${API_target}" == "cex" ]; then
|
local URL=$(getURL)
|
||||||
local URL="${API_cex}${Currency}/${Target}"
|
|
||||||
elif [ "${API_target}" == "shapeshift" ]; then
|
|
||||||
local URL="${API_shapeshift}${Currency}_${Target}"
|
|
||||||
fi
|
|
||||||
# now get the json
|
# now get the json
|
||||||
local json=$(wget -q -O- "$URL")
|
local json=$(wget -q -O- "${URL}")
|
||||||
|
# set the key
|
||||||
|
local eKey=$"API_error_${API_target}"
|
||||||
|
local evKey=$"API_error_value_${API_target}"
|
||||||
# check if we have and error
|
# check if we have and error
|
||||||
local error=($( echo "$json" | jq -r '.error'))
|
local error=($( echo "$json" | jq -r ".${!eKey}"))
|
||||||
if [ "${error}" != "null" ]; then
|
if [ "${error}" != "${!evKey}" ]; then
|
||||||
if (( "$allowEcho" == 1 )); then
|
if (( "$allowEcho" == 1 )); then
|
||||||
echo "...!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!..."
|
echo "...__________________________________________________________________________________________..."
|
||||||
echoTweak "${json}"
|
echoTweak "${json}"
|
||||||
echo "...!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!..."
|
echo "...__________________________________________________________________________________________..."
|
||||||
fi
|
fi
|
||||||
# no currency pair found
|
# no currency pair found
|
||||||
CurrencyPair["${Currency}${Target}"]='null'
|
CurrencyPair["${Currency}${Target}"]='null'
|
||||||
else
|
else
|
||||||
|
# set the key
|
||||||
|
local vKey=$"API_json_${API_target}"
|
||||||
# set the value
|
# set the value
|
||||||
if [ "${API_target}" == "cex" ]; then
|
local value=($( echo "$json" | jq -r ".${!vKey}"))
|
||||||
local value=($( echo "$json" | jq -r '.lprice'))
|
|
||||||
elif [ "${API_target}" == "shapeshift" ]; then
|
|
||||||
local value=($( echo "$json" | jq -r '.rate'))
|
|
||||||
fi
|
|
||||||
# add value to global bucket
|
# add value to global bucket
|
||||||
CurrencyPair["${Currency}${Target}"]="$value"
|
CurrencyPair["${Currency}${Target}"]="$value"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# get the API url
|
||||||
|
function getURL () {
|
||||||
|
# API switches
|
||||||
|
if [ "${API_target}" == "cex" ]; then
|
||||||
|
# cex
|
||||||
|
echo "${API_cex}${Currency}/${Target}"
|
||||||
|
elif [ "${API_target}" == "shapeshift" ]; then
|
||||||
|
# shapeshift
|
||||||
|
echo "${API_shapeshift}${Currency}_${Target}"
|
||||||
|
elif [ "${API_target}" == "bitfinex" ]; then
|
||||||
|
# bitfinex
|
||||||
|
echo "${API_bitfinex}${Currency}${Target}"
|
||||||
|
elif [ "${API_target}" == "gate" ]; then
|
||||||
|
# gate
|
||||||
|
echo "${API_gate}${Currency}_${Target}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# run some validation against the options given
|
# run some validation against the options given
|
||||||
function runValidation () {
|
function runValidation () {
|
||||||
# check if above or below value is set
|
|
||||||
if (( "$BelowValue" == 0 && "$AboveValue" == 0 )); then
|
|
||||||
echo "Above or Below Switch are required!"
|
|
||||||
show_help
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
# check that value are set
|
# check that value are set
|
||||||
if (( "$BelowValue" == 1 && "$TargetAll" == 0 && "$TargetBelow" == 0)); then
|
if (( "$BelowValue" == 1 && "$TargetAll" == 0 && "$TargetBelow" == 0)); then
|
||||||
echo "A below value is required!"
|
echo "A below value is required!"
|
||||||
@ -548,6 +561,12 @@ function runValidation () {
|
|||||||
show_help
|
show_help
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
# check if above or below value is set
|
||||||
|
if (( "$BelowValue" == 0 && "$AboveValue" == 0 )); then
|
||||||
|
echo "Above or Below Switch are required!"
|
||||||
|
show_help
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# little echo tweak
|
# little echo tweak
|
||||||
|
11
getPrice.sh
11
getPrice.sh
@ -52,7 +52,9 @@ Getting Coin Value in Fiat Currency at set price
|
|||||||
-I Select the api to query
|
-I Select the api to query
|
||||||
Options:
|
Options:
|
||||||
1 = [cex] cex.io - (default)
|
1 = [cex] cex.io - (default)
|
||||||
2 = [shapeshift]
|
2 = [shapeshift] shapeshift.io
|
||||||
|
3 = [bitfinex] bitfinex.com
|
||||||
|
4 = [gate] gate.io
|
||||||
-x Hide API name from message
|
-x Hide API name from message
|
||||||
|
|
||||||
Basic options
|
Basic options
|
||||||
@ -113,6 +115,13 @@ while getopts hc:C:o:v:B:A:baqtT:sS:M:lf:I:kp:P: opt; do
|
|||||||
I)
|
I)
|
||||||
if (( "$OPTARG" == 2 )); then
|
if (( "$OPTARG" == 2 )); then
|
||||||
API_target="shapeshift"
|
API_target="shapeshift"
|
||||||
|
API_urlname="shapeshift.io"
|
||||||
|
elif (( "$OPTARG" == 3 )); then
|
||||||
|
API_target="bitfinex"
|
||||||
|
API_urlname="bitfinex.com"
|
||||||
|
elif (( "$OPTARG" == 4 )); then
|
||||||
|
API_target="gate"
|
||||||
|
API_urlname="gate.io"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
x)
|
x)
|
||||||
|
24
main.sh
24
main.sh
@ -68,11 +68,33 @@ SMS=0
|
|||||||
smsID=1
|
smsID=1
|
||||||
smstoID=1
|
smstoID=1
|
||||||
|
|
||||||
# API URL
|
# API Details
|
||||||
API_show=1
|
API_show=1
|
||||||
|
# defaults
|
||||||
API_target="cex"
|
API_target="cex"
|
||||||
|
API_urlname="cex.io"
|
||||||
|
# cex
|
||||||
API_cex="https://cex.io/api/last_price/" # (default)
|
API_cex="https://cex.io/api/last_price/" # (default)
|
||||||
|
API_json_cex="lprice"
|
||||||
|
API_error_cex="error"
|
||||||
|
API_error_value_cex="null"
|
||||||
|
# shapeshift
|
||||||
API_shapeshift="https://shapeshift.io/rate/"
|
API_shapeshift="https://shapeshift.io/rate/"
|
||||||
|
API_json_shapeshift="rate"
|
||||||
|
API_error_shapeshift="error"
|
||||||
|
API_error_value_shapeshift="null"
|
||||||
|
# bitfinex
|
||||||
|
API_bitfinex="https://api.bitfinex.com/v1/pubticker/"
|
||||||
|
API_json_bitfinex="last_price"
|
||||||
|
API_error_bitfinex="message"
|
||||||
|
API_error_value_bitfinex="null"
|
||||||
|
# gate
|
||||||
|
API_gate="https://data.gate.io/api2/1/ticker/"
|
||||||
|
API_json_gate="last"
|
||||||
|
API_error_gate="message"
|
||||||
|
API_error_value_gate="null"
|
||||||
|
|
||||||
|
# file path to config
|
||||||
FilePath=''
|
FilePath=''
|
||||||
|
|
||||||
# percentage values
|
# percentage values
|
||||||
|
Loading…
Reference in New Issue
Block a user