Exemplo n.º 1
0
 def test_get_share(self):
     share = _modb.get_share('', isodate_to_milliseconds('2018-04-27'),
                             isodate_to_milliseconds('2018-04-27'))
     lg.info("local daily summary:\n{}".format(share.head(1)))
     online = sse.get_money_fund_share('2018-04-27')
     lg.info("online daily summary:\n{}".format(online.head(1)))
     self.assertEqual(len(share.index), len(online.index))
     self.assertEqual(share.iloc[0][moneydb.COL_TRADE_DATE],
                      online.iloc[0]['STAT_DATE'])
Exemplo n.º 2
0
 def sync_gcr_ohlc(self,
                   gcr_index='sh204001',
                   count_of_recent_trading_days=14):
     logger.info("syncing gcr ohlc {}:days:{}".format(
         gcr_index, count_of_recent_trading_days))
     if gcr_index not in moneydb.tracked_gcr:
         logger.error("gcr {} is not tracked.".format(gcr_index))
         return
     duration = moneydb.tracked_gcr[gcr_index][moneydb.COL_GCR_DURATION]
     amt_multiple = moneydb.tracked_gcr[gcr_index][moneydb.COL_GCR_AMOUNT]
     ohlc = moneysites.qq.get_gcr_ohlc(
         gcr_index=gcr_index,
         count_of_recent_trading_days=count_of_recent_trading_days)
     ohlc[moneydb.COL_GCR_INDEX] = [gcr_index for _ in ohlc.index]
     ohlc[moneydb.COL_GCR_DURATION] = [duration for _ in ohlc.index]
     ohlc[moneydb.COL_GCR_AMOUNT] = [
         amt_multiple * ohlc.loc[i]['v'] for i in ohlc.index
     ]
     ohlc[moneydb.COL_TRADE_DATE] = ohlc['d']
     ohlc[moneydb.COL_MILLISECONDS] = [
         isodate_to_milliseconds(ohlc.loc[i][moneydb.COL_TRADE_DATE])
         for i in ohlc.index
     ]
     logger.debug("grc_ohlc:\n{}".format(ohlc.tail(1)))
     self._modb.upsert_gcr_ohlc(ohlc)
     logger.info("{} gcr ohlc sync is done:{}".format(
         gcr_index, len(ohlc.index)))
Exemplo n.º 3
0
    def sync_today(self, force_update=False, missed_days=14):
        '''
        清算后
        :param force_update:
        :param missed_days:
        :return:
        '''
        trade_date = datetime.today().isoformat()[:10]
        start = datetime.today() - timedelta(days=missed_days)
        start_date = start.isoformat()[:10]
        logger.info("syncing money share today from {} to {}...".format(
            start_date, trade_date))
        self.sync_money_share(fr_date=start_date, force_update=force_update)
        for gcr_index in moneydb.tracked_gcr:
            # logger.info("syncing gcr today:{}".format(gcr_index))
            self.sync_gcr_ohlc(gcr_index=gcr_index,
                               count_of_recent_trading_days=missed_days)
        logger.info("update gcr locked amount from: {}".format(start_date))
        self.update_gcr_locked_amount(fr_date=start_date)

        logger.info("{}:ugly szse share is syncing...".format(trade_date))
        share = moneysites.szse.get_money_fund_share(trade_date)
        share[moneydb.COL_MONEY_FUND_INDEX] = share['SEC_CODE']
        share[moneydb.COL_TRADE_DATE] = share['STAT_DATE']
        share[moneydb.COL_MILLISECONDS] = [
            isodate_to_milliseconds(share.loc[i][moneydb.COL_TRADE_DATE])
            for i in share.index
        ]
        self._modb.upsert_share(share)

        logger.info("sync today is done.")
Exemplo n.º 4
0
 def sync_money_share(self,
                      fr_date='2018-01-01',
                      to_date='',
                      force_update=False,
                      wait=1):
     end = datetime.today()
     if to_date != '':
         end = datetime.strptime(to_date, '%Y-%m-%d')
     start = datetime.strptime(fr_date, '%Y-%m-%d')
     delta = timedelta(days=1)
     count = int((end - start) / delta) + 1
     i = 1
     while start <= end:
         trade_date = start.isoformat()[:10]
         logger.info("{}({}/{}):".format(trade_date, i, count))
         if start.weekday() < 5:
             milliseconds = isodate_to_milliseconds(trade_date)
             cached_share = self._modb.get_share(fund_index='',
                                                 fr_ms=milliseconds,
                                                 to_ms=milliseconds)
             if len(cached_share.index) == 0 or force_update:
                 self._sync_money_share(trade_date)
                 time.sleep(wait)
             else:
                 logger.info(
                     "{} share already exists and not force update.".format(
                         trade_date))
         else:
             logger.info("skip weekend:{}".format(start.strftime("%A")))
         start += delta
         i += 1
Exemplo n.º 5
0
 def _sync_ohlc(self, option_index):
     option_index = str(option_index)
     logger.info("{}:ohlc is syncing...".format(option_index))
     ohlc = optionsites.sina.get_option_history_ohlc(option_index)
     ohlc[optiondb.COL_OPTION_INDEX] = [option_index for _ in ohlc.index]
     ohlc[optiondb.COL_TRADE_DATE] = ohlc['d']
     ohlc[optiondb.COL_MILLISECONDS] = [
         isodate_to_milliseconds(ohlc.loc[i][optiondb.COL_TRADE_DATE])
         for i in ohlc.index
     ]
     logger.debug("online ohlc:{}\n{}".format(len(ohlc.index),
                                              ohlc.head(1)))
     self._opdb.upsert_ohlc(ohlc)
Exemplo n.º 6
0
 def sync_hsg_flow(self, fr_date='2014-11-17', to_date=''):
     logger.info("syncing hsg flow {} to {}".format(fr_date, to_date))
     flow = moneysites.eastmoney.get_hsg_flow(fr_date, to_date)
     flow[moneydb.COL_TRADE_DATE] = [
         flow.loc[i]['DateTime'][:10] for i in flow.index
     ]
     flow[moneydb.COL_MILLISECONDS] = [
         isodate_to_milliseconds(flow.loc[i][moneydb.COL_TRADE_DATE])
         for i in flow.index
     ]
     logger.debug("hsg flow:\n{}".format(flow.tail(1)))
     self._modb.upsert_hsg_flow(flow)
     logger.info("hsg flow sync is done:{}: {} to {}".format(
         len(flow.index), fr_date, to_date))
Exemplo n.º 7
0
    def _sync_greeks(self, trade_date):
        logger.info("{}:greeks is syncing...".format(trade_date))
        greeks = optionsites.sse.get_greeks(trade_date)
        greeks[optiondb.COL_OPTION_INDEX] = greeks['SECURITY_ID']
        greeks[optiondb.COL_OPTION_CODE] = greeks['CONTRACT_ID']
        greeks[optiondb.COL_TRADE_DATE] = greeks['TRADE_DATE']
        greeks[optiondb.COL_MILLISECONDS] = [
            isodate_to_milliseconds(greeks.loc[i][optiondb.COL_TRADE_DATE])
            for i in greeks.index
        ]

        self._opdb.upsert_greeks(greeks)
        logger.debug("\n{}".format(greeks.head(1)))
        logger.info("greeks sync done.")
Exemplo n.º 8
0
 def _sync_money_share(self, trade_date):
     check_isodatestr_or_raise(trade_date)
     logger.info("{}:share is syncing...".format(trade_date))
     share = moneysites.sse.get_money_fund_share(trade_date)
     share[moneydb.COL_MONEY_FUND_INDEX] = share['SEC_CODE']
     share[moneydb.COL_TRADE_DATE] = share['STAT_DATE']
     share[moneydb.COL_MILLISECONDS] = [
         isodate_to_milliseconds(share.loc[i][moneydb.COL_TRADE_DATE])
         for i in share.index
     ]
     self._modb.upsert_share(share)
     logger.debug("\n{}".format(share.head(1)))
     logger.info("{}:share sync is done:{}".format(trade_date,
                                                   len(share.index)))
Exemplo n.º 9
0
 def update_gcr_locked_amount(self, fr_date='2018-01-01', to_date=''):
     end = datetime.today()
     if to_date != '':
         end = datetime.strptime(to_date, '%Y-%m-%d')
     start = datetime.strptime(fr_date, '%Y-%m-%d')
     delta = timedelta(days=1)
     count = int((end - start) / delta) + 1
     i = 1
     while start <= end:
         trade_date = start.isoformat()[:10]
         logger.info("update gcr locked amount: {}({}/{}):".format(
             trade_date, i, count))
         if start.weekday() < 5:
             milliseconds = isodate_to_milliseconds(trade_date)
             self._modb.update_gcr_locked_amount(milliseconds)
         else:
             logger.info("skip weekend:{}".format(start.strftime("%A")))
         start += delta
         i += 1
Exemplo n.º 10
0
    def sync_greeks(self,
                    fr_date='2015-02-09',
                    to_date='',
                    force_update=False,
                    wait=1):
        '''
        must be called before sync_ohlc([], False)
        :param fr_date:
        :param to_date:
        :param force_update:
        :param wait:
        :return:
        '''
        end = datetime.today()
        if to_date != '':
            end = datetime.strptime(to_date, '%Y-%m-%d')
        start = datetime.strptime(fr_date, '%Y-%m-%d')
        delta = timedelta(days=1)
        count = int((end - start) / delta) + 1
        i = 1
        while start <= end:
            trade_date = start.isoformat()[:10]
            logger.info("({}/{}){}:".format(i, count, trade_date))
            if start.weekday() < 5:  # need trade calendar
                milliseconds = isodate_to_milliseconds(trade_date)
                cached_greeks = self._opdb.get_greeks(option_index='',
                                                      fr_ms=milliseconds,
                                                      to_ms=milliseconds)
                if len(cached_greeks.index) == 0 or force_update:
                    self._sync_greeks(trade_date)
                    time.sleep(wait)
                else:
                    logger.info(
                        "{} greeks already exists and not force update.".
                        format(trade_date))
            else:
                logger.info("skip weekend:{} {}".format(
                    trade_date, start.strftime("%A")))

            start += delta
            i += 1
Exemplo n.º 11
0
 def test_update_gcr_locked_amount(self):
     _modb.update_gcr_locked_amount(isodate_to_milliseconds('2018-05-02'))