minitrade.datasource¤
minitrade.datasource.base
¤
QuoteSource
¤
Bases: ABC
QuoteSource is a base class that returns quote data for instruments. Extend this class to add a concrete implementation to get data from particular data source.
At a minimum, the following methods should be implemented:
class MyQuoteSource(QuoteSource):
def _ticker_timezone(self, ticker: str) -> str:
pass
def _ticker_calendar(self, ticker: str) -> str:
pass
def _daily_bar(self, ticker: str, start: str, end: str) -> pd.DataFrame:
pass
SYSTEM_SOURCES
class-attribute
instance-attribute
¤
SYSTEM_SOURCES = sorted(['Yahoo', 'EODHistoricalData', 'TwelveData', 'Alpaca', 'EastMoney', 'Tiingo', 'InteractiveBrokers', 'CboeIndex', 'CboeFutures'])
A list of names for supported quote sources as input to QuoteSource.get_source()
.
_daily_bar
abstractmethod
¤
Same as daily_bar()
for only one ticker.
This should be overridden in subclass to provide an implemention.
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe with columns 'Open', 'High', 'Low', 'Close', 'Volume' indexed by datetime |
_minute_bar
abstractmethod
¤
Same as minute_bar()
for only one ticker.
This should be overridden in subclass to provide an implemention.
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe with columns 'Open', 'High', 'Low', 'Close', 'Volume' indexed by datetime |
_spot
abstractmethod
¤
_spot(tickers: list[str]) -> Series
Return spot prices for a list of tickers.
_ticker_calendar
abstractmethod
¤
Get the calendar name of a ticker as recognized by pandas_market_calendars
.
_ticker_timezone
abstractmethod
¤
Get the timezone of a ticker.
daily_bar
¤
daily_bar(tickers: list[str] | str, start: str = '2000-01-01', end: str = None, align: bool = True, normalize: bool = False, num_workers: int = 1) -> DataFrame
Read end-of-day OHLCV data for a list of tickers
starting from start
date and ending on end
date (both inclusive).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tickers |
list[str] | str
|
Tickers as a list of string or a comma separated string without space |
required |
start |
str
|
Start date in string format 'YYYY-MM-DD' |
'2000-01-01'
|
end |
str
|
End date in string format 'YYYY-MM-DD' |
None
|
align |
bool
|
True to align data to start on the same date, i.e. drop leading days when not all tickers have data available. |
True
|
normalize |
bool
|
True to normalize the close price on the start date to 1 for all tickers and scale all price data accordingly. |
False
|
num_workers |
int
|
Number of parallel workers to use for fetching data. |
1
|
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe with 2-level columns, first level being the tickers, and the second level being columns 'Open', 'High', 'Low', 'Close', 'Volume'. The dataframe is indexed by datetime. |
get_source
staticmethod
¤
get_source(name: str, **kwargs: dict[str, Any]) -> QuoteSource
Get quote source by name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Quote source name |
required |
kwargs |
dict[str, Any]
|
Keyword arguments to be passed to the quote source constructor |
{}
|
Returns:
Type | Description |
---|---|
QuoteSource
|
A QuoteSource instance |
Raises:
Type | Description |
---|---|
ValueError
|
If the asked data source is not supported |
minute_bar
¤
minute_bar(tickers: list[str] | str, start: str = None, end: str = None, interval: int = 1, num_workers: int = 1) -> DataFrame
Read minute OHLCV data for a ticker
starting from start
date and ending on end
date (both inclusive).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tickers |
list[str] | str
|
Tickers as a list or comma-separated string |
required |
start |
str
|
Start date in string format 'YYYY-MM-DD' |
None
|
end |
str
|
End date in string format 'YYYY-MM-DD' |
None
|
interval |
int
|
Interval in minutes |
1
|
num_workers |
int
|
Number of parallel workers to use for fetching data. |
1
|
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe with columns 'Open', 'High', 'Low', 'Close', 'Volume' indexed by datetime |
monthly_bar
¤
monthly_bar(tickers: list[str] | str, start: str = '2020-01-01', end: str = None, align: bool = True, normalize: bool = False, num_workers: int = 1) -> DataFrame
Read monthly OHLCV data for a list of tickers
starting from start
date and ending on end
date (both inclusive).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tickers |
list[str] | str
|
Tickers as a list of string or a comma separated string without space |
required |
start |
str
|
Start date in string format 'YYYY-MM' |
'2020-01-01'
|
end |
str
|
End date in string format 'YYYY-MM' |
None
|
align |
bool
|
True to align data to start on the same date, i.e. drop leading days when not all tickers have data available. |
True
|
normalize |
bool
|
True to normalize the close price on the start date to 1 for all tickers and scale all price data accordingly. |
False
|
num_workers |
int
|
Number of parallel workers to use for fetching data. |
1
|
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe with 2-level columns, first level being the tickers, and the second level being columns 'Open', 'High', 'Low', 'Close', 'Volume'. The dataframe is indexed by last day of month. |
spot
¤
spot(tickers: list[str] | str) -> Series
Read current quote for a list of tickers
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tickers |
list[str] | str
|
Tickers as a list of string or a comma separated string without space |
required |
Returns:
Type | Description |
---|---|
Series
|
Current quotes indexed by ticker as a pandas Series |