This section deals with loading data from data providers. Data providers populate dynts.dsl.Symbol instances with actual data. For example:
>>> import dynts
>>> ts = dynts.evaluate('YHOO,AMZN')
In this case YAHOO and AMZN are two symbols which a least one of the registered data provider will be able to handle, otherwise an error will occur.
A data provider is a class which derives from dynts.data.DataProvider and is responsable for loading actual data into dynts.dsl.Symbol. A data provider can be a simple web service, your own data source or a professional streaming source.
Interface class for Data Providers.
The string code for the provider. This attribute is obtained from the class name in upper case.
This is the function to implement. It loads the actual data from the data rovider. This function is not called directly, instead it is called by the dynts.data.TimeSerieLoader.load().
ticker string id for the symbol to load (the ticker).
startdate and enddate interval to load.
If None the default field for the provider should load.
It should return either an instance of dynts.TimeSeries or a dictionary of the form:
{'date': [list of dates],
'field1': [list of values for field1],
...
'fieldN': [list of values for field1N]}
Return True if data connection is available
Return a list of all fields available for the providers. The first of the list will be treated as the default field.
Optional web link for a given ticker. Default return None.
Dynts is currently shipped with two providers:
To check for registered providers:
>>> from dynts.data import providers
>>> providers.keys()
['GOOGLE', 'YAHOO']
Let’s say we create a new provider along these lines:
from dynts.data import DataProvider
class MyCustomProvider(DataProvider):
def load(ticker, startdate, enddate, fields, logger):
...
Registration is obtained simply:
>>> from dynts.data import register
>>> register(MyCustomProvider)
>>> providers.keys()
['MYCUSTOMPROVIDER', 'GOOGLE', 'YAHOO']