Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

#
alpaca module

Module with AlpacaData.

## AlpacaData class

    AlpacaData(
        wrapper,
        data,
        single_key=True,
        classes=None,
        level_name=None,
        fetch_kwargs=None,
        returned_kwargs=None,
        last_index=None,
        delisted=None,
        tz_localize=None,
        tz_convert=None,
        missing_index=None,
        missing_columns=None,
        **kwargs
    )

Data class for fetching from Alpaca.

See https://github.com/alpacahq/alpaca-py for API.

See AlpacaData.fetch_symbol() for arguments.

Usage

- Set up the API key globally (optional for crypto):

    >>> from vectorbtpro import *

    >>> vbt.AlpacaData.set_custom_settings(
    ...     client_config=dict(
    ...         api_key="YOUR_KEY",
    ...         secret_key="YOUR_SECRET"
    ...     )
    ... )

- Pull stock data:

    >>> data = vbt.AlpacaData.pull(
    ...     "AAPL",
    ...     start="2021-01-01",
    ...     end="2022-01-01",
    ...     timeframe="1 day"
    ... )

- Pull crypto data:

    >>> data = vbt.AlpacaData.pull(
    ...     "BTCUSD",
    ...     client_type="crypto",
    ...     start="2021-01-01",
    ...     end="2022-01-01",
    ...     timeframe="1 day"
    ... )

Superclasses

- Analyzable
- AttrResolverMixin
- BaseDataMixin
- Cacheable
- Chainable
- Comparable
- Configured
- CustomData
- Data
- DataWithFeatures
- ExtPandasIndexer
- HasSettings
- IndexingBase
- OHLCDataMixin
- PandasIndexer
- Pickleable
- PlotsBuilderMixin
- Prettified
- RemoteData
- StatsBuilderMixin
- Wrapping

Inherited members

- AttrResolverMixin.deep_getattr()
- AttrResolverMixin.post_resolve_attr()
- AttrResolverMixin.pre_resolve_attr()
- AttrResolverMixin.resolve_attr()
- AttrResolverMixin.resolve_shortcut_attr()
- BaseDataMixin.assert_has_feature()
- BaseDataMixin.assert_has_symbol()
- BaseDataMixin.get_feature()
- BaseDataMixin.get_feature_idx()
- BaseDataMixin.get_symbol()
- BaseDataMixin.get_symbol_idx()
- BaseDataMixin.has_feature()
- BaseDataMixin.has_multiple_keys()
- BaseDataMixin.has_symbol()
- BaseDataMixin.prepare_key()
- BaseDataMixin.select_features()
- BaseDataMixin.select_symbols()
- Cacheable.get_ca_setup()
- Chainable.pipe()
- Configured.copy()
- Configured.equals()
- Configured.get_writeable_attrs()
- Configured.prettify()
- Configured.resolve_merge_kwargs()
- Configured.update_config()
- CustomData.get_custom_setting()
- CustomData.get_custom_settings()
- CustomData.has_custom_setting()
- CustomData.has_custom_settings()
- CustomData.key_match()
- CustomData.resolve_custom_setting()
- CustomData.set_custom_settings()
- Data.add()
- Data.add_column()
- Data.add_feature()
- Data.add_key()
- Data.add_symbol()
- Data.align_columns()
- Data.align_data()
- Data.align_index()
- Data.build_feature_config_doc()
- Data.check_dict_type()
- Data.column_stack()
- Data.concat()
- Data.dropna()
- Data.fetch()
- Data.fetch_feature()
- Data.fix_data_dict_type()
- Data.fix_dict_types_in_kwargs()
- Data.from_csv()
- Data.from_data()
- Data.from_data_str()
- Data.from_duckdb()
- Data.from_feather()
- Data.from_hdf()
- Data.from_parquet()
- Data.from_sql()
- Data.get()
- Data.get_base_setting()
- Data.get_base_settings()
- Data.get_feature_wrapper()
- Data.get_key_wrapper()
- Data.get_keys()
- Data.get_symbol_wrapper()
- Data.has_base_setting()
- Data.has_base_settings()
- Data.has_key_dict()
- Data.indexing_func()
- Data.invert()
- Data.invert_data()
- Data.merge()
- Data.modify_state()
- Data.override_feature_config_doc()
- Data.plot()
- Data.prepare_dt()
- Data.prepare_dt_column()
- Data.prepare_dt_index()
- Data.prepare_tzaware_index()
- Data.pull()
- Data.realign()
- Data.remove()
- Data.remove_columns()
- Data.remove_features()
- Data.remove_keys()
- Data.remove_symbols()
- Data.rename()
- Data.rename_columns()
- Data.rename_features()
- Data.rename_in_dict()
- Data.rename_keys()
- Data.rename_symbols()
- Data.replace()
- Data.resample()
- Data.resolve_base_setting()
- Data.resolve_columns()
- Data.resolve_features()
- Data.resolve_key_arg()
- Data.resolve_keys()
- Data.resolve_keys_meta()
- Data.resolve_symbols()
- Data.row_stack()
- Data.run()
- Data.select()
- Data.select_classes()
- Data.select_columns()
- Data.select_delisted()
- Data.select_feature_from_dict()
- Data.select_feature_idxs()
- Data.select_feature_kwargs()
- Data.select_fetch_kwargs()
- Data.select_from_dict()
- Data.select_key_from_dict()
- Data.select_key_kwargs()
- Data.select_keys()
- Data.select_last_index()
- Data.select_returned_kwargs()
- Data.select_run_func_args()
- Data.select_run_func_kwargs()
- Data.select_symbol_from_dict()
- Data.select_symbol_idxs()
- Data.select_symbol_kwargs()
- Data.set_base_settings()
- Data.sql()
- Data.switch_class()
- Data.to_csv()
- Data.to_duckdb()
- Data.to_feather()
- Data.to_feature_oriented()
- Data.to_hdf()
- Data.to_parquet()
- Data.to_sql()
- Data.to_symbol_oriented()
- Data.transform()
- Data.try_fetch_feature()
- Data.try_fetch_symbol()
- Data.try_run()
- Data.try_update_feature()
- Data.try_update_symbol()
- Data.update()
- Data.update_classes()
- Data.update_feature()
- Data.update_fetch_kwargs()
- Data.update_returned_kwargs()
- Data.update_symbol()
- Data.use_feature_config_of()
- HasSettings.get_path_setting()
- HasSettings.get_path_settings()
- HasSettings.get_setting()
- HasSettings.get_settings()
- HasSettings.has_path_setting()
- HasSettings.has_path_settings()
- HasSettings.has_setting()
- HasSettings.has_settings()
- HasSettings.reset_settings()
- HasSettings.resolve_setting()
- HasSettings.resolve_settings_paths()
- HasSettings.set_settings()
- IndexingBase.indexing_setter_func()
- OHLCDataMixin.get_daily_log_returns()
- OHLCDataMixin.get_daily_returns()
- OHLCDataMixin.get_drawdowns()
- OHLCDataMixin.get_log_returns()
- OHLCDataMixin.get_returns()
- OHLCDataMixin.get_returns_acc()
- PandasIndexer.xs()
- Pickleable.decode_config()
- Pickleable.decode_config_node()
- Pickleable.dumps()
- Pickleable.encode_config()
- Pickleable.encode_config_node()
- Pickleable.file_exists()
- Pickleable.getsize()
- Pickleable.load()
- Pickleable.loads()
- Pickleable.resolve_file_path()
- Pickleable.save()
- PlotsBuilderMixin.build_subplots_doc()
- PlotsBuilderMixin.override_subplots_doc()
- PlotsBuilderMixin.plots()
- RemoteData.classes
- RemoteData.close
- RemoteData.cls_dir
- RemoteData.column_only_select
- RemoteData.column_type
- RemoteData.columns
- RemoteData.config
- RemoteData.daily_log_returns
- RemoteData.daily_returns
- RemoteData.data
- RemoteData.delisted
- RemoteData.dict_type
- RemoteData.drawdowns
- RemoteData.feature_classes
- RemoteData.feature_config
- RemoteData.feature_oriented
- RemoteData.feature_wrapper
- RemoteData.features
- RemoteData.fetch_kwargs
- RemoteData.freq
- RemoteData.group_select
- RemoteData.has_ohlc
- RemoteData.has_ohlcv
- RemoteData.high
- RemoteData.hlc3
- RemoteData.iloc
- RemoteData.index
- RemoteData.indexing_kwargs
- RemoteData.key_wrapper
- RemoteData.keys
- RemoteData.last_index
- RemoteData.level_name
- RemoteData.loc
- RemoteData.log_returns
- RemoteData.low
- RemoteData.missing_columns
- RemoteData.missing_index
- RemoteData.ndim
- RemoteData.ohlc
- RemoteData.ohlc4
- RemoteData.ohlcv
- RemoteData.open
- RemoteData.plots_defaults
- RemoteData.range_only_select
- RemoteData.rec_state
- RemoteData.returned_kwargs
- RemoteData.returns
- RemoteData.returns_acc
- RemoteData.self_aliases
- RemoteData.shape
- RemoteData.shape_2d
- RemoteData.single_feature
- RemoteData.single_key
- RemoteData.single_symbol
- RemoteData.stats_defaults
- RemoteData.symbol_classes
- RemoteData.symbol_oriented
- RemoteData.symbol_wrapper
- RemoteData.symbols
- RemoteData.trade_count
- RemoteData.tz_convert
- RemoteData.tz_localize
- RemoteData.volume
- RemoteData.vwap
- RemoteData.wrapper
- RemoteData.xloc
- StatsBuilderMixin.build_metrics_doc()
- StatsBuilderMixin.override_metrics_doc()
- StatsBuilderMixin.stats()
- Wrapping.regroup()
- Wrapping.resolve_column_stack_kwargs()
- Wrapping.resolve_row_stack_kwargs()
- Wrapping.resolve_self()
- Wrapping.resolve_stack_kwargs()
- Wrapping.select_col()
- Wrapping.select_col_from_obj()
- Wrapping.split()

### fetch_symbol class method

    AlpacaData.fetch_symbol(
        symbol,
        client=None,
        client_type=None,
        client_config=None,
        start=None,
        end=None,
        timeframe=None,
        tz=None,
        adjustment=None,
        feed=None,
        limit=None
    )

Override Data.fetch_symbol() to fetch a symbol from Alpaca.

Args

`symbol` :`str`
  Symbol.
`client` :`alpaca.common.rest.RESTClient`

  Client.

  See AlpacaData.resolve_client().

`client_type` :`str`

  Client type.

  See AlpacaData.resolve_client().

`client_config` :`dict`

  Client config.

  See AlpacaData.resolve_client().

`start` :`any`

  Start datetime.

  See to_tzaware_datetime().

`end` :`any`

  End datetime.

  See to_tzaware_datetime().

`timeframe` :`str`

  Timeframe.

  Allows human-readable strings such as "15 minutes".

`tz` :`any`

  Timezone.

  See to_timezone().

`adjustment` :`str`

  Specifies the corporate action adjustment for the returned bars.

  Options are: "raw", "split", "dividend" or "all". Default is "raw".

`feed` :`str`

  The feed to pull market data from.

  This is either "iex", "otc", or "sip". Feeds "sip" and "otc" are only available to those with a subscription. Default is "iex" for free plans and "sip" for paid.

`limit` :`int`
  The maximum number of returned items.

For defaults, see `custom.alpaca` in data. Global settings can be provided per exchange id using the `exchanges` dictionary.

### list_symbols class method

    AlpacaData.list_symbols(
        pattern=None,
        use_regex=False,
        status=None,
        asset_class=None,
        exchange=None,
        trading_client=None,
        client_config=None
    )

List all symbols.

Uses CustomData.key_match() to check each symbol against `pattern`.

Arguments `status`, `asset_class`, and `exchange` can be strings, such as `asset_class="crypto"`. For possible values, take a look into `alpaca.trading.enums`.

Note

If you get an authorization error, make sure that you either enable or disable the `paper` flag in `client_config` depending upon the account whose credentials you used. By default, the credentials are assumed to be of a live trading account (`paper=False`).

### resolve_client class method

    AlpacaData.resolve_client(
        client=None,
        client_type=None,
        **client_config
    )

Resolve the client.

If provided, must be of the type `alpaca.data.historical.CryptoHistoricalDataClient` for `client_type="crypto"` and `alpaca.data.historical.StockHistoricalDataClient` for `client_type="stocks"`. Otherwise, will be created using `client_config`.

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings