當前位置: 首頁>>代碼示例>>Python>>正文


Python base_data_source.BaseDataSource方法代碼示例

本文整理匯總了Python中rqalpha.data.base_data_source.BaseDataSource方法的典型用法代碼示例。如果您正苦於以下問題:Python base_data_source.BaseDataSource方法的具體用法?Python base_data_source.BaseDataSource怎麽用?Python base_data_source.BaseDataSource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rqalpha.data.base_data_source的用法示例。


在下文中一共展示了base_data_source.BaseDataSource方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from rqalpha.data import base_data_source [as 別名]
# 或者: from rqalpha.data.base_data_source import BaseDataSource [as 別名]
def __init__(self, data_bundle_path=None):
        default_bundle_path = os.path.abspath(os.path.expanduser('~/.rqalpha'))
        if data_bundle_path is None:
            data_bundle_path = default_bundle_path
        else:
            data_bundle_path = os.path.abspath(os.path.join(data_bundle_path, '.'))

        data_bundle_path = data_bundle_path + '/bundle'

        self._data_bundle_path = data_bundle_path

        # basic_system_log.debug('rqalpha data bundle path: ' + data_bundle_path)
        if not os.path.exists(data_bundle_path):
            self.update(skip_last_date_check=True)

        from rqalpha.data.base_data_source import BaseDataSource
        data_source = BaseDataSource(data_bundle_path)
        super(DataSource, self).__init__(data_source)

        self._last_date_date = None
        self.get_data_last_date()
        # basic_system_log.debug('rqalpha data bundle date: ' + self._last_date_date.strftime('%Y-%m-%d')) 
開發者ID:SixQuant,項目名稱:rqalpha-data,代碼行數:24,代碼來源:datasource.py

示例2: __init__

# 需要導入模塊: from rqalpha.data import base_data_source [as 別名]
# 或者: from rqalpha.data.base_data_source import BaseDataSource [as 別名]
def __init__(self, path):
        """
        數據源接口。 通過 :class:`DataProxy` 進一步進行了封裝,向上層提供更易用的接口。
        在擴展模塊中,可以通過調用 ``env.set_data_source`` 來替換默認的數據源。可參考 :class:`BaseDataSource`。
        """
        self._env = Environment.get_instance()
        self.conn = pymongo.MongoClient(path, 27017)

        # Day DB
        self.stocks_days_db = self.conn.InplusTrader_Stocks_Day_Db
        self.indexes_days_db = self.conn.InplusTrader_Indexes_Day_Db
        self.futures_days_db = self.conn.InplusTrader_Futures_Day_Db
        self.funds_days_db = self.conn.InplusTrader_Funds_Day_Db
        # Minute DB
        self.stocks_mins_db = self.conn.InplusTrader_Stocks_Min_Db
        self.futures_mins_db = self.conn.InplusTrader_Futures_Min_Db
        # Tick DB
        self.stocks_tick_db = self.conn.InplusTrader_Stocks_Tick_Db
        self.futures_tick_db = self.conn.InplusTrader_Futures_Tick_Db

        self.instruments_db = self.conn.InplusTrader_Instruments_Db
        self.adjusted_dividends_db = self.conn.InplusTrader_Adjusted_Dividents_Db
        self.original_dividends_db = self.conn.InplusTrader_Original_Dividents_Db
        self.trading_dates_db = self.conn.InplusTrader_Trading_Dates_Db
        self.yield_curve_db = self.conn.InplusTrader_Yield_Curve_Db
        self.st_stock_days_db = self.conn.InplusTrader_St_Stocks_Day_Db
        self.suspend_days_db = self.conn.InplusTrader_Suspend_Day_Db

        self._day_bars = [self.stocks_days_db, self.indexes_days_db, self.futures_days_db, self.funds_days_db]
        self._min_bars = [self.stocks_mins_db, self.futures_mins_db]
        self._tick_bars = [self.stocks_tick_db, self.futures_tick_db]
        self._instruments = self.instruments_db
        self._adjusted_dividends = self.adjusted_dividends_db
        self._original_dividends = self.original_dividends_db
        self._trading_dates = self.trading_dates_db
        self._yield_curve = self.yield_curve_db
        self._st_stock_days = self.st_stock_days_db
        self._suspend_days = self.suspend_days_db 
開發者ID:zhengwsh,項目名稱:InplusTrader_Linux,代碼行數:40,代碼來源:inplus_data_source.py

示例3: quotation_server

# 需要導入模塊: from rqalpha.data import base_data_source [as 別名]
# 或者: from rqalpha.data.base_data_source import BaseDataSource [as 別名]
def quotation_server(redis_url):
    """
    [sys_stock_realtime] quotation service, download market data into redis

    Multiple RQAlpha instance can use single market data service.
    """
    import redis
    import time
    import json

    from .utils import get_realtime_quotes

    redis_client = redis.from_url(redis_url)

    from rqalpha.data.data_proxy import DataProxy
    # ͨ�� parse_config ���� ��ȡ Ĭ�� data_bundle ������
    # ���� parse_config ��������ü�飬���û������ account ����ʾ���������������һ����Ʊ��ʼ�ʽ�����֤��ȷ��ȡĬ�ϲ�������
    config = parse_config({
        'base': {
            'accounts': {
                'stock': 10000
            }
        }
    })

    data_source = BaseDataSource(config.base.data_bundle_path)
    data_proxy = DataProxy(data_source)

    order_book_id_list = sorted(ins.order_book_id for ins in data_proxy.all_instruments("CS"))

    def record_market_data(total_df):
        for order_book_id, item in total_df.iterrows():
            redis_client[order_book_id] = json.dumps(item.to_dict())

    retry_cnt = 0
    while True:
        try:
            total_df = get_realtime_quotes(order_book_id_list, include_limit=True)
        except (OSError, IOError) as e:
            system_log.exception("get_realtime_quotes socket error. retry {} {}", retry_cnt, e)
            time.sleep(retry_cnt * 2)
            retry_cnt += 1
            continue
        system_log.info("Fetching snapshots, size {}", len(total_df))
        record_market_data(total_df)
        time.sleep(1)
        retry_cnt = 0 
開發者ID:DingTobest,項目名稱:Rqalpha-myquant-learning,代碼行數:49,代碼來源:__init__.py

示例4: __init__

# 需要導入模塊: from rqalpha.data import base_data_source [as 別名]
# 或者: from rqalpha.data.base_data_source import BaseDataSource [as 別名]
def __init__(self, start=start_default, end=end_default, path=RQALPHA_BUNDLE_PATH):
        super(RqalphaAStockTradingCalendar, self).__init__()
        self._data_source = BaseDataSource(path)
        _all_days = self._data_source.get_trading_calendar()
        _all_days = _all_days[_all_days.slice_indexer(start, end)]
        # `DatetimeIndex`s of standard opens/closes for each day.
        self._opens = days_at_time(_all_days, self.open_time, self.tz,
                                   self.open_offset)
        self._closes = days_at_time(
            _all_days, self.close_time, self.tz, self.close_offset
        )

        # In pandas 0.16.1 _opens and _closes will lose their timezone
        # information. This looks like it has been resolved in 0.17.1.
        # http://pandas.pydata.org/pandas-docs/stable/whatsnew.html#datetime-with-tz  # noqa
        self.schedule = pd.DataFrame(
            index=_all_days,
            columns=['market_open', 'market_close'],
            data={
                'market_open': self._opens,
                'market_close': self._closes,
            },
            dtype='datetime64[ns]',
        )

        # Simple cache to avoid recalculating the same minute -> session in
        # "next" mode. Analysis of current zipline code paths show that
        # `minute_to_session_label` is often called consecutively with the same
        # inputs.
        self._minute_to_session_label_cache = LRU(1)

        self.market_opens_nanos = self.schedule.market_open.values. \
            astype(np.int64)

        self.market_closes_nanos = self.schedule.market_close.values. \
            astype(np.int64)

        self._trading_minutes_nanos = self.all_minutes.values. \
            astype(np.int64)

        self.first_trading_session = _all_days[0]
        self.last_trading_session = _all_days[-1] 
開發者ID:DingTobest,項目名稱:Rqalpha-myquant-learning,代碼行數:44,代碼來源:trading_calendar.py

示例5: quotation_server

# 需要導入模塊: from rqalpha.data import base_data_source [as 別名]
# 或者: from rqalpha.data.base_data_source import BaseDataSource [as 別名]
def quotation_server(redis_url):
    """
    [stock_realtime] quotation service, download market data into redis

    Multiple RQAlpha instance can use single market data service.
    """
    import redis
    import time
    import json

    from .utils import get_realtime_quotes

    redis_client = redis.from_url(redis_url)

    from rqalpha.environment import Environment
    from rqalpha.data.data_proxy import DataProxy
    # 通過 parse_config 函數 獲取 默認 data_bundle 的配置
    # 由於 parse_config 會進行配置檢查,如果沒有設置 account 會提示報錯,因此隨意設置一個股票初始資金,來保證正確獲取默認參數配置
    config = parse_config({
        'base': {
            'accounts': {
                'stock': 10000
            }
        }
    })

    Environment(config)
    data_source = BaseDataSource(config.base.data_bundle_path)
    data_proxy = DataProxy(data_source)

    order_book_id_list = sorted(ins.order_book_id for ins in data_proxy.all_instruments("CS"))

    def record_market_data(total_df):
        for order_book_id, item in total_df.iterrows():
            redis_client[order_book_id] = json.dumps(item.to_dict())

    retry_cnt = 0
    while True:
        try:
            total_df = get_realtime_quotes(order_book_id_list, include_limit=True)
        except (OSError, IOError) as e:
            system_log.exception("get_realtime_quotes socket error. retry {} {}", retry_cnt, e)
            time.sleep(retry_cnt * 2)
            retry_cnt += 1
            continue
        system_log.info("Fetching snapshots, size {}", len(total_df))
        record_market_data(total_df)
        time.sleep(1)
        retry_cnt = 0 
開發者ID:ricequant,項目名稱:rqalpha-mod-stock-realtime,代碼行數:51,代碼來源:__init__.py


注:本文中的rqalpha.data.base_data_source.BaseDataSource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。