python sdk与www.worldtradingdata.com交互
worldtradingdata的Python项目详细描述
世界贸易数据python sdk
这是一个非正式的sdk。这意味着这份回购协议和作者都没有 与世界贸易数据的关系。此回购协议只是一个简单的工具,旨在使 与rest api集成。
此sdk旨在访问财务数据。因此,作者想强调
您对通过这个sdk获得的任何数据所做的操作是您自己的问题,也是您自己的问题。我接受
对于使用此sdk可能导致的任何损失或问题,绝对不承担任何责任。
我也不对任何数据的准确性负责。
用gnu的话来说(即使这个项目是在mit许可下的),
“本软件绝对不提供保修”
开始
此sdk将要求您拥有一个具有世界贸易数据的帐户(注册 here)
安装
- 确保已安装PIP3或PIP
- 在控制台中
pip3 install worldtradingdata==0.1.1
pip3 install worldtradingdata==0.1.1
然后在python中…
>>> from WorldTradingData import WorldTradingData
>>> my_api_token = get_my_token_from_somewhere_safe()
# provide the api_token once when creating the WorldTradingData instance.
# you do not need to provide the api_token on each request
>>> wtd = WorldTradingData(my_api_token)
>>> wtd.stock_search('AAPL') # will find all your favourite fruity stocks
一般指南
必需的参数应该单独给出,可选的参数应该是 作为字典提供,参数名为键,参数值为值。
例如
使用
执行基本库存搜索
wtd.stock_search('AAPL')
任何在正式文档中是可选查询字符串param的内容都可以在字典中传递 作为第二个论点 (see official docs for full argument reference)。
optional_params = {'output': 'csv', 'currency': 'usd'}
wtd.stock_search('AAPL', optional_params)
方法是根据官方文档中该请求的url路径后缀命名的。
即,如果请求的基url是
https://api.worldtradingdata.com/api/v1
外汇历史请求的最终url是
https://api.worldtradingdata.com/api/v1/forex_history
然后请求的url路径后缀被认为是/forex_history
。
sdk中的所有方法都是根据它们对应的url路径后缀命名的,没有/
。
例如wtd.forex_history(args, in, here)
方法参考
请注意,这个sdk是为官方rest api设计的一个松散包装。 由www.worldtradingdata.com提供。 这意味着它不包括飞行前检查,以确保您提供的参数是正确的。 这提供了更多的灵活性,但这意味着如果提供的格式不正确。 对于sdk,它们将被忽略,并且您得到的结果可能不是您所期望的。
我正在对版本2进行更严格的类型检查。
#注意:“api_token”是自动提供的
实时市场数据
在https://www.worldtradingdata.com/documentation#real-time-market-data
股票和指数实时wtd.stock(symbol: list [, optional_params: dict])
示例more_params = {'output': 'csv'}
wtd.stock(['AAPL', 'GOOG'], more_params)
实时共同基金wtd.mutual_fund(symbol: list [, optional_params: dict])
示例my_symbol_array = ['AAAAX', 'AAADX', 'AAAGX']
wtd.mutual_fund(my_symbol_array)
日内市场数据
在https://www.worldtradingdata.com/documentation#intraday-market-data
股票和指数日内wtd.intraday(symbol: str, interval: int, range: int [, optional_params: dict])
历史市场数据
在https://www.worldtradingdata.com/documentation#historical-market-data
完整历史记录wtd.history(symbol: str [, optional_params: dict])
多个单日历史记录wtd.history_multi_single_day(symbol: str, date: str [, optional_params: dict])
# date should be formatted as 'YYYY-MM-DD'
外汇
在https://www.worldtradingdata.com/documentation#forex-data
实时wtd.forex(base: str)
历史wtd.forex_history(base: str, convert_to: str [, optional_params: dict])
单日历史记录wtd.forex_single_day(base: str, date: str [, optional_params: dict])
搜索股票
在https://www.worldtradingdata.com/documentation#searchingwtd._stock_search(search_term: string [, optional_params: dict])
使用
执行基本库存搜索
wtd.stock_search('AAPL')
任何在正式文档中是查询字符串参数的都可以传递 在可选参数字典中。
optional_params = {'output': 'csv', 'currency': 'usd'}
wtd.stock_search('AAPL', optional_params)