Added two more API options bitfinex.com, gate.io

This commit is contained in:
Llewellyn van der Merwe 2018-01-02 22:02:45 +02:00
parent 629c5eb526
commit b77b427f18
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
3 changed files with 77 additions and 27 deletions

View File

@ -37,7 +37,7 @@ function runFactory () {
local currencypair=($cpairs)
# if percentage
if (( "$PercentSwitch" == 1 )); then
# always rest updater (since it per currency pair
# always rest updater (since it per currency pair)
COINupdate=0
# check number of values
if [ ${#currencypair[@]} == 3 ]; then
@ -48,7 +48,11 @@ function runFactory () {
# set percentages
setPercentage
# run the main functions
runMain
if (( "$BelowValue" == 0 && "$AboveValue" == 0 )); then
echoTweak "${Currency}${Target} returned no value"
else
runMain
fi
else
echoTweak "Line missing values, see example dynamic.txt file for details"
fi
@ -368,7 +372,7 @@ function sendMessages () {
if [ ${#Messages[@]} -gt 0 ]; then
# load the API being targeted
if (( "$API_show" == 1 )); then
Messages+=("(${API_target})")
Messages+=("(${API_urlname})")
fi
# set to string
IFS=$'\n'
@ -491,45 +495,54 @@ function get_Price () {
if (( "$Factory" == 1 )); then
echoTweak "Getting the current price of $Currency in $Target"
fi
# get price from API
if [ "${API_target}" == "cex" ]; then
local URL="${API_cex}${Currency}/${Target}"
elif [ "${API_target}" == "shapeshift" ]; then
local URL="${API_shapeshift}${Currency}_${Target}"
fi
# get URL
local URL=$(getURL)
# 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
local error=($( echo "$json" | jq -r '.error'))
if [ "${error}" != "null" ]; then
local error=($( echo "$json" | jq -r ".${!eKey}"))
if [ "${error}" != "${!evKey}" ]; then
if (( "$allowEcho" == 1 )); then
echo "...!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!..."
echo "...__________________________________________________________________________________________..."
echoTweak "${json}"
echo "...!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!..."
echo "...__________________________________________________________________________________________..."
fi
# no currency pair found
CurrencyPair["${Currency}${Target}"]='null'
else
# set the key
local vKey=$"API_json_${API_target}"
# set the value
if [ "${API_target}" == "cex" ]; then
local value=($( echo "$json" | jq -r '.lprice'))
elif [ "${API_target}" == "shapeshift" ]; then
local value=($( echo "$json" | jq -r '.rate'))
fi
local value=($( echo "$json" | jq -r ".${!vKey}"))
# add value to global bucket
CurrencyPair["${Currency}${Target}"]="$value"
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
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
if (( "$BelowValue" == 1 && "$TargetAll" == 0 && "$TargetBelow" == 0)); then
echo "A below value is required!"
@ -548,6 +561,12 @@ function runValidation () {
show_help
exit 1
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

View File

@ -52,7 +52,9 @@ Getting Coin Value in Fiat Currency at set price
-I Select the api to query
Options:
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
Basic options
@ -113,6 +115,13 @@ while getopts hc:C:o:v:B:A:baqtT:sS:M:lf:I:kp:P: opt; do
I)
if (( "$OPTARG" == 2 )); then
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
;;
x)

24
main.sh
View File

@ -68,11 +68,33 @@ SMS=0
smsID=1
smstoID=1
# API URL
# API Details
API_show=1
# defaults
API_target="cex"
API_urlname="cex.io"
# cex
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_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=''
# percentage values