-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
executable file
·105 lines (96 loc) · 3.55 KB
/
script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
set -euo pipefail
### CONFIG
r4automator="localhost:8080"
robot_advisor="localhost:8081"
### END_CONFIG
session="./session"
function create_new_session {
FOLDER="data/$(date "+%Y-%m-%dT%H%M%S")"
mkdir -p $FOLDER
rm -f "$session"
touch "$session"
cp data/seed/* $FOLDER
echo "FOLDER=$FOLDER" >> "$session"
}
function read_session {
file="$session"
if [ -f "$file" ]
then
while IFS='=' read -r key value
do
eval "${key}='${value}'"
done < "$file"
else
echo "$file not found."
fi
}
read_session
set -e
case "$1" in
newsession )
create_new_session
echo "session created in $FOLDER"
;;
login )
echo "if you wish to proceed, go to the IDE to manually confirm this request"
curl ${r4automator}/login -XPOST -H "Content-Type: application/json" -d '{"username":"AzureDiamond", "password": "hunter2", "nif": "Cthon98"}' > $FOLDER/login.html
if [ $? -eq 0 ]; then
echo "Login was ok"
else
echo "Error with log in - see $FOLDER/login.html"
fi
;;
2fa )
./2fa.sh ;;
scrape )
curl ${r4automator}/scrapes/cash -o $FOLDER/cash.html
curl ${r4automator}/scrapes/funds -o $FOLDER/funds.html
;;
parseportfolio )
curl ${r4automator}/parse -XPOST -F "funds=@${FOLDER}/funds.html" -F "cash=@${FOLDER}/cash.html" | jq "." > ${FOLDER}/portfolio.json
cat ${FOLDER}/portfolio.json | jq "."
;;
prepare-contribution )
cat ${FOLDER}/portfolio.json | jq '.assets[] | select(.type|contains ("cash"))' > ${FOLDER}/cash.json
cat ${FOLDER}/cash.json | jq "."
echo "For manual modifications, please go to ${FOLDER}/cash.json and edit the value"
;;
contribute )
set -x
echo "For manual modifications, please go to ${FOLDER}/cash.json and edit the value"
./join_contribute_request.sh ${FOLDER}/cash.json ${FOLDER}/idealallocation.json | jq "." > ${FOLDER}/contribute_request.json
curl ${robot_advisor}/contribute -XPOST -H "Content-Type: application/json" --data-binary @${FOLDER}/contribute_request.json -o ${FOLDER}/new_orders.json
cat ${FOLDER}/new_orders.json | jq "."
set +x
;;
contribute-manually )
set +e
mv ${FOLDER}/new_orders.manual.json ${FOLDER}/new_orders.json
set -e
vim ${FOLDER}/new_orders.json
echo "You have finished editing the orders, manually"
;;
rebalance )
echo "For manual modifications, please go to ${FOLDER}/portfolio.json and edit the 'cash' section"
./join_rebalance_request.sh ${FOLDER}/portfolio.json ${FOLDER}/idealallocation.json > ${FOLDER}/rebalance_request.json
curl ${robot_advisor}/rebalance -XPOST -H "Content-Type: application/json" --data-binary @${FOLDER}/rebalance_request.json -o ${FOLDER}/new_orders.json
cat ${FOLDER}/rebalance_orders.json | jq "."
;;
makeoperations )
echo "if you wish to proceed, go to the IDE to manually confirm this request"
curl ${r4automator}/operations -XPOST -H "Content-Type: application/json" --data-binary @${FOLDER}/new_orders.json > ${FOLDER}/operations_result.html
if [ $? -eq 0 ]; then
echo "Making the operations was ok"
else
echo "Error with making the operations - see ${FOLDER}/operations_result.html or the IDE"
fi
;;
endsession )
rm ./"$session"
;;
* )
echo "could not understand command $1"
exit 1
esac
exit 0