1111
1212class MoexReader (_DailyBaseReader ):
1313 """
14- Returns DataFrame of historical stock prices from symbols from Moex
14+ Returns a DataFrame of historical stock prices from symbols from Moex
1515
1616 Parameters
1717 ----------
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.
2121 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
2323 representations (e.g., 'JAN-01-2010', '1/1/10', 'Jan, 1, 1980')
2424 end : str, (defaults to today)
25- Ending date, timestamp. Same format as starting date.
25+ The ending date, timestamp. Same format as starting date.
2626 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
2929 Time, in seconds, to pause between consecutive queries of chunks. If
3030 single value given for symbol, represents the pause between retries.
3131 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.
3333 session : Session, default None
3434 requests.sessions.Session instance to be used
3535
3636 Notes
3737 -----
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.
4040 """
4141
4242 def __init__ (self , * args , ** kwargs ):
4343 super (MoexReader , self ).__init__ (* args , ** kwargs )
4444 self .start = self .start .date ()
4545 self .end_dt = self .end
4646 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 ):
4851 self .symbols = [self .symbols ]
52+
4953 self .__engines , self .__markets = {}, {} # dicts for engines and markets
5054
5155 __url_metadata = "https://iss.moex.com/iss/securities/{symbol}.csv"
@@ -66,6 +70,8 @@ def url(self):
6670 symbol = s ) for s in self .symbols ]
6771
6872 def _get_params (self , start ):
73+ """Return a dict for REST API GET request parameters"""
74+
6975 params = {
7076 'iss.only' : 'history' ,
7177 'iss.dp' : 'point' ,
@@ -184,13 +190,5 @@ def _read_url_as_String(self, url, params=None):
184190 def _read_lines (self , input ):
185191 """Return a pandas DataFrame from input"""
186192
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