How to use the zvt.domain.TradingLevel function in zvt

To help you get started, we’ve selected a few zvt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zvtvz / zvt / tests / test_joinquant_quotes.py View on Github external
def test_jq_603220_kdata():
    df = technical.get_kdata(security_id='stock_sh_603220', session=day_k_session, level=TradingLevel.LEVEL_1DAY,
                             provider='joinquant')
    print(df)
    df = technical.get_kdata(security_id='stock_sh_603220', session=day_1h_session, level=TradingLevel.LEVEL_1HOUR,
                             provider='joinquant')
    print(df)
github zvtvz / zvt / tests / test_joinquant_quotes.py View on Github external
def test_jq_603220_kdata():
    df = technical.get_kdata(security_id='stock_sh_603220', session=day_k_session, level=TradingLevel.LEVEL_1DAY,
                             provider='joinquant')
    print(df)
    df = technical.get_kdata(security_id='stock_sh_603220', session=day_1h_session, level=TradingLevel.LEVEL_1HOUR,
                             provider='joinquant')
    print(df)
github zvtvz / zvt / zvt / recorders / joinquant / jq_china_stock_day_kdata_recorder.py View on Github external
def __init__(self, security_type=SecurityType.stock, exchanges=['sh', 'sz'], codes=None, batch_size=10,
                 force_update=False, sleeping_time=5, fetching_style=TimeSeriesFetchingStyle.end_size,
                 default_size=2000, contain_unfinished_data=False, level=TradingLevel.LEVEL_1DAY,
                 one_shot=True) -> None:
        super().__init__(security_type, exchanges, codes, batch_size, force_update, sleeping_time, fetching_style,
                         default_size, contain_unfinished_data, level, one_shot)

        self.current_factors = {}
        for security_item in self.securities:
            kdata = get_kdata(security_id=security_item.id, provider=self.provider,
                              level=self.level.value, order=StockDayKdata.timestamp.desc(),
                              limit=1,
                              return_type='domain',
                              session=self.session)
            if kdata:
                self.current_factors[security_item.id] = kdata[0].factor
                self.logger.info('{} latest factor:{}'.format(security_item.id, kdata[0].factor))

        auth(JQ_ACCOUNT, JQ_PASSWD)
github zvtvz / zvt / zvt / recorders / recorder.py View on Github external
def __init__(self, security_type=SecurityType.stock, exchanges=['sh', 'sz'], codes=None, batch_size=10,
                 force_update=False, sleeping_time=5, fetching_style=TimeSeriesFetchingStyle.end_size,
                 default_size=2000, contain_unfinished_data=False, level=TradingLevel.LEVEL_1DAY,
                 one_shot=False, kdata_use_begin_time=False) -> None:
        super().__init__(security_type, exchanges, codes, batch_size, force_update, sleeping_time, fetching_style,
                         default_size, one_shot)

        self.level = level
        # FIXME:should remove unfinished data when recording,always set it to False now
        self.contain_unfinished_data = contain_unfinished_data
        self.kdata_use_begin_time = kdata_use_begin_time
github zvtvz / zvt / zvt / trader / examples / coin_trader.py View on Github external
codes=codes,
                                             start_timestamp=start_timestamp,
                                             end_timestamp=end_timestamp,
                                             level=TradingLevel.LEVEL_1MIN,
                                             provider='ccxt'))
        self.selectors.append(my_selector)

    @classmethod
    def get_constructor_meta(cls):
        meta = super().get_constructor_meta()
        meta.metas['security_type'] = marshal_object_for_ui(cls.security_type)
        return meta


if __name__ == '__main__':
    SingleCoinTrader(level=TradingLevel.LEVEL_1MIN, start_timestamp='2019-06-29', end_timestamp='2019-07-01',
                     real_time=True).run()
github zvtvz / zvt / zvt / trader / examples / coin_trader.py View on Github external
def init_selectors(self, security_list, security_type, exchanges, codes, start_timestamp, end_timestamp):
        my_selector = TargetSelector(security_list=security_list, security_type=security_type, exchanges=exchanges,
                                     codes=codes, start_timestamp=start_timestamp,
                                     end_timestamp=end_timestamp)
        # add the factors
        my_selector \
            .add_filter_factor(CrossMaFactor(security_list=security_list,
                                             security_type=security_type,
                                             exchanges=exchanges,
                                             codes=codes,
                                             start_timestamp=start_timestamp,
                                             end_timestamp=end_timestamp,
                                             level=TradingLevel.LEVEL_1MIN,
                                             provider='ccxt'))
        self.selectors.append(my_selector)
github zvtvz / zvt / zvt / recorders / recorder.py View on Github external
order=self.data_schema.timestamp.desc(), limit=1,
                                 return_type='domain',
                                 session=self.session)

        if latest_record:
            latest_timestamp = latest_record[0].timestamp
        else:
            latest_timestamp = security_item.timestamp

        if not latest_timestamp:
            return latest_timestamp, None, self.default_size, None

        current_time = pd.Timestamp.now()
        time_delta = current_time - latest_timestamp

        if self.level == TradingLevel.LEVEL_1DAY:
            if is_same_date(current_time, latest_timestamp):
                return latest_timestamp, None, 0, None
            return latest_timestamp, None, time_delta.days + 1, None

        close_hour, close_minute = get_close_time(security_item.id)

        # to today,check closing time
        # 0,0 means never stop,e.g,coin
        if (close_hour != 0 and close_minute != 0) and time_delta.days == 0:
            if latest_timestamp.hour == close_hour and latest_timestamp.minute == close_minute:
                return latest_timestamp, None, 0, None

        if self.kdata_use_begin_time:
            touching_timestamp = latest_timestamp + pd.Timedelta(seconds=self.level.to_second())
        else:
            touching_timestamp = latest_timestamp
github zvtvz / zvt / zvt / trader / multiple_level_trader.py View on Github external
def init_selectors(self, security_list, security_type, exchanges, codes, start_timestamp, end_timestamp):
        self.selectors = []

        ma_1d_selector = TechnicalSelector(security_list=security_list, security_type=security_type,
                                           exchanges=exchanges, codes=codes,
                                           start_timestamp=start_timestamp,
                                           end_timestamp=end_timestamp, level=TradingLevel.LEVEL_15MIN,
                                           provider='ccxt')
        ma_1d_selector.run()

        ma_1h_selector = TechnicalSelector(security_list=security_list, security_type=security_type,
                                           exchanges=exchanges, codes=codes,
                                           start_timestamp=start_timestamp,
                                           end_timestamp=end_timestamp, level=TradingLevel.LEVEL_5MIN,
                                           provider='ccxt')
        ma_1h_selector.run()

        # finance_selector = FundamentalSelector(security_type=security_type, exchanges=exchanges, codes=codes,
        #                                        start_timestamp=start_timestamp, end_timestamp=end_timestamp)
        # finance_selector.run()

        self.selectors.append(ma_1d_selector)
        self.selectors.append(ma_1h_selector)
github zvtvz / zvt / zvt / trader / examples / coin_trader.py View on Github external
def __init__(self,
                 security: str = 'coin_binance_EOS/USDT',
                 start_timestamp: Union[str, pd.Timestamp] = '2018-06-01',
                 end_timestamp: Union[str, pd.Timestamp] = '2019-06-30',
                 provider: Union[str, Provider] = 'ccxt',
                 level: Union[str, TradingLevel] = TradingLevel.LEVEL_1DAY,
                 trader_name: str = None,
                 real_time: bool = False,
                 kdata_use_begin_time: bool = True) -> None:
        super().__init__([security], SecurityType.coin, None, None, start_timestamp, end_timestamp, provider,
                         level, trader_name, real_time, kdata_use_begin_time=kdata_use_begin_time)