用于tdameritrade api的python库

tdlink的Python项目详细描述


GitHub license

t链接

用于tdameritrade api的python库

所有日期和时间都以UTC为单位。

认证

注意:在使用此库之前,请确保从tdameritrade获取代码或刷新令牌。

按照以下步骤获取代码:

  1. 转到tdameritrade开发者:https://developer.tdameritrade.com/
  2. 登录并转到“我的应用程序”
  3. 创建应用程序。使用http://localhost作为回调URL。
  4. 转到此URL:https://auth.tdameritrade.com/auth?response_type=code&redirect_uri=http://localhost&client_id=[YourAppName]@AMER.OAUTHAP
  5. 输入您的TD凭证并给予预许可
  6. 登录后,您将被重定向到此表单的url https://localhost/?code=[code]
  7. 复制[代码]部分。将其作为参数添加到tdameritrade类。
  8. TDAmeritrade类现在应该可以工作了!

注意:您获得的代码仅在有限的时间内有效。如果过期,请再次执行步骤以获取新代码。

安装

来自PYPI

pip install tdlink

源代码

pip install --upgrade git+git://github.com/ysriram1/tdlink

示例

连接到API
fromtdlinkimportTDlinktd=TDlink(app_key='TRADING123',redirect_uri='http://localhost',code=code,# follow instructions to get the codereturn_raw_response=False# will return formatted df if False, else returns HTTP response)

获取刷新和访问令牌

td.refresh_token# returns refresh tokentd.access_token# returns the access token

注意:您可以保存刷新令牌以创建未来会话,而不是使用代码。

从api获取数据

当前报价

```Python td.获取当前报价(symbol='qq', to_return=['askprice','bidprice','totalvolume']) ```
quote

注意:这也用于选项的价格。

历史数据
td.get_historical_prices(symbol='QQQ',period_type='day',# 'day'period=2,# day: 1, 2, 3, 4, 5, 10* month: 1*, 2, 3, 6 year: 1*, 2, 3, 5, 10, 15, 20 ytd: 1*frequency_type='minute',# day: minute* month: daily, weekly* year: daily, weekly, monthly* ytd: daily, weekly*frequency=5,# minute: 1*, 5, 10, 15, 30 daily: 1* weekly: 1* monthly: 1*start_date='06/03/2019',# mm/dd/yyyystart_time=None,# hh:mm:ssend_date='06/04/2019',end_time=None,extended_hours=True,return_df=True# if False, returns a dictionary instead)
Historical Data

选项链
td.get_options_chain(symbol='QQQ',# symbol of underlying securitystrike=None,# mention a specific strikefrom_date='01/01/2020',# only expirations after this date (mm/dd/yyyy)from_time=None,to_date='01/30/2020',# only expirations before this dateto_time=None,expiry_month='ALL',# option expiry month ALL or JANkind='OTM',# ITM, NTM, OTM, SAK (Strikes Above Market), ALL etc.include_quotes=False,# if FALSE only returns the option names (use get_current_quote() to get value)contract_type='CALL',# CALL, PUTstrikes=5,# number of strikes above or below at-the-money pricestrategy='SINGLE',return_df=True# if False, returns a dictionary instead)
Options Chain

指数的上扬者
td.get_movers_for_index(symbol='DJI',# has to be an index DJI, SPX.X  etcdirection=None,# 'up' or 'down'. if None, returns bothchange=None# 'value' or 'percent'. if None, defaults to percentage)
Top Movers

支持

如果您有任何问题、建议或改进意见,请发电子邮件给我ysriram@umich.edu

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用(BluetoothGattCharacteristic)特性中的数据创建、写入和保存csv文件。getValue()   java如何使用groupBy创建一个值为BigDecimal字段平均值的映射?   日期时间Java将iso_即时格式的字符串转换为日期   java如何检索和显示Android firebase的配置文件?   scala AWSJAVASDK:解压缩大小必须小于262144000字节   要应用于列表的java JSTL if条件   java在3个点之间画一个正方形   Kotlin java抽象类IllegaAccessError   java原语双值相等取决于大小?   java有没有一种方法可以对数据集使用compareTo()方法,而不必遍历数据集的每个元素?   java为什么我发送的每个UDP消息都会改变端口源?   重新选择文件时swing Java JTree冻结   java不知道我的游戏是怎么回事   Motif L&F中自定义组合框渲染器中的Java Swing消失文本   java Trade Me API访问前的OAuth