Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions finam/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class Timeframe(IntEnum):
WEEKLY = 9
MONTHLY = 10


class LookupComparator(IntEnum):

EQUALS = 1
Expand Down Expand Up @@ -304,8 +303,6 @@ class Exporter(object):
'dtf': '1',
'tmf': '3',
'MSOR': '0',
'mstime': 'on',
'mstimever': '1',
'sep': '3',
'sep2': '1',
'at': '1'
Expand Down Expand Up @@ -350,8 +347,13 @@ def download(self,
market,
start_date=datetime.date(2007, 1, 1),
end_date=None,
timeframe=Timeframe.DAILY):
timeframe=Timeframe.DAILY,
moscowtime=True):

if moscowtime:
mstimever='1'
else:
mstimever='0'
items = self._meta.lookup(id_=id_, market=market)
# i.e. for markets 91, 519, 2
# id duplicates are feasible, looks like corrupt data on finam
Expand All @@ -376,11 +378,16 @@ def download(self,
'yt': end_date.year,
'cn': code,
'code': code,
#1 for moscow time 0 for market time
'mstimever': mstimever,
# I would guess this param denotes 'data format'
# that differs for ticks only
'datf': 6 if timeframe == Timeframe.TICKS.value else 5
}

if moscowtime:
params['mstime']='on'

url = self._build_url(params)
# deliberately not using pd.read_csv's ability to fetch
# urls to fully control what's happening
Expand Down
10 changes: 8 additions & 2 deletions scripts/finam-download.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ def _arg_split(ctx, param, value):
@click.option('--ext',
help='Resulting file extension',
default='csv')
@click.option('--moscowtime',
help='Moscow time True or False',
required=False,
default=True,
type=bool)
def main(contracts, market, timeframe, destdir, lineterm,
delay, startdate, enddate, skiperr, ext):
delay, startdate, enddate, skiperr, ext, moscowtime):
exporter = Exporter()

if not any((contracts, market)):
Expand Down Expand Up @@ -108,7 +113,8 @@ def main(contracts, market, timeframe, destdir, lineterm,
start_date=startdate,
end_date=enddate,
timeframe=Timeframe[timeframe],
market=Market(contract.market))
market=Market(contract.market),
moscowtime=moscowtime)
except FinamExportError as e:
if skiperr:
logger.error(repr(e))
Expand Down