Ejemplo n.º 1
0
def append_one_stock(service, code, dtype, listing_date):
    '''

    :param worker:
    :param code:
    :param dtype:
    :param last_fetchdate:
    :param listing_date:
    :return:
    '''
    global is_closing
    todayStr = DateUtil.getTodayStr()
    last_fetchdate = DateUtil.string_toDate('2018-08-02')

    start = None
    ld, tindex = service.storeservice.find_lastdate_and_tindex(code, dtype)
    lastdate = last_fetchdate if ld == None else ld
    if lastdate is not None and lastdate.date() > listing_date:
        start = DateUtil.getDatetimeFutureStr(lastdate.date(), 1)
    else:
        start = DateUtil.date_toString(last_fetchdate)
    end = todayStr
    gen = DateUtil.getNextHalfYear(DateUtil.string_toDate(start),
                                   DateUtil.string_toDate(end),
                                   ndays=360)
    while True:
        try:
            end = next(gen)

            if is_closing is True:
                break

            b2 = time.time()
            days = DateUtil.diff(start, end)
            lastest_date = service.get_hisft_klinetory_data(
                code[3:], start, days)

            if lastest_date is not None:
                service.storeservice.update_lastdate(
                    code, dtype,
                    DateUtil.string_toDatetime(
                        DateUtil.datetime_toString(lastest_date)))
                logging.info('********I')
            e2 = time.time()
            logging.info(
                "fetching {} dtype {}  listing_date: {} start: {} end:{} cost time {}"
                .format(code, dtype, listing_date, start, end, e2 - b2))

            start = DateUtil.getDatetimeFutureStr(DateUtil.string_toDate(end),
                                                  1)
        except StopIteration as e:
            print(e)
            break
Ejemplo n.º 2
0
 def find_history_kline(self, code, dtype, start, end):
     tindex = self.find_tindex(code, dtype)
     cls = getClassByIndex(tindex)
     ret = []
     #for item in self.mysqlStore.session.query(FTHistoryKline6).filter(cls.code == code).filter(and_(text('time_key>:start'),text('time_key<:end')).params(start=start,end=end)).all():
     #,cls.code,cls.time_key,cls.open,cls.close,cls.high,cls.low,cls.pe_ratio,cls.turnover_rate,cls.volume,cls.turnover,cls.change_rate,cls.last_close
     #(code, time_key, open, close, high, low, pe_ratio, turnover_rate, volume, turnover, change_rate, last_close)
     for code, time_key, open, close, high, low, pe_ratio, turnover_rate, volume, turnover, change_rate, last_close in self.mysqlStore.session.query(
             cls.code, cls.time_key, cls.open, cls.close, cls.high, cls.low,
             cls.pe_ratio, cls.turnover_rate, cls.volume, cls.turnover,
             cls.change_rate,
             cls.last_close).filter(cls.code == code).filter(
                 and_(cls.time_key >= start,
                      cls.time_key <= end)).order_by(cls.time_key).all():
         item = (code, DateUtil.datetime_toString(time_key), open, close,
                 high, low, pe_ratio, turnover_rate, volume, turnover,
                 change_rate, last_close)
         ret.append(item)
     return ret