0

我试图通过在 python 中使用 TDA-API 组合周期类型、周期、频率类型和频率来获得以下时间范围:

3Y:W
1Y:1D
180D:4H
20D:1H
10D:30M
10D:15M
5D:5M
1D:1M

例如,我为 1Y:1D 制作了这个

PeriodType.MONTH,
Period.ONE_YEAR,
FrequencyType.WEEKLY,
Frequency.WEEKLY,

您可以在此链接上找到选项 https://tda-api.readthedocs.io/en/stable/client.html#price-history

编辑-

到目前为止,以下是我发现有效和无效的时间表:

 1. weekly (Works) 
 - PeriodType.YEAR,
 - Period.THREE_YEARS,
 - FrequencyType.WEEKLY,
 - Frequency.WEEKLY

 2. daily (Works)
 - PeriodType.YEAR 
 - Period.ONE_YEAR
 - FrequencyType.DAILY
 - Frequency.DAILY

 3. fourhour (Does Not Work)
 - PeriodType.YEAR 
 - Period.ONE_YEAR
 - FrequencyType.DAILY
 - Frequency.DAILY

 4. twentyhour(Does Not Work)
 - PeriodType.DAY
 - Period.TWENTY_YEARS
 - FrequencyType.MINUTE
 - Frequency.EVERY_SIXTY_MINUTES

 5. thirtymin(Work)
 - PeriodType.DAY
 - Period.TEN_DAYS
 - FrequencyType.MINUTE
 - Frequency.EVERY_THIRTY_MINUTES

 6. fifteenmin(Works)
 - PeriodType.DAY
 - Period.FIVE_DAYS
 - FrequencyType.MINUTE
 - Frequency.EVERY_FIFTEEN_MINUTES

 7. fivemin(Works)
 - PeriodType.DAY
 - Period.FIVE_DAYS
 - FrequencyType.MINUTE
 - Frequency.EVERY_FIVE_MINUTES

 8. onemin(Works)
 - PeriodType.DAY
 - Period.ONE_DAY
 - FrequencyType.MINUTE
 - Frequency.EVERY_MINUTE
4

1 回答 1

1

假设您知道如何进行身份验证并进行正确的调用。以下是您应该能够修改以获得所需内容的几个变体

# Three years, weekly
c = auth.client_from_token_file(config.TOKEN_PATH, config.API_KEY)
response = c.get_price_history('NFLX',
        period=c.PriceHistory.Period.THREE_YEARS, # period not provided when start and end dates are used
        period_type=c.PriceHistory.PeriodType.YEAR,
        frequency=c.PriceHistory.Frequency.WEEKLY,
        frequency_type=c.PriceHistory.FrequencyType.WEEKLY,
        need_extended_hours_data=True)
df = pd.read_json(json.dumps(response.json()['candles']))  
print(df)    

# Three years, daily
response = c.get_price_history('NFLX',
        period=c.PriceHistory.Period.THREE_YEARS, # period not provided when start and end dates are used
        period_type=c.PriceHistory.PeriodType.YEAR,
        frequency=c.PriceHistory.Frequency.DAILY,
        frequency_type=c.PriceHistory.FrequencyType.DAILY,
        need_extended_hours_data=True)
df = pd.read_json(json.dumps(response.json()['candles']))  
print(df)         

# daily, MINUTE
#need to enter timestamps in epoch
response = c.get_price_history(sym,
        period_type=c.PriceHistory.PeriodType.DAY,
        # period=c.PriceHistory.Period.ONE_DAY,
        frequency_type=c.PriceHistory.FrequencyType.MINUTE,
        frequency=c.PriceHistory.Frequency.EVERY_MINUTE,
        start_datetime=datetime.fromtimestamp(market_start_epoch),
        end_datetime=datetime.fromtimestamp(market_end_epoch),
        need_extended_hours_data=True)
df = pd.read_json(json.dumps(response.json()['candles']))  
print(df)    

# daily, every five minutes
#need to enter timestamps in epoch
response = c.get_price_history(sym,
        period_type=c.PriceHistory.PeriodType.DAY,
        # period=c.PriceHistory.Period.ONE_DAY,
        frequency_type=c.PriceHistory.FrequencyType.MINUTE,
        frequency=c.PriceHistory.Frequency.EVERY_FIVE_MINUTES,
        start_datetime=datetime.fromtimestamp(market_start_epoch),
        end_datetime=datetime.fromtimestamp(market_end_epoch),
        need_extended_hours_data=True)                     
df = pd.read_json(json.dumps(response.json()['candles']))  
print(df)    
于 2021-08-24T21:55:05.133 回答