def current_minute(order_book_ids, skip_suspended=False, fields=None, market="cn"): """获取实时分钟行情 :param order_book_ids: 合约代码或代码列表 :param skip_suspended: 是否过滤停复牌. (Default value = False) :param fields: 可选参数。默认为所有字段。 (Default value = None) :param market: 地区代码, 如'cn' (Default value = "cn") :returns: None or pd.DataFrame """ from rqdatac.services.get_price import classify_order_book_ids, _ensure_fields from rqdatac.services.detail.get_price_df import MINBAR_FIELDS (order_book_ids, stocks, funds, indexes, futures, futures888, spots, options, convertibles, repos) = classify_order_book_ids(order_book_ids, market) if skip_suspended and stocks: date = get_previous_trading_date(datetime.date.today() + datetime.timedelta(days=1)) df_suspended = is_suspended(stocks, date, date) if not df_suspended.empty: df_suspended_t = df_suspended.T suspended_obids = set(df_suspended_t[df_suspended_t[df_suspended_t.columns[0]]].index) inspection = suspended_obids & set(stocks) if inspection: stocks = set(stocks) - inspection order_book_ids = list(set(order_book_ids) - inspection) fields, _ = _ensure_fields(fields, MINBAR_FIELDS, stocks, funds, futures, futures888, spots, options, convertibles, indexes, repos) data = get_client().execute("current_minute", order_book_ids, fields + ["datetime"], market=market) if not data: return df = pd.DataFrame(data) df["datetime"] = df["datetime"].map(int14_to_datetime, na_action="ignore") df.set_index(["order_book_id", "datetime"], inplace=True) return df
def filter_suspended(ret, order_book_id, start_date, end_date, market): # return a frame if only one order book specified s = is_suspended(order_book_id, start_date, end_date, market) index = s.index.union(ret.index) s = s.reindex(index) s = s.fillna(method="ffill") s = s.loc[ret.index] return ret[s[order_book_id] == False] # noqa
def filter_suspended(ret, order_book_id, start_date, end_date, market): s = is_suspended(order_book_id, start_date, end_date, market) ret_date_index = ret.index.get_level_values(1) index = s.index.union(ret_date_index) s = s.reindex(index) s = s.fillna(method="ffill") s = s.loc[ret_date_index] s = s[order_book_id] == False return ret[s.values]
def filter_suspended(ret, order_book_id, start_date, end_date, is_convertible, market): if is_convertible: from rqdatac.services.convertible import is_suspended as is_convertible_suspend s = is_convertible_suspend(order_book_id, start_date, end_date) else: s = is_suspended(order_book_id, start_date, end_date, market) ret_date_index = ret.index.get_level_values(1) index = s.index.union(ret_date_index) s = s.reindex(index) s = s.fillna(method="ffill") s = s.loc[ret_date_index] s = s[order_book_id] == False return ret[s.values]