From 5dae41b0f9e15758559917fedaae8f94b7ffe870 Mon Sep 17 00:00:00 2001 From: Sampath Kumar Date: Fri, 2 Oct 2020 15:55:20 +0530 Subject: [PATCH] Add toggle option for moscow time and market time --- finam/export.py | 15 +++++++++++---- scripts/finam-download.py | 10 ++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/finam/export.py b/finam/export.py index c7e4257..ea4d7aa 100644 --- a/finam/export.py +++ b/finam/export.py @@ -64,7 +64,6 @@ class Timeframe(IntEnum): WEEKLY = 9 MONTHLY = 10 - class LookupComparator(IntEnum): EQUALS = 1 @@ -304,8 +303,6 @@ class Exporter(object): 'dtf': '1', 'tmf': '3', 'MSOR': '0', - 'mstime': 'on', - 'mstimever': '1', 'sep': '3', 'sep2': '1', 'at': '1' @@ -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 @@ -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 diff --git a/scripts/finam-download.py b/scripts/finam-download.py index 815cbc4..56fd718 100755 --- a/scripts/finam-download.py +++ b/scripts/finam-download.py @@ -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)): @@ -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))