mirror of
https://github.com/Llewellynvdm/CoinRate.git
synced 2024-11-21 18:45:10 +00:00
added shapeshift API option, added readme with some basic instructions
This commit is contained in:
parent
dc971e9c00
commit
a426405ae6
158
README.md
Normal file
158
README.md
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
# Coin Rate Watcher
|
||||||
|
The Bash script gets current values for cryptocurrencies from a variety of Exchange APIs, and then calculates if various notifications should be send based on above or below price margins. All dynamically set by command options or file, you can now stay informed of any changes in the market with this coin rate watching script.
|
||||||
|
|
||||||
|
## The Get Method (getPrice.sh)
|
||||||
|
|
||||||
|
..... more info soon
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* hmmm many
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
First, clone the repository using git:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$git clone https://github.com/vdm-io/CoinRate.git
|
||||||
|
```
|
||||||
|
|
||||||
|
Then give the execution permission to this file:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$chmod +x getPrice.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Set your sms details (if required):
|
||||||
|
|
||||||
|
Read [sms.txt](https://github.com/vdm-io/CoinRate/blob/master/sms.txt) for more details.
|
||||||
|
|
||||||
|
Set your Telegram details (if required):
|
||||||
|
|
||||||
|
Read [notify.txt](https://github.com/vdm-io/CoinRate/blob/master/notify.txt) for more details.
|
||||||
|
|
||||||
|
Set your Factory details (if you want to do build checks):
|
||||||
|
|
||||||
|
Read [factory.txt](https://github.com/vdm-io/CoinRate/blob/master/factory.txt) for more details.
|
||||||
|
|
||||||
|
## Usage GET
|
||||||
|
|
||||||
|
The syntax is quite simple:
|
||||||
|
|
||||||
|
```
|
||||||
|
$./getPrice.sh <PARAMETERS>
|
||||||
|
|
||||||
|
<%%>: Required param
|
||||||
|
```
|
||||||
|
|
||||||
|
**Parameters:**
|
||||||
|
```text
|
||||||
|
API options
|
||||||
|
======================================================
|
||||||
|
-I Select the api to query
|
||||||
|
Options:
|
||||||
|
1 = [cex] cex.io - (default)
|
||||||
|
2 = [shapeshift]
|
||||||
|
-x Hide API name from message
|
||||||
|
|
||||||
|
Basic options
|
||||||
|
======================================================
|
||||||
|
-c Currency to watch (c:_)
|
||||||
|
example: BTC
|
||||||
|
-C Target Currecy to Display (_:t)
|
||||||
|
example: USD
|
||||||
|
-o How often should the message be send/shown
|
||||||
|
0 = once per/day
|
||||||
|
1 = once per/hour
|
||||||
|
2 = everyTime (default)
|
||||||
|
3 = only once
|
||||||
|
-v Value (above or below) at which to send/send notice
|
||||||
|
example: 17000 or 14000,15000
|
||||||
|
-A Value Above at which to send notice
|
||||||
|
example: 17000 or 19000,18000
|
||||||
|
-B Value Below at which to send notice
|
||||||
|
example: 14000 or 14000,15000
|
||||||
|
-b Send Notice below target value once a day
|
||||||
|
-a Send Notice above target value once a day (default)
|
||||||
|
|
||||||
|
Advance options (factory option)
|
||||||
|
======================================================
|
||||||
|
-f Path to file with multiple currency pair options
|
||||||
|
(see example factory.txt file for details)
|
||||||
|
|
||||||
|
Message options
|
||||||
|
======================================================
|
||||||
|
-q Quiet - Turn off terninal output
|
||||||
|
-t Send A Telegram Notice
|
||||||
|
-s Send A SMS Notice
|
||||||
|
-l Show A Linux Notice via zenity
|
||||||
|
|
||||||
|
-h display this help menu
|
||||||
|
|
||||||
|
======================================================
|
||||||
|
Vast Development Method (vdm.io)
|
||||||
|
======================================================
|
||||||
|
```
|
||||||
|
|
||||||
|
**Examples (CEX API):**
|
||||||
|
```bash
|
||||||
|
# Get Linux & SMS & Telegram notice when BTC is above 10000 USD (every time command is run)
|
||||||
|
./getPrice.sh -c BTC -C USD -av 10000 -lst
|
||||||
|
|
||||||
|
# Get Telegram notice when BTC is [above 15000,16000,17000 USD] & [below 14000,13000,12000 USD] (every hour - if run in crontab)
|
||||||
|
./getPrice.sh -c BTC -C USD -aA 15000,16000,17000 -bB 14000,13000,12000 -to 1
|
||||||
|
|
||||||
|
# Get SMS notice when XRP is [above 2.50,2.60,3 USD] & [below 2.50,2.40,2.30 USD] (only once - if run in crontab)
|
||||||
|
./getPrice.sh -c XRP -C USD -aA 2.50,2.60,3 -bB 2.50,2.40,2.30 -so 3
|
||||||
|
|
||||||
|
# Get Telegram notice when any curracy pair in file meets criteria (once a day - if run in crontab)
|
||||||
|
./getPrice.sh -f /home/coin/factory -to 0
|
||||||
|
```
|
||||||
|
|
||||||
|
**To use shapeshift API ad the `-I 2` command:***
|
||||||
|
```bash
|
||||||
|
# Get Linux & SMS & Telegram notice when BTC is above 10000 USD (every time command is run)
|
||||||
|
./getPrice.sh -c BTC -C USD -av 10000 -lst -I 2
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tested Environments
|
||||||
|
|
||||||
|
* GNU Linux
|
||||||
|
|
||||||
|
If you have successfully tested this script on others systems or platforms please let me know!
|
||||||
|
|
||||||
|
## Running as cron job (ubuntu)
|
||||||
|
|
||||||
|
First, open crontab:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$crontab -e
|
||||||
|
```
|
||||||
|
|
||||||
|
Add the following line at bottom of the file (adapting to your script location!!!):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
* * * * * /home/bitnami/coin/getPrice.sh -f /home/bitnami/coin/factory -to 1 -I 2 >> /home/bitnami/coin/coin.log
|
||||||
|
```
|
||||||
|
or
|
||||||
|
```bash
|
||||||
|
* * * * * /home/bitnami/coin/getPrice.sh -c BTC -C USD -aA 15000,16000,17000 -bB 14000,13000,12000 -to 1 -q
|
||||||
|
* * * * * /home/bitnami/coin/getPrice.sh -c XRP -C USD -aA 2.50,2.60,3 -bB 2.50,2.40,2.30 -so 3 -q -I 2
|
||||||
|
```
|
||||||
|
|
||||||
|
## BASH, JQ, curl and bc installation
|
||||||
|
|
||||||
|
**Debian & Ubuntu Linux:**
|
||||||
|
```bash
|
||||||
|
$sudo apt-get install bash (Probably BASH is already installed on your system)
|
||||||
|
$sudo apt-get install bc (Probably bc is already installed on your system)
|
||||||
|
$sudo apt-get install curl
|
||||||
|
$sudo apt-get install jq
|
||||||
|
```
|
||||||
|
|
||||||
|
## Donations
|
||||||
|
|
||||||
|
Come on buy me a coffee :)
|
||||||
|
* PayPal: [paypal.me/payvdm](https://www.paypal.me/payvdm)
|
||||||
|
* Bitcoin: 18vURxYpPFjvNk8BnUy1ovCAyQmY3MzkSf
|
||||||
|
* Ethereum: 0x9548144662b47327c954f3e214edb96662d51218
|
28
functions.sh
28
functions.sh
@ -28,7 +28,7 @@ function runFactory () {
|
|||||||
if (( "$allowEcho" == 1 )); then
|
if (( "$allowEcho" == 1 )); then
|
||||||
echo ".................................[ Vast Development Method ]...................................."
|
echo ".................................[ Vast Development Method ]...................................."
|
||||||
echo "...========================================================================| www.vdm.io |====..."
|
echo "...========================================================================| www.vdm.io |====..."
|
||||||
echoTweak "Getting all the prices from CEX.io"
|
echoTweak "Getting all the prices from ${API_target}"
|
||||||
echo "...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~..."
|
echo "...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~..."
|
||||||
fi
|
fi
|
||||||
# now start parsing the values
|
# now start parsing the values
|
||||||
@ -269,6 +269,10 @@ function sendMessages () {
|
|||||||
filterMessages
|
filterMessages
|
||||||
# check if we have messages
|
# check if we have messages
|
||||||
if [ ${#Messages[@]} -gt 0 ]; then
|
if [ ${#Messages[@]} -gt 0 ]; then
|
||||||
|
# load the API being targeted
|
||||||
|
if (( "$API_show" == 1 )); then
|
||||||
|
Messages+=("(${API_target})")
|
||||||
|
fi
|
||||||
# set to string
|
# set to string
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
local messages="${Messages[*]}"
|
local messages="${Messages[*]}"
|
||||||
@ -353,13 +357,13 @@ function sendTime () {
|
|||||||
then
|
then
|
||||||
# send every time
|
# send every time
|
||||||
send=1
|
send=1
|
||||||
elif grep -Fxq "$keySendTime" "$VDMHOME/.cointracker"
|
elif grep -Fxq "$keySendTime" "$COINTracker"
|
||||||
then
|
then
|
||||||
# Do not send notification (already send in time frame)
|
# Do not send notification (already send in time frame)
|
||||||
send=0
|
send=0
|
||||||
else
|
else
|
||||||
# add key to file
|
# add key to file
|
||||||
echo "$keySendTime" >> "$VDMHOME/.cointracker"
|
echo "$keySendTime" >> "$COINTracker"
|
||||||
# send notification if asked to
|
# send notification if asked to
|
||||||
send=1
|
send=1
|
||||||
fi
|
fi
|
||||||
@ -391,11 +395,25 @@ function get_Price () {
|
|||||||
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 price from API
|
||||||
local URL="${API}${Currency}/${Target}"
|
if [ "${API_target}" == "cex" ]; then
|
||||||
|
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")
|
||||||
|
# check if we have and error
|
||||||
|
local error=($( echo "$json" | jq -r '.error'))
|
||||||
|
if [ "${error}" != "null" ]; then
|
||||||
|
echo "Currency Pair: $error"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
# set the value
|
# set the value
|
||||||
local value=($( echo "$json" | jq -r '.lprice'))
|
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
|
||||||
# add value to global bucket
|
# add value to global bucket
|
||||||
CurrencyPair["${Currency}${Target}"]="$value"
|
CurrencyPair["${Currency}${Target}"]="$value"
|
||||||
fi
|
fi
|
||||||
|
44
getPrice.sh
44
getPrice.sh
@ -43,23 +43,31 @@ cat << EOF
|
|||||||
Usage: ${0##*/:-} [OPTION...]
|
Usage: ${0##*/:-} [OPTION...]
|
||||||
Getting Coin Value in Fiat Currency at set price
|
Getting Coin Value in Fiat Currency at set price
|
||||||
|
|
||||||
|
API options
|
||||||
|
======================================================
|
||||||
|
-I Select the api to query
|
||||||
|
Options:
|
||||||
|
1 = [cex] cex.io - (default)
|
||||||
|
2 = [shapeshift]
|
||||||
|
-x Hide API name from message
|
||||||
|
|
||||||
Basic options
|
Basic options
|
||||||
======================================================
|
======================================================
|
||||||
-c Currency to watch (c:_)
|
-c Currency to watch (c:_)
|
||||||
example: BTC
|
example: BTC
|
||||||
-C Target Currecy to Display (_:t)
|
-C Target Currecy to Display (_:t)
|
||||||
example: USD
|
example: USD
|
||||||
-o How often should the message be send/shown
|
-o How often should the message be send/shown
|
||||||
0 = once per/day (default)
|
0 = once per/day
|
||||||
1 = once per/hour
|
1 = once per/hour
|
||||||
2 = everyTime
|
2 = everyTime (default)
|
||||||
3 = only once
|
3 = only once
|
||||||
-v Value (above or below) at which to send/send notice
|
-v Value (above or below) at which to send/send notice
|
||||||
example: 17000 or 14000,15000
|
example: 17000 or 14000,15000
|
||||||
-A Value Above at which to send notice
|
-A Value Above at which to send notice
|
||||||
example: 17000 or 19000,18000
|
example: 17000 or 19000,18000
|
||||||
-B Value Below at which to send notice
|
-B Value Below at which to send notice
|
||||||
example: 14000 or 14000,15000
|
example: 14000 or 14000,15000
|
||||||
-b Send Notice below target value once a day
|
-b Send Notice below target value once a day
|
||||||
-a Send Notice above target value once a day (default)
|
-a Send Notice above target value once a day (default)
|
||||||
|
|
||||||
@ -89,8 +97,16 @@ 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:baqtslf: opt; do
|
while getopts hc:C:o:v:B:A:baqtslf:I: opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
|
I)
|
||||||
|
if (( "$OPTARG" == 2 )); then
|
||||||
|
API_target="shapeshift"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
x)
|
||||||
|
API_show=0
|
||||||
|
;;
|
||||||
h)
|
h)
|
||||||
show_help >&2
|
show_help >&2
|
||||||
exit 1
|
exit 1
|
||||||
@ -169,5 +185,13 @@ while getopts hc:C:o:v:B:A:baqtslf: opt; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# BUILD Cointracker file per/API
|
||||||
|
COINTracker="${VDMHOME}/.cointracker_${API_target}"
|
||||||
|
# make sure the tracker file is set
|
||||||
|
if [ ! -f "$COINTracker" ]
|
||||||
|
then
|
||||||
|
> "$COINTracker"
|
||||||
|
fi
|
||||||
|
|
||||||
# Run the script
|
# Run the script
|
||||||
main
|
main
|
||||||
|
11
main.sh
11
main.sh
@ -57,7 +57,10 @@ LinuxNotice=0
|
|||||||
SMS=0
|
SMS=0
|
||||||
|
|
||||||
# API URL
|
# API URL
|
||||||
API="https://cex.io/api/last_price/"
|
API_show=1
|
||||||
|
API_target="cex"
|
||||||
|
API_cex="https://cex.io/api/last_price/" # (default)
|
||||||
|
API_shapeshift="https://shapeshift.io/rate/"
|
||||||
FilePath=''
|
FilePath=''
|
||||||
|
|
||||||
# Some Messages arrays
|
# Some Messages arrays
|
||||||
@ -70,9 +73,3 @@ Messages=()
|
|||||||
|
|
||||||
# use UTC+00:00 time also called zulu
|
# use UTC+00:00 time also called zulu
|
||||||
Datetimenow=$(TZ=":ZULU" date +"%m/%d/%Y @ %R (UTC)" )
|
Datetimenow=$(TZ=":ZULU" date +"%m/%d/%Y @ %R (UTC)" )
|
||||||
|
|
||||||
# make sure the tracker file is set
|
|
||||||
if [ ! -f "$VDMHOME/.cointracker" ]
|
|
||||||
then
|
|
||||||
> "$VDMHOME/.cointracker"
|
|
||||||
fi
|
|
||||||
|
Loading…
Reference in New Issue
Block a user