-
Notifications
You must be signed in to change notification settings - Fork 679
/
Copy pathstooq.py
67 lines (59 loc) · 2.2 KB
/
stooq.py
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
from pandas_datareader.base import _DailyBaseReader
class StooqDailyReader(_DailyBaseReader):
"""
Returns DataFrame/dict of Dataframes of historical stock prices from
symbols, over date range, start to end.
Parameters
----------
symbols : string, array-like object (list, tuple, Series), or DataFrame
Single stock symbol (ticker), array-like object of symbols or
DataFrame with index containing stock symbols.
start : string, int, date, datetime, Timestamp
Starting date. Parses many different kind of date
representations (e.g., 'JAN-01-2010', '1/1/10', 'Jan, 1, 1980'). Defaults to
20 years before current date.
end : string, int, date, datetime, Timestamp
Ending date
retry_count : int, default 3
Number of times to retry query request.
pause : int, default 0.1
Time, in seconds, to pause between consecutive queries of chunks. If
single value given for symbol, represents the pause between retries.
chunksize : int, default 25
Number of symbols to download consecutively before initiating pause.
session : Session, default None
requests.sessions.Session instance to be used
Notes
-----
See `Stooq <https://stooq.com>`__
"""
@property
def url(self):
"""API URL"""
return "https://stooq.com/q/d/l/"
def _get_params(self, symbol, country="US"):
symbol_parts = symbol.split(".")
if not symbol.startswith("^"):
if len(symbol_parts) == 1:
symbol = ".".join([symbol, country])
elif symbol_parts[1].lower() == "pl":
symbol = symbol_parts[0]
else:
if symbol_parts[1].lower() not in [
"de",
"hk",
"hu",
"jp",
"uk",
"us",
"f",
"b",
]:
symbol = ".".join([symbol, "US"])
params = {
"s": symbol,
"i": self.freq or "d",
"d1": self.start.strftime("%Y%m%d"),
"d2": self.end.strftime("%Y%m%d"),
}
return params