AlpacaDataProvider

class qf_lib.data_providers.alpaca_py.alpaca_data_provider.AlpacaDataProvider(timer: Optional[Timer] = None, api_key: Optional[str] = None, secret_key: Optional[str] = None, oauth_token: Optional[str] = None, use_basic_auth: bool = False)[source]

Bases: AbstractPriceDataProvider

Methods:

get_history(tickers, fields, start_date[, ...])

Gets historical attributes (fields) of different securities (tickers).

price_field_to_str_map(*args)

Method has to be implemented in each data provider in order to be able to use get_price.

supported_ticker_types()

Returns classes of tickers which are supported by this DataProvider.

get_history(tickers: Union[Ticker, Sequence[Ticker]], fields: Union[None, str, Sequence[str]], start_date: datetime, end_date: datetime = None, frequency: Frequency = None, look_ahead_bias: bool = False, **kwargs) Union[QFSeries, QFDataFrame, QFDataArray][source]

Gets historical attributes (fields) of different securities (tickers).

Parameters:
  • tickers (YFinanceTicker, Sequence[YFinanceTicker]) – tickers for securities which should be retrieved

  • fields (None, str, Sequence[str]) – fields of securities which should be retrieved.

  • start_date (datetime) – date representing the beginning of historical period from which data should be retrieved

  • end_date (datetime) – date representing the end of historical period from which data should be retrieved; if no end_date was provided, by default the current date will be used.

  • frequency (Frequency) – frequency of the data. This data provider supports Monthly, Weekly, Daily frequencies along with intraday frequencies at the following intervals: 60 and 1 minute. It is important to highlight that in order to match the behaviour of other data providers, in case of intraday frequency, the end_date bar is not included in the output.

  • look_ahead_bias (bool) – if set to False, the look-ahead bias will be taken care of to make sure no future data is returned

Returns:

If possible the result will be squeezed, so that instead of returning a QFDataArray, data of lower dimensionality will be returned. The results will be either a QFDataArray (with 3 dimensions: date, ticker, field), a QFDataFrame (with 2 dimensions: date, ticker or field; it is also possible to get 2 dimensions ticker and field if single date was provided), a QFSeries (with 1 dimensions: date) or a float / str (in case if a single ticker, field and date were provided). If no data is available in the database or a non existing ticker was provided an empty structure (nan, QFSeries, QFDataFrame or QFDataArray) will be returned.

Return type:

QFSeries, QFDataFrame, QFDataArray, float, str

price_field_to_str_map(*args) Dict[PriceField, str][source]

Method has to be implemented in each data provider in order to be able to use get_price. Returns dictionary containing mapping between PriceField and corresponding string that has to be used by get_history method to get appropriate type of price series.

Returns:

mapping between PriceFields and corresponding strings

Return type:

Dict[PriceField, str]

supported_ticker_types() Set[Type[Ticker]][source]

Returns classes of tickers which are supported by this DataProvider.