-
Notifications
You must be signed in to change notification settings - Fork 0
/
curler.sh
executable file
·130 lines (116 loc) · 3.84 KB
/
curler.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
#load apikey
if [ -f .env ]; then
source .env
fi
#load apikey, build url from it:
if [ -f .env ]; then
source .env
fi
apikey="$API_KEY"
baseUrl="https://www.alphavantage.co/query?apikey=${apikey}&function="
# Parse the input arguments
# or just use $1, $2, $3...
# in case I decide to change the API structure,
# I'll declare them into variables
function="$1"
ticker="$2"
third_arg="$3"
case "$1" in
# TOP_GAINERS_LOSERS and most active...
TGLAT*|TGLATS*|GAINERS*|LOSERS*|TOPGAINERSLOSERS*)
url="${baseUrl}TOP_GAINERS_LOSERS"
;;
OVERVIEW*)
url="${baseUrl}OVERVIEW&symbol=${ticker}"
;;
INCOME_STATEMENT*|INCOME*|STATEMENT*|INCOMESTATEMENT*)
url="${baseUrl}INCOME_STATEMENT&symbol=${ticker}"
;;
BALANCE_SHEET*|BALANCESHEET*|BALANCE*)
url="${baseUrl}BALANCE_SHEET&symbol=${ticker}"
;;
CASH_FLOW*|CASHFLOW*)
url="${baseUrl}CASH_FLOW&symbol=${ticker}"
;;
EARNINGS*)
url="${baseUrl}EARNINGS&symbol=${ticker}"
;;
# Commodities and Macro Indicators
WTI*|BRENT*|NATURAL_GAS*|GAS*|COPPER*|ALUMINUM*|WHEAT*|CORN*|COTTON*|SUGAR*|COFFEE*|ALL_COMMODITIES*|GDP*|GDPPC*|GDPPERCAP*|FEDFUNDSRATE*|FEDFUNDS*|FUNDS*|EFFECTIVEFEDERALFUNDSRATE*|EFFR*|CPI*|INFLATION*|RETAILSALES*|RETAIL*|DURABLES*|UNEMPLOYMENT*|NONFARMPAYROLL*|NONFARM*|PAYROLL*|EMPLOYMENT*|BOND*|YIELD*|TREASURY*|TREASURY_YIELD*)
case "$function" in
WTI*|BRENT*|NATURAL_GAS*|GAS*)
interval="interval=daily"
;;
COPPER*|ALUMINUM*|WHEAT*|CORN*|COTTON*|SUGAR*|COFFEE*|ALL_COMMODITIES*)
interval="interval=quarterly"
;;
GDP*|GDPPC*|GDPPERCAP*)
interval="interval=quarterly"
;;
FEDFUNDSRATE*|FEDFUNDS*|FUNDS*|EFFECTIVEFEDERALFUNDSRATE*|EFFR*)
interval="interval=daily"
;;
CPI*)
interval="interval=monthly"
;;
INFLATION*)
;;
RETAILSALES*|RETAIL*)
;;
DURABLES*)
;;
UNEMPLOYMENT*)
;;
NONFARMPAYROLL*|NONFARM*|PAYROLL*|EMPLOYMENT*)
;;
BOND*|YIELD*|TREASURY*|TREASURY_YIELD*)
function="TREASURY_YIELD"
maturity="$third_arg"
case "$maturity" in
3|3m|3month)
maturity="3month"
;;
2|2y|2yr|2year)
maturity="2year"
;;
5|5y|5yr|5year)
maturity="5year"
;;
7|7y|7yr|7year)
maturity="7year"
;;
10|10y|10yr|10year)
maturity="10year"
;;
30|30y|30yr|30year)
maturity="30year"
;;
esac
interval="interval=daily"
;;
esac
url="${baseUrl}${function}&${interval}"
;;
# FX_DAILY
EXCHANGE*|CURRENCY*|RATE*)
from="$ticker"
to="$third_arg"
url="${baseUrl}FX_DAILY&outputsize=full&from_symbol=${from}&to_symbol=${to}"
;;
# Time Series IntraDay
# Date-based query
[0-9][0-9][0-9][0-9]-[0-9][0-9]) #e.g. 2003-03
refDate="2000-01"
if [ "$function" \< "$refDate" ]; then
echo "Error: Date is before 2000-01"
exit 1
fi
url="${baseUrl}TIME_SERIES_INTRADAY&month=${function}&interval=1min&symbol=${ticker}&outputsize=full"
;;
*)
url="${baseUrl}TIME_SERIES_DAILY&symbol=${function}"
;;
esac
echo $url
curl "$url"