【问题标题】:How to get the stock option train data with tda-api?如何使用 tda-api 获取股票期权训练数据?
【发布时间】:2021-08-17 08:20:47
【问题描述】:

我已经注册了 tdameritrade 开发者账户并获得了 api 密钥。

curl -X GET --header "Authorization: "    \
"https://api.tdameritrade.com/v1/marketdata/aapl/quotes?apikey=my_tda_api_key"

可以获取aapl的数据如下:

{"AAPL":    {"assetType":"EQUITY","assetMainType":"EQUITY","cusip":"037833100","symbol":"AAPL",     
#omitted all other info        

现在我想用 curl 和我的 api 密钥获得 aapl 的股票期权火车:

curl -X GET --header "Authorization: " "https://api.tdameritrade.com/v1/marketdata/chains?   \
apikey=my_tda_api_key&                                                                           \
symbol=aapl&contractType=all&includeQuotes=false&strategy=single&interval=1&range=all&       \
fromDate=2021-8-14&toDate=2023-8-14&expMonth=all&optionType=all"

我总是得到所有HTTP/1.1 400 Bad Request,在url中尝试了许多不同的参数组合,仍然无法得到正常响应,那么如何解决?

https://developer.tdameritrade.com/option-chains/apis/get/marketdata/chains#

【问题讨论】:

    标签: api curl


    【解决方案1】:
    import requests
    import json
    td_consumer_key = "xxxxxxxxxxxxxxxxxxxxxx"
    base_url = 'https://api.tdameritrade.com/v1/marketdata/chains?\
                &symbol={stock_ticker}&contractType={contract_type}\
                &strike={strike}&fromDate={date}&toDate={date}'    
    endpoint = base_url.format(stock_ticker = 'AAPL',
        contract_type = 'PUT',
        strike = 125,
        date='2021-08-27')    
    page = requests.get(url=endpoint, 
                params={'apikey' : td_consumer_key})    
    content = json.loads(page.content)
    

    【讨论】:

      猜你喜欢
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多