11
11
12
12
class MoexReader (_DailyBaseReader ):
13
13
"""
14
- Returns DataFrame of historical stock prices from symbols from Moex
14
+ Returns a DataFrame of historical stock prices from symbols from Moex
15
15
16
16
Parameters
17
17
----------
18
- symbols : str, array-like object (list, tuple, Series), or DataFrame
19
- Single stock symbol (ticker), array-like object of symbols or
20
- DataFrame with index containing stock symbols.
18
+ symbols : str, an array-like object (list, tuple, Series), or a DataFrame
19
+ A single stock symbol (secid), an array-like object of symbols or
20
+ a DataFrame with an index containing stock symbols.
21
21
start : str, (defaults to '1/1/2010')
22
- Starting date, timestamp. Parses many different kind of date
22
+ The starting date, timestamp. Parses many different kind of date
23
23
representations (e.g., 'JAN-01-2010', '1/1/10', 'Jan, 1, 1980')
24
24
end : str, (defaults to today)
25
- Ending date, timestamp. Same format as starting date.
25
+ The ending date, timestamp. Same format as starting date.
26
26
retry_count : int, default 3
27
- Number of times to retry query request.
28
- pause : int, default 0
27
+ The number of times to retry query request.
28
+ pause : int, default 0.1
29
29
Time, in seconds, to pause between consecutive queries of chunks. If
30
30
single value given for symbol, represents the pause between retries.
31
31
chunksize : int, default 25
32
- Number of symbols to download consecutively before intiating pause.
32
+ The number of symbols to download consecutively before intiating pause.
33
33
session : Session, default None
34
34
requests.sessions.Session instance to be used
35
35
36
36
Notes
37
37
-----
38
- To avoid being penalized by Moex servers, pauses between downloading
39
- 'chunks' of symbols can be specified.
38
+ To avoid being penalized by Moex servers, pauses more than 0.1s between
39
+ downloading 'chunks' of symbols can be specified.
40
40
"""
41
41
42
42
def __init__ (self , * args , ** kwargs ):
43
43
super (MoexReader , self ).__init__ (* args , ** kwargs )
44
44
self .start = self .start .date ()
45
45
self .end_dt = self .end
46
46
self .end = self .end .date ()
47
- if not is_list_like (self .symbols ):
47
+
48
+ if isinstance (self .symbols , pd .DataFrame ):
49
+ self .symbols = self .symbols .index .tolist ()
50
+ elif not is_list_like (self .symbols ):
48
51
self .symbols = [self .symbols ]
52
+
49
53
self .__engines , self .__markets = {}, {} # dicts for engines and markets
50
54
51
55
__url_metadata = "https://iss.moex.com/iss/securities/{symbol}.csv"
@@ -66,6 +70,8 @@ def url(self):
66
70
symbol = s ) for s in self .symbols ]
67
71
68
72
def _get_params (self , start ):
73
+ """Return a dict for REST API GET request parameters"""
74
+
69
75
params = {
70
76
'iss.only' : 'history' ,
71
77
'iss.dp' : 'point' ,
@@ -184,13 +190,5 @@ def _read_url_as_String(self, url, params=None):
184
190
def _read_lines (self , input ):
185
191
"""Return a pandas DataFrame from input"""
186
192
187
- rs = pd .read_csv (input , index_col = 'TRADEDATE' , parse_dates = True , sep = ';' ,
188
- na_values = ('-' , 'null' ))
189
- # Get rid of unicode characters in index name.
190
- try :
191
- rs .index .name = rs .index .name .decode (
192
- 'unicode_escape' ).encode ('ascii' , 'ignore' )
193
- except AttributeError :
194
- # Python 3 string has no decode method.
195
- rs .index .name = rs .index .name .encode ('ascii' , 'ignore' ).decode ()
196
- return rs
193
+ return pd .read_csv (input , index_col = 'TRADEDATE' , parse_dates = True ,
194
+ sep = ';' , na_values = ('-' , 'null' ))
0 commit comments