Exemple #1
0
def get_trade_day_bar(unit='W',
                      n=1,
                      start_date=None,
                      end_date=None,
                      count=None):
    """
    unit: freq, "W":means week "M":means month
    n: n=1,first trade day; n=-1,last trade day
    start_date: begin date
    end_date: finish date
    count: return data count
    """
    df = pd.DataFrame(pd.to_datetime(jqdatasdk.get_all_trade_days()),
                      columns=['date'])
    week_stamp = 24 * 60 * 60 * 7
    day_stamp = 24 * 60 * 60
    df['timestamp'] = df.data.apply(lambda x: x.timestamp() - day_stamp * 3)
    df['mkweek'] = df.timestamp // week_stamp
    df['month'] = df.date.apply(lambda x: x.month)
    df['year'] = df.date.apply(lambda x: x.year)

    if unit == "W":
        group_list = ['mkweek']
    elif unit == "M":
        group_list = ["year", "month"]
    else:
        raise ValueError('only support para "M" or "W" ')
    if not isinstance(n, int):
        raise ValueError('n para should be int')
    elif n > 0:
        res = df.groupby(group_list, as_index=False).head(n), groupby(
            group_list, as_index=False).last()
    elif n < 0:
        res = df.groupby(group_list, as_index=False), tail(-n).groupby(
            group_list, as_index=False).first()
    else:
        raise ValueError('n para error: n={}.'.format(n))

    if start_date and end_date and count:
        raise ValueError('start_date, end_date, count shoule select two')
    elif start_date and count:
        return res[res.date >= start_date].head(count)
    elif end_date and count:
        return res[res.date <= end_date].tail(count)
    elif start_date and end_date:
        return res[(res.date <= end_date) & (res.date >= start_date)]
    elif not start_date and not end_date and not count:
        return res
    else:
        raise ValueError('start_date, end_date, count should select two')
    def checkout_with_jqdatasdk(self, start: datetime.datetime,
                                end: datetime.datetime):
        """
        与聚宽 sdk 的交易日数据进行对比
        :param start:  对比开始时间
        :param end:  对比结束时间
        :return:
        """

        sus, trades = self.gen_sh000001(start, end, datetime.datetime.now())
        trades = [self.yyyymmdd_date(day) for day in trades]

        jq_trades = jqsdk.get_all_trade_days()
        jq_trades = jq_trades.tolist()
        jq_trades = [self.yyyymmdd_date(day) for day in jq_trades]

        self.log(len(trades), trades[0], trades[-1])
        self.log(len(jq_trades), jq_trades[0], jq_trades[-1])

        return trades == jq_trades

def yyyymmdd_date(dt: datetime) -> int:
    return dt.year * 10**4 + dt.month * 10**2 + dt.day


if __name__ == "__main__":
    start = datetime.datetime(2005, 1, 4)
    end = datetime.datetime(2019, 12, 31)

    sus, trading = gen_sh000001(start, end)
    trading = [yyyymmdd_date(day) for day in trading]

    print(len(trading))
    print(trading[0])
    print(trading[-1])

    # 使用 JQdata 接口的数据做测试
    import jqdatasdk as jqsdk

    jqsdk.auth('15626046299', '046299')
    # print(type(jqsdk.get_all_trade_days()))

    res1 = jqsdk.get_all_trade_days()
    res2 = res1.tolist()
    res2 = [yyyymmdd_date(day) for day in res2]
    print(len(res2))
    print(res2[0])  # 2005-01-04
    print(res2[-1])  # 2019-12-31
    print(trading == res2)
    async def get_all_trade_days(self) -> np.array:
        if not self.connected:
            logger.warning("not connected")
            return None

        return jq.get_all_trade_days()
 def get_trading_calendar(self):
     trading_dates = get_all_trade_days()
     #pdb.set_trace()
     trading_dates_timestamp = list(map(convert_to_timestamp,
                                        trading_dates))
     return pd.Index(trading_dates_timestamp)
def get_all_trade_days(*args, **kwargs):
    return jqdatasdk.get_all_trade_days(*args, **kwargs)
Exemple #7
0
        print(e)


def verify_stop_status(date_list, status):
    # 首先查records_status表,查询已经完成的数据
    recorded_date_list = model.find_record(status)
    condition = lambda t: t not in recorded_date_list
    date_list = list(filter(condition, date_list))
    return date_list


import numpy as np

if __name__ == '__main__':
    jq.auth("18675594612", "Cmfchina123")
    date_list = jq.get_all_trade_days()[-40:-20]
    len_datelist = len(date_list)
    per = len_datelist // 100
    print("多线程开始")
    try:

        for i in date_list:
            thread_list = []
            code = get_data_base1()
            code = deal_code(code, i)
            for origin in ['alpha191','alpha101']:
                if not code.empty:
                    code = code['code']
                    code = code.tolist()
                for c in range(0,len(code),30):
                    tmplis = []
Exemple #8
0
            print(e)


def verify_stop_status(date_list, status):
    # 首先查records_status表,查询已经完成的数据
    recorded_date_list = model.find_record(status)
    condition = lambda t: t not in recorded_date_list
    date_list = list(filter(condition, date_list))
    return date_list


import numpy as np

if __name__ == '__main__':
    jq.auth("18675594612", "Cmfchina123")
    date_list = jq.get_all_trade_days()[-20:]
    len_datelist = len(date_list)
    per = len_datelist // 100
    print("多线程开始")
    try:
        thread_list = []
        for i in range(30):
            th = threading.Thread(target=cc_alpha191_data,
                                  args=([
                                      date_list[i],
                                  ], ))
            th.start()
            thread_list.append(th)
        for t in thread_list:
            t.join()
Exemple #9
0
 def get_all_trade_days(self):
     return jq.get_all_trade_days()