Update
This commit is contained in:
55
README.md
55
README.md
@@ -6,13 +6,11 @@
|
|||||||
|
|
||||||
Based from [ticker.sh](https://github.com/pstadler/ticker.sh)
|
Based from [ticker.sh](https://github.com/pstadler/ticker.sh)
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
@@ -22,11 +20,41 @@ $ curl -o ticker.sh https://raw.githubusercontent.com/pstadler/ticker.sh/master/
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- [jq](https://stedolan.github.io/jq/), a versatile command-line JSON processor.
|
- [jq](https://stedolan.github.io/jq/), a versatile command-line JSON processor.
|
||||||
- [yq](https://github.com/kislyuk/yq), a versatile command-line YAML processor (Python version).
|
- [yq](https://github.com/mikefarah/yq/), a versatile command-line YAML processor.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
#### Preferences:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Preference file:
|
||||||
|
$ nano ~/.stocks.yaml
|
||||||
|
|
||||||
|
watchlist:
|
||||||
|
- ^FCHI
|
||||||
|
- AC.PA
|
||||||
|
- ALCLS.PA
|
||||||
|
- ATO.PA
|
||||||
|
- AUB.PA
|
||||||
|
- CS.PA
|
||||||
|
- DG.PA
|
||||||
|
- ORA.PA
|
||||||
|
- VIRP.PA
|
||||||
|
- WLN.PA
|
||||||
|
lots:
|
||||||
|
- symbol: "AUB.PA"
|
||||||
|
quantity: 600
|
||||||
|
unit_cost: 32.164
|
||||||
|
- symbol: "ORA.PA"
|
||||||
|
quantity: 700
|
||||||
|
unit_cost: 9.426
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Running:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Single symbol:
|
# Single symbol:
|
||||||
$ ./ticker.sh AAPL
|
$ ./ticker.sh AAPL
|
||||||
@@ -34,23 +62,16 @@ $ ./ticker.sh AAPL
|
|||||||
# Multiple symbols:
|
# Multiple symbols:
|
||||||
$ ./ticker.sh AAPL MSFT GOOG BTC-USD
|
$ ./ticker.sh AAPL MSFT GOOG BTC-USD
|
||||||
|
|
||||||
# Read from file:
|
# Run stocks.sh:
|
||||||
$ echo "AAPL MSFT GOOG BTC-USD" > ~/.ticker.conf
|
$ ./stocks.sh
|
||||||
$ ./ticker.sh $(cat ~/.ticker.conf)
|
|
||||||
|
|
||||||
# Use different colors:
|
|
||||||
$ COLOR_BOLD="\e[38;5;248m" \
|
|
||||||
COLOR_GREEN="\e[38;5;154m" \
|
|
||||||
COLOR_RED="\e[38;5;202m" \
|
|
||||||
./ticker.sh AAPL
|
|
||||||
|
|
||||||
# Disable colors:
|
|
||||||
$ NO_COLOR=1 ./ticker.sh AAPL
|
|
||||||
|
|
||||||
# Update every five seconds:
|
# Update every five seconds:
|
||||||
$ watch -n 5 -t -c ./ticker.sh AAPL MSFT GOOG BTC-USD
|
$ watch -n 5 -t -c ./ticker.sh AAPL MSFT GOOG BTC-USD
|
||||||
# Or if `watch` is not available:
|
# Or if `watch` is not available:
|
||||||
$ while true; do clear; ./ticker.sh AAPL MSFT GOOG BTC-USD; sleep 5; done
|
$ while true; do clear; ./ticker.sh; sleep 5; done
|
||||||
|
# Or
|
||||||
|
./run_stocks.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
refresh="60"
|
refresh="600"
|
||||||
|
|
||||||
|
sleep-with-countdown() {
|
||||||
|
secs=$1
|
||||||
|
while [ $secs -gt 0 ]; do
|
||||||
|
printf "\rProchaine dans $secs\033[0K s"
|
||||||
|
sleep 1
|
||||||
|
: $((secs--))
|
||||||
|
done
|
||||||
|
printf "\n"
|
||||||
|
}
|
||||||
|
# sleep-with-countdown $refresh;
|
||||||
|
|
||||||
|
#while true; do clear; ./stocks.sh $(cat ~/.ticker.conf); sleep $refresh; done
|
||||||
|
while true; do clear; ./stocks.sh; sleep $refresh; done
|
||||||
|
|
||||||
while true; do clear; ./stocks.sh $(cat ~/.ticker.conf); sleep $refresh; done
|
|
||||||
|
|||||||
116
stocks.sh
116
stocks.sh
@@ -14,6 +14,8 @@ reset="\033[0m"
|
|||||||
LANG=C
|
LANG=C
|
||||||
LC_NUMERIC=C
|
LC_NUMERIC=C
|
||||||
|
|
||||||
|
stocks_list=~/.stocks.yaml
|
||||||
|
|
||||||
query() {
|
query() {
|
||||||
echo "$obj" | jq -r ".$1"
|
echo "$obj" | jq -r ".$1"
|
||||||
}
|
}
|
||||||
@@ -24,30 +26,36 @@ round() {
|
|||||||
|
|
||||||
# Test if jq & yq executables are in $PATH
|
# Test if jq & yq executables are in $PATH
|
||||||
|
|
||||||
if ! $(type jq > /dev/null 2>&1); then
|
if ! $(type jq >/dev/null 2>&1); then
|
||||||
echo "'jq' is not in the PATH. (See: https://stedolan.github.io/jq/)"
|
echo "'jq' is not in the PATH. (See: https://stedolan.github.io/jq/)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! $(type yq > /dev/null 2>&1); then
|
if ! $(type yq >/dev/null 2>&1); then
|
||||||
echo "'yq' is not in the PATH. (See: https://github.com/kislyuk/yq"
|
echo "'yq' is not in the PATH. (See: https://github.com/kislyuk/yq"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Read stocks from .stocks.yaml config file
|
# Read stocks from .stocks.yaml config file
|
||||||
|
|
||||||
a=$(cat ~/.stocks.yaml | yq .watchlist)
|
if [ -f $stocks_list ]; then
|
||||||
b=$(cat ~/.stocks.yaml | yq .lots)
|
#a=$(cat ~/.stocks.yaml | yq '.watchlist')
|
||||||
|
a=$(cat $stocks_list | yq '.watchlist')
|
||||||
|
b=$(cat $stocks_list | yq '.lots')
|
||||||
|
else
|
||||||
|
echo "$stocks_list not present !"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
while IFS= read -r obj; do
|
while IFS= read -r obj; do
|
||||||
stock=$(echo "$obj" | jq -r)
|
stock=${obj:2}
|
||||||
list+="$stock,"
|
list+="$stock,"
|
||||||
done < <(echo "$a" | jq -c '.[]')
|
done < <(echo "$a")
|
||||||
|
|
||||||
symbols=$(echo "$list" | sed 's/.$//')
|
symbols=$(echo "$list" | sed 's/.$//')
|
||||||
#echo "$symbols"
|
|
||||||
|
|
||||||
# AC.PA ATO.PA AUB.PA CS.PA DG.PA ^FCHI VIRP.PA WLN.PA
|
# AC.PA ATO.PA AUB.PA CS.PA DG.PA ^FCHI VIRP.PA WLN.PA
|
||||||
|
|
||||||
#####
|
#####
|
||||||
|
|
||||||
if [ -z "$symbols" ]; then
|
if [ -z "$symbols" ]; then
|
||||||
@@ -61,7 +69,6 @@ fi
|
|||||||
API_ENDPOINT="https://query1.finance.yahoo.com/v7/finance/quote?lang=fr-FR®ion=FR&corsDomain=finance.yahoo.com"
|
API_ENDPOINT="https://query1.finance.yahoo.com/v7/finance/quote?lang=fr-FR®ion=FR&corsDomain=finance.yahoo.com"
|
||||||
|
|
||||||
results=$(curl --silent "$API_ENDPOINT&fields=$fields&symbols=$symbols" | jq '.quoteResponse .result')
|
results=$(curl --silent "$API_ENDPOINT&fields=$fields&symbols=$symbols" | jq '.quoteResponse .result')
|
||||||
#echo "$results"
|
|
||||||
|
|
||||||
# Display stocks data
|
# Display stocks data
|
||||||
|
|
||||||
@@ -72,57 +79,60 @@ echo -e "${bold}stocks.sh${reset}\n"
|
|||||||
while IFS= read -r obj; do
|
while IFS= read -r obj; do
|
||||||
marketState=$(query 'marketState')
|
marketState=$(query 'marketState')
|
||||||
symbol=$(query 'symbol')
|
symbol=$(query 'symbol')
|
||||||
|
|
||||||
preMarketChange=$(query 'preMarketChange')
|
preMarketChange=$(query 'preMarketChange')
|
||||||
postMarketChange=$(query 'postMarketChange')
|
postMarketChange=$(query 'postMarketChange')
|
||||||
|
|
||||||
longName=$(query 'longName')
|
longName=$(query 'longName')
|
||||||
if [ "$longName" == "null" ] && [ $symbol == "^FCHI" ]; then
|
if [ "$longName" == "null" ] && [ $symbol == "^FCHI" ]; then
|
||||||
longName="CAC 40"
|
longName="CAC 40"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $t == "0" ]; then
|
if [ $t == "0" ]; then
|
||||||
printf "${bold}%-10s | %-23s | %-7s | " "Symbole" "Entreprise" "Cours"
|
printf "${bold}%-10s | %-21s | %-7s | " "Symbole" "Entreprise" "Cours"
|
||||||
printf "%-6s | %-7s | %-7s | " "Diff" "%" "Veille"
|
printf "%-6s | %-7s | %-7s | " "Diff" "%" "Veille"
|
||||||
printf "%-7s | %-7s | %-8s | " "+ Haut" "+ Bas" "Volume"
|
printf "%-7s | %-7s | %-8s | " "+ Haut" "+ Bas" "Volume"
|
||||||
printf "%-9s | %-25s | %-18s | " "Ouverture" "Heure" "52 semaines"
|
printf "%-9s | %-25s | %-18s | " "Ouverture" "Heure" "52 semaines"
|
||||||
printf "%-7s | %-9s | %-9s | %-6s${reset}\n" "Qté" "Valoris." "+/- value" "Perf."
|
printf "%-7s | %-9s | %-9s | %-6s${reset}\n" "Qté" "Valoris." "+/- value" "Perf."
|
||||||
fi
|
fi
|
||||||
t=1
|
t=1
|
||||||
|
|
||||||
if [ $marketState == "PRE" ] && [ $preMarketChange != "0" ] && [ $preMarketChange != "null" ]; then
|
if [ $marketState == "PRE" ] && [ $preMarketChange != "0" ] && [ $preMarketChange != "null" ]; then
|
||||||
nonRegularMarketSign='*'
|
nonRegularMarketSign='*'
|
||||||
price=$(query 'preMarketPrice')
|
price=$(query 'preMarketPrice')
|
||||||
diff=$preMarketChange
|
diff=$preMarketChange
|
||||||
percent=$(query 'preMarketChangePercent')
|
percent=$(query 'preMarketChangePercent')
|
||||||
elif [ $marketState != "REGULAR" ] && [ $postMarketChange != "0" ] && [ $postMarketChange != "null" ]; then
|
elif [ $marketState != "REGULAR" ] && [ $postMarketChange != "0" ] && [ $postMarketChange != "null" ]; then
|
||||||
nonRegularMarketSign='*'
|
nonRegularMarketSign='*'
|
||||||
price=$(query 'postMarketPrice')
|
price=$(query 'postMarketPrice')
|
||||||
diff=$postMarketChange
|
diff=$postMarketChange
|
||||||
percent=$(query 'postMarketChangePercent')
|
percent=$(query 'postMarketChangePercent')
|
||||||
else
|
else
|
||||||
nonRegularMarketSign=''
|
nonRegularMarketSign=''
|
||||||
price=$(query 'regularMarketPrice')
|
price=$(query 'regularMarketPrice')
|
||||||
diff=$(query 'regularMarketChange')
|
diff=$(query 'regularMarketChange')
|
||||||
percent=$(query 'regularMarketChangePercent')
|
percent=$(query 'regularMarketChangePercent')
|
||||||
previous=$(query 'regularMarketPreviousClose')
|
previous=$(query 'regularMarketPreviousClose')
|
||||||
volume=$(query 'regularMarketVolume')
|
volume=$(query 'regularMarketVolume')
|
||||||
haut=$(query 'regularMarketDayHigh')
|
haut=$(query 'regularMarketDayHigh')
|
||||||
bas=$(query 'regularMarketDayLow')
|
bas=$(query 'regularMarketDayLow')
|
||||||
ouverture=$(query 'regularMarketOpen')
|
ouverture=$(query 'regularMarketOpen')
|
||||||
ts=$(query 'regularMarketTime')
|
ts=$(query 'regularMarketTime')
|
||||||
heure=$(LC_ALL=fr_FR.UTF-8 date -d @$ts +"%c" 2>/dev/null || LC_ALL=fr_FR.UTF-8 date -r $ts +"%c")
|
heure=$(LC_ALL=fr_FR.UTF-8 date -d @$ts +"%c" 2>/dev/null || LC_ALL=fr_FR.UTF-8 date -r $ts +"%c")
|
||||||
ftweeks=$(query 'fiftyTwoWeekRange')
|
ftweeks=$(query 'fiftyTwoWeekRange')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Stocks owned
|
# Stocks owned
|
||||||
z=$(jq -c '.[] | select(.symbol == "'${symbol}'")' <<< $b)
|
#z=$(jq -c '.[] | select(.symbol == "'${symbol}'")' <<<$b)
|
||||||
|
z=$(yq '.[] | select(.symbol == "'${symbol}'")' <<< "$b")
|
||||||
|
|
||||||
if [ -n "$z" ]; then
|
if [ -n "$z" ]; then
|
||||||
#echo "$z"
|
#echo "$z"
|
||||||
#quantity=$(jq -c '.[] | select(.symbol == "'${symbol}'") | .quantity' <<< $b)
|
#quantity=$(jq -c '.[] | select(.symbol == "'${symbol}'") | .quantity' <<< $b)
|
||||||
quantity=$(jq -c '.quantity' <<< $z)
|
#quantity=$(jq -c '.quantity' <<<$z)
|
||||||
unit_cost=$(jq -c '.unit_cost' <<< $z)
|
#unit_cost=$(jq -c '.unit_cost' <<<$z)
|
||||||
|
quantity=$(yq '.quantity' <<<$z)
|
||||||
|
unit_cost=$(yq '.unit_cost' <<<$z)
|
||||||
purchase=$(echo "$quantity * $unit_cost" | bc -l)
|
purchase=$(echo "$quantity * $unit_cost" | bc -l)
|
||||||
valuations=$(echo "$quantity * $price" | bc -l)
|
valuations=$(echo "$quantity * $price" | bc -l)
|
||||||
profit=$(echo "$valuations - $purchase" | bc -l)
|
profit=$(echo "$valuations - $purchase" | bc -l)
|
||||||
@@ -136,13 +146,13 @@ while IFS= read -r obj; do
|
|||||||
#((profit = valuations - purchase))
|
#((profit = valuations - purchase))
|
||||||
|
|
||||||
#echo "Qte: $quantity - PM: $unit_cost - Achat: $purchase - Valorisation: $valuations"
|
#echo "Qte: $quantity - PM: $unit_cost - Achat: $purchase - Valorisation: $valuations"
|
||||||
#echo "+-value: $profit - Perf: $performance%"
|
#echo "+-value: $profit - Perf: $performance%"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Lines colors: + green ; - red ; 0 no color
|
# Lines colors: + green ; - red ; 0 no color
|
||||||
if [ "$diff" == "0" ] || [ "$diff" == "0.0" ]; then
|
if [ "$diff" == "0" ] || [ "$diff" == "0.0" ]; then
|
||||||
color=
|
color=
|
||||||
elif ( echo "$diff" | grep -q ^- ); then
|
elif (echo "$diff" | grep -q ^-); then
|
||||||
color=$red
|
color=$red
|
||||||
#cours_color="\033[3;31m"
|
#cours_color="\033[3;31m"
|
||||||
cours_color="\033[1;37;1;41m"
|
cours_color="\033[1;37;1;41m"
|
||||||
@@ -151,17 +161,21 @@ while IFS= read -r obj; do
|
|||||||
#cours_color="\033[3;32m"
|
#cours_color="\033[3;32m"
|
||||||
cours_color="\033[1;37;1;42m"
|
cours_color="\033[1;37;1;42m"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Displaying
|
# Displaying
|
||||||
if [ "$price" != "null" ]; then
|
if [ "$price" != "null" ]; then
|
||||||
printf "${color}%-10s | %-23s | ${reset}${cours_color}%7.2f${reset}${color} | " $symbol "$longName" $price
|
printf "${color}%-10s | %-21s | ${reset}${cours_color}%7.2f${reset}${color} | " $symbol "$longName" $price
|
||||||
printf "% 6.2f | % 6.2f%% | %7.2f | " $diff $percent $previous
|
printf "% 6.2f | % 6.2f%% | %7.2f | " $diff $percent $previous
|
||||||
printf "%7.2f | %7.2f | %8d | " $haut $bas $volume
|
printf "%7.2f | %7.2f | %8d | " $haut $bas $volume
|
||||||
printf "%9.2f | %25s | %18s | " $ouverture "$heure" "$ftweeks"
|
printf "%9.2f | %25s | %18s | " $ouverture "$heure" "$ftweeks"
|
||||||
if [ -n "$z" ]; then
|
if [ -n "$z" ]; then
|
||||||
printf "%6d | %9.2f | %9.2f | % 6.2f%%${reset}\n" $quantity $valuations $profit $performance
|
printf "%6d | %9.2f | %9.2f | % 6.2f%%${reset}\n" $quantity $valuations $profit $performance
|
||||||
else echo ""
|
else
|
||||||
|
echo ""
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done < <(echo "$results" | jq -c '.[]')
|
done < <(echo "$results" | jq -c '.[]')
|
||||||
|
|
||||||
|
d=$(LC_ALL=fr_FR.UTF-8 TZ='Europe/Paris' date +"%c")
|
||||||
|
echo -e "\n${reset}Dernière mise-à-jour: ${bold}$d${reset}"
|
||||||
|
|||||||
Reference in New Issue
Block a user