Data Providers

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.

Data provider interface

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.

class dynts.data.DataProvider

Interface class for Data Providers.

code

The string code for the provider. This attribute is obtained from the class name in upper case.

load(symbol, startdate, enddate, logger, backend)

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.

  • field None, a string or alist of string. Fiels 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]}
isconnected()

Return True if data connection is available

allfields(ticker=None)

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.

Available Providers

Dynts is currently shipped with two providers:

  • google finance
  • yahoo finance

To check for registered providers:

>>> from dynts.data import providers
>>> providers.keys()
['GOOGLE', 'YAHOO']

Registering

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']

Table Of Contents

Previous topic

Evaluate Timeseries Expressions

Next topic

Data Loader

This Page