WTDpy

This page lists all functions and classes available of WTDpy.

Submodules

There is only one submodule with one class: WTDpy. Please check the information below on how the code reads.

wtdpy.wtdpy module

WTDpy Packge.

class wtdpy.wtdpy.WTDpy(api_token: str)[source]

Python wrapper for the World Trading Data API.

Parameters

api_token : str
Your personal API token from https://www.worldtradingdata.com/.

Attributes

api_token : str
Your personal API token from https://www.worldtradingdata.com/.
url : str
The base url for requesting the API.

Notes

Create an account on https://www.worldtradingdata.com/ to obtain your API key. It will show on the top of your personal dashboard. You can make 250 API calls per day with the free tier.

Currently supporting:
  • Historical data;
  • Checking if a symbol excists.
get_historical_data(symbol: Union[str, List[str]], date_from: Union[datetime.datetime, str, None] = None, date_to: Union[datetime.datetime, str, None] = None, sort: str = 'asc', output: str = 'dict') → Union[dict, pandas.core.frame.DataFrame][source]

Get the historical data for the given symbol.

Parameters

symbol : str or list of str
A string or list of strings such as “^AEX”, or [“^AEX”, “^DAX”]. The symbols should match the format as shown on the World Trading Data site. You can check https://www.worldtradingdata.com/search to see what data is available at World Trading Data.
date_from : str or datetime
A string representing a date in isoformat (yyyy-mm-dd), a datetime object or None. If no data is provided the earliest date will be requested.
date_to: str or datetime
A string representing a date in isoformat (yyyy-mm-dd), a datetime object or None. If no data is provided the latest date will be requested.
sort: str
A string representing the sorting of the requested data. Either ascending “asc” or descending “desc”.
output: str
A string representing the desired output. Either dict for a python dict or “df” for a pandas DataFrame.

Raises

ValueError
  • If provided symbol is not available.
TypeError
  • If date_from is not a correct string or datetime object
  • If date_to is not a correct string or datetime object
  • If sort is not a correct string
  • If output is not a correct string

Returns

to_return : dict or pd.DataFrame
A dictionary or a pandas DataFrame. If symbol is a list then a dictionary of pandas DataFrames will be returned.
search(query: Union[str, List[str]], number_of_hits: int = 5) → Dict[str, List[dict]][source]

Search the query in the World Trading Data database.

Parameters

query : str or list of str
A string or list of strings such as “Apple computers” or [“Apple computers”, “Microsoft”]. This is similar to manually checking https://www.worldtradingdata.com/search to see what data is available at World Trading Data.
number_of_hits : int
The number of hits that will be returned.

Returns

returned_hits : dict
A dict, with the listed hits based on your search query.
search_available_data(symbol: Union[str, List[str]], list_alternatives: bool = False, number_of_alternatives: int = 1) → Union[bool, List[dict]][source]

Check if the requested data is available.

Parameters

symbol : str or list of str
A string or list of strings such as “^AEX”, or [“^AEX”, “^DAX”]. The symbols should match the format as shown on the World Trading Data site. You can check https://www.worldtradingdata.com/search to see what data is available at World Trading Data.
list_alternatives : bool
If True a list of likely matches is presented
number_of_alternatives : int
The number of alternatives, besides the top hit, that are checked whether or not they match the provided symbol.

Returns

matching_symbols or alternatives : bool or list
A boolean to check whether data is avaible. If list_alternatives is True and a symbol is not found a list with possible alternatives will be returned.