def __init__(self, force_update=True, sleeping_time=10, exchanges=None, entity_ids=None, code=None, codes=None, day_data=False, entity_filters=None, ignore_failed=True, real_time=False, fix_duplicate_way='ignore', start_timestamp=None, end_timestamp=None, level=IntervalLevel.LEVEL_1DAY, kdata_use_begin_time=False, one_day_trading_minutes=24 * 60, adjust_type=AdjustType.qfq) -> None: level = IntervalLevel(level) self.adjust_type = AdjustType(adjust_type) self.entity_type = self.entity_schema.__name__.lower() self.data_schema = get_kdata_schema(entity_type=self.entity_type, level=level, adjust_type=self.adjust_type) super().__init__(force_update, sleeping_time, exchanges, entity_ids, code, codes, day_data, entity_filters, ignore_failed, real_time, fix_duplicate_way, start_timestamp, end_timestamp, level, kdata_use_begin_time, one_day_trading_minutes)
def __init__(self, exchanges=['sh', 'sz'], entity_ids=None, codes=None, batch_size=10, force_update=True, sleeping_time=0, default_size=zvt_config['batch_size'], real_time=False, fix_duplicate_way='ignore', start_timestamp=None, end_timestamp=None, level=IntervalLevel.LEVEL_1WEEK, kdata_use_begin_time=False, close_hour=15, close_minute=0, one_day_trading_minutes=4 * 60, adjust_type=AdjustType.qfq, share_para=None) -> None: level = IntervalLevel(level) adjust_type = AdjustType(adjust_type) self.data_schema = get_kdata_schema(entity_type=EntityType.Stock, level=level, adjust_type=adjust_type) self.bao_trading_level = to_bao_trading_level(level) super().__init__(EntityType.Stock, exchanges, entity_ids, codes, batch_size, force_update, sleeping_time, default_size, real_time, fix_duplicate_way, start_timestamp, end_timestamp, close_hour, close_minute, level, kdata_use_begin_time, one_day_trading_minutes, share_para=share_para) self.adjust_type = adjust_type
def __init__(self, exchanges=['sh', 'sz'], entity_ids=None, codes=None, batch_size=10, force_update=True, sleeping_time=0, default_size=2000, real_time=False, fix_duplicate_way='ignore', start_timestamp=None, end_timestamp=None, level=IntervalLevel.LEVEL_1WEEK, kdata_use_begin_time=False, close_hour=15, close_minute=0, one_day_trading_minutes=4 * 60, adjust_type=AdjustType.qfq) -> None: level = IntervalLevel(level) adjust_type = AdjustType(adjust_type) self.data_schema = get_kdata_schema(entity_type='stock', level=level, adjust_type=adjust_type) self.jq_trading_level = to_jq_trading_level(level) super().__init__('stock', exchanges, entity_ids, codes, batch_size, force_update, sleeping_time, default_size, real_time, fix_duplicate_way, start_timestamp, end_timestamp, close_hour, close_minute, level, kdata_use_begin_time, one_day_trading_minutes) self.adjust_type = adjust_type get_token(zvt_env['jq_username'], zvt_env['jq_password'], force=True)
def to_em_fq_flag(adjust_type: AdjustType): adjust_type = AdjustType(adjust_type) if adjust_type == AdjustType.bfq: return 0 if adjust_type == AdjustType.qfq: return 1 if adjust_type == AdjustType.hfq: return 2
def __init__( self, force_update=True, sleeping_time=10, exchanges=None, entity_id=None, entity_ids=None, code=None, codes=None, day_data=False, entity_filters=None, ignore_failed=True, real_time=False, fix_duplicate_way="ignore", start_timestamp=None, end_timestamp=None, level=IntervalLevel.LEVEL_1DAY, kdata_use_begin_time=False, one_day_trading_minutes=24 * 60, adjust_type=AdjustType.qfq, ) -> None: level = IntervalLevel(level) adjust_type = AdjustType(adjust_type) self.data_schema = get_kdata_schema(entity_type="stock", level=level, adjust_type=adjust_type) self.jq_trading_level = to_jq_trading_level(level) super().__init__( force_update, sleeping_time, exchanges, entity_id, entity_ids, code, codes, day_data, entity_filters, ignore_failed, real_time, fix_duplicate_way, start_timestamp, end_timestamp, level, kdata_use_begin_time, one_day_trading_minutes, ) self.adjust_type = adjust_type get_token(zvt_config["jq_username"], zvt_config["jq_password"], force=True)
def get_kdata_schema(entity_type: str, level: Union[IntervalLevel, str] = IntervalLevel.LEVEL_1DAY, adjust_type: Union[AdjustType, str] = None): if type(level) == str: level = IntervalLevel(level) if type(adjust_type) == str: adjust_type = AdjustType(adjust_type) # kdata schema rule # 1)name:{entity_type.capitalize()}{IntervalLevel.value.upper()}Kdata if adjust_type and (adjust_type != AdjustType.qfq): schema_str = '{}{}{}Kdata'.format(entity_type.capitalize(), level.value.capitalize(), adjust_type.value.capitalize()) else: schema_str = '{}{}Kdata'.format(entity_type.capitalize(), level.value.capitalize()) return get_schema_by_name(schema_str)
def __init__(self, exchanges=['sh', 'sz'], entity_ids=None, codes=None, batch_size=10, force_update=True, sleeping_time=0, default_size=2000, real_time=False, fix_duplicate_way='ignore', start_timestamp=None, end_timestamp=None, level=IntervalLevel.LEVEL_1WEEK, kdata_use_begin_time=False, close_hour=15, close_minute=0, one_day_trading_minutes=4 * 60, adjust_type=AdjustType.qfq) -> None: level = IntervalLevel(level) adjust_type = AdjustType(adjust_type) self.data_schema = get_kdata_schema(entity_type='stock', level=level, adjust_type=adjust_type) self.bs_trading_level = to_bs_trading_level(level) super().__init__('stock', exchanges, entity_ids, codes, batch_size, force_update, sleeping_time, default_size, real_time, fix_duplicate_way, start_timestamp, end_timestamp, close_hour, close_minute, level, kdata_use_begin_time, one_day_trading_minutes) self.adjust_type = adjust_type print("尝试登陆baostock") #####login##### lg = bs.login(user_id="anonymous", password="******") if (lg.error_code == '0'): print("登陆成功") else: print("登录失败")
def __init__( self, entity_ids: List[str] = None, exchanges: List[str] = None, codes: List[str] = None, start_timestamp: Union[str, pd.Timestamp] = None, end_timestamp: Union[str, pd.Timestamp] = None, provider: str = None, level: Union[str, IntervalLevel] = IntervalLevel.LEVEL_1DAY, trader_name: str = None, real_time: bool = False, kdata_use_begin_time: bool = False, draw_result: bool = True, rich_mode: bool = False, adjust_type: AdjustType = None, profit_threshold=(3, -0.3)) -> None: assert self.entity_schema is not None self.logger = logging.getLogger(__name__) if trader_name: self.trader_name = trader_name else: self.trader_name = type(self).__name__.lower() self.trading_signal_listeners: List[TradingListener] = [] # Usually for selecting the targets in whole market with factors self.selectors: List[TargetSelector] = [] self.entity_ids = entity_ids self.exchanges = exchanges self.codes = codes self.provider = provider # make sure the min level selector correspond to the provider and level self.level = IntervalLevel(level) self.real_time = real_time if start_timestamp and end_timestamp: self.start_timestamp = to_pd_timestamp(start_timestamp) self.end_timestamp = to_pd_timestamp(end_timestamp) else: assert False self.trading_dates = self.entity_schema.get_trading_dates( start_date=self.start_timestamp, end_date=self.end_timestamp) if real_time: self.logger.info( 'real_time mode, end_timestamp should be future,you could set it big enough for running forever' ) assert self.end_timestamp >= now_pd_timestamp() self.kdata_use_begin_time = kdata_use_begin_time self.draw_result = draw_result self.rich_mode = rich_mode if type(adjust_type) is str: adjust_type = AdjustType(adjust_type) self.adjust_type = adjust_type self.profit_threshold = profit_threshold self.account_service = SimAccountService( entity_schema=self.entity_schema, trader_name=self.trader_name, timestamp=self.start_timestamp, provider=self.provider, level=self.level, rich_mode=rich_mode, adjust_type=self.adjust_type) self.register_trading_signal_listener(self.account_service) self.init_selectors(entity_ids=entity_ids, entity_schema=self.entity_schema, exchanges=self.exchanges, codes=self.codes, start_timestamp=self.start_timestamp, end_timestamp=self.end_timestamp, adjust_type=self.adjust_type) if self.selectors: self.trading_level_asc = list( set([ IntervalLevel(selector.level) for selector in self.selectors ])) self.trading_level_asc.sort() self.logger.info( f'trader level:{self.level},selectors level:{self.trading_level_asc}' ) if self.level != self.trading_level_asc[0]: raise Exception( "trader level should be the min of the selectors") self.trading_level_desc = list(self.trading_level_asc) self.trading_level_desc.reverse() self.session = get_db_session('zvt', data_schema=TraderInfo) self.level_map_long_targets = {} self.level_map_short_targets = {} self.trading_signals: List[TradingSignal] = [] self.on_start()