def ensure_instruments_in_order(order_book_ids, type=None, market="cn"): order_book_ids = ensure_list_of_string(order_book_ids) from rqdatac.services.basic import _all_instruments_dict all_instruments = _all_instruments_dict(market) result = [] unique = set() result_append = result.append unique_add = unique.add for ob in order_book_ids: i = all_instruments.get(ob) if not i: warnings.warn("invalid order_book_id: {}".format(ob), stacklevel=0) continue if type is not None and i.type != type: warnings.warn("expect {} instrument, got {}({}), ignored".format( type, i.type, ob), stacklevel=0) continue if ob in unique: warnings.warn("duplicated order_book_id: {}".format(ob), stacklevel=0) continue unique_add(ob) result_append(i) if not result: raise ValueError( "order_book_ids: at least one valid instrument expected, got none") return result
def ensure_order_book_id(ob, type=None, market="cn"): ob = ensure_string(ob, "order_book_id") from rqdatac.services.basic import _all_instruments_dict all_instruments = _all_instruments_dict(market) try: i = all_instruments[ob] except KeyError as e: raise ValueError("invalid order_book_id: {!s}".format(e)) if type is not None and i.type != type: raise ValueError("expect {} instrument, got {}({}), ignored".format( type, i.type, ob)) return i.order_book_id
def ensure_order_book_ids(order_book_ids, type=None, market="cn"): order_book_ids = ensure_list_of_string(order_book_ids) from rqdatac.services.basic import _all_instruments_dict all_instruments = _all_instruments_dict(market) result = [] for ob in set(order_book_ids): i = all_instruments.get(ob) if not i: warnings.warn("invalid order_book_id: {}".format(ob)) continue if type is not None and i.type != type: warnings.warn("expect {} instrument, got {}({}), ignored".format( type, i.type, ob)) continue result.append(i.order_book_id) if not result: raise ValueError( "order_book_ids: at least one valid instrument expected, got none") return result