def get_macd_data_by_ifcode(cls, date, ifcode, pre_time): today = str2day(date, DATE_DISPLAY_FORMAT) pre = pre_day(today) pre_str = pre.strftime('%Y-%m-%d') _ifcode = get_ifcode(pre) # 如果是上一个合约 _rs = [] if _ifcode != ifcode: _where = '''%s where (`time` >= '%s 14:%s:00' and `time` <= '%s 15:00:00') ''' % (_ifcode, pre_str, pre_time, pre_str) _sql = '''select `inserttime`, `time` as time_index, `now` as price, `volume` from ''' + _where + ''' order by inserttime;''' _rs = yhdb(_sql) where = '''%s where (`time` >= '%s 14:%s:00' and `time` <= '%s 15:00:00') or (`time` >= '%s 09:30:00' and `time` <= '%s 11:30:00') or (`time` >= '%s 13:00:00' and `time` <= '%s 15:00:00') ''' % (ifcode, pre_str, pre_time, pre_str, date, date, date, date) sql = '''select `inserttime`, `time` as time_index, `now` as price, `volume` from ''' + where + ''' order by inserttime;''' rs = yhdb(sql) if _rs: rs = _rs + rs return [obj_to_list(cls(*r)) for r in rs if r]
def get_data_by_ifcode(cls, date, ifcode): where = '''%s where (`time` >= '%s 09:30:00' and `time` <= '%s 11:30:00') or (`time` >= '%s 13:00:00' and `time` <= '%s 15:00:00')''' % ( ifcode, date, date, date, date) sql = '''select `inserttime`, `time` as time_index, `now` as price, `volume` from ''' + where + ''' order by inserttime;''' rs = yhdb(sql) return [obj_to_list(cls(*r)) for r in rs]
def ifcode_day_map(ifcode): sql = '''select distinct date(`time`) from %s;''' % ifcode rs = yhdb(sql) return [d[0].strftime('%Y-%m-%d') for d in rs]