AutoData#
from autotrader import AutoData
AutoData is the unified data retrieval module of AutoTrader.
It enables fetching historical and live price data from the
feeds of the supported brokers (where
available). You can also use AutoData
to load locally stored
data. To configure AutoData, you must provide a data_config
dictionary, specifying at least the data source. If you do
not provide this dictionary, AutoData will assume you will
be using local data.
AutoData has three main public methods:
fetch
: to fetch historical OHLC dataL1
: to get a snapshot of level 1 dataL2
: to get a snapshot of level 2 data
AutoData Class#
The AutoData
class is optionally initialised with a configuration
dictionary (either manually constructed, or the output of the utility
function get_data_config
. This dictionary
contains any authentication information related to the data feed being
used. Some samples are provided below.
data_config = {
'data_source': 'ccxt',
'exchange': 'binance'
}
ad = AutoData(data_config)
data_config = {
'data_source': 'dydx',
}
ad = AutoData(data_config)
data_config = {
'data_source': "oanda",
'API': "api-fxtrade.oanda.com",
'ACCESS_TOKEN': "xxx-yyy",
'PORT': 443,
'ACCOUNT_ID': "xxx-xxx-xxxxxxxx-xxx",
}
ad = AutoData(data_config)
Fetch historical OHLC data#
To fetch OHLC price data, use the fetch
method.
- AutoData.fetch(instrument: str, granularity: str | None = None, count: int | None = None, start_time: datetime | None = None, end_time: datetime | None = None, *args, **kwargs) DataFrame #
Unified OHLC data retrieval api.
- Parameters:
instrument (str, list) – The instrument to fetch data for, or a list of instruments.
granularity (str) – The granularity of the data to fetch.
count (int, optional) – The number of OHLC bars to fetch. The default is None.
start_time (datetime, optional) – The start date of the data to fetch. The default is None.
end_time (datetime, optional) – The end date of the data to fetch. The default is None.
- Returns:
data – The OHLC data.
- Return type:
pd.DataFrame, dict[pd.DataFrame]
Get level 1 data#
To retrieve a snapshot of the current level 1 data, use the
L1
method.
- AutoData.L1(instrument=None, *args, **kwargs)#
Unified level 1 data retrieval api.
Get level 2 data#
To retrieve a snapshot of the current level 2 data, use the
L2
method.
- AutoData.L2(instrument=None, *args, **kwargs)#
Unified level 2 data retrieval api.
Accessing exchange endpoints#
If you wish to access an endpoint of the feed-specific API, you can
do so through the AutoData.api
attribute. This attribute gets created
when you instantiate AutoData with the data_config
dictionary.