简体   繁体   English

羊驼贸易 api 错误:'REST' object 没有属性 'get_barset'

[英]Alpaca trade api error: 'REST' object has no attribute 'get_barset'

I use ALPACA paper markets.我使用羊驼纸市场。 I'm trying to get stock data from ALPACA markets to put into a dataframe, and running into an error.我正在尝试从 ALPACA 市场获取库存数据以放入 dataframe 并遇到错误。

AttributeError Traceback (most recent call last) in 11 # Get 1 year's worth of historical data for Tesla and Coca-Cola 12 # YOUR CODE HERE. AttributeError Traceback (last last call last) in 11 # 获取特斯拉和可口可乐 12 年的 1 年历史数据 # 你的代码在这里。 ---> 13 df_ticker = alpaca,get_barset( 14 ticker, 15 timeframe: AttributeError: 'REST' object has no attribute 'get_barset' ---> 13 df_ticker = alpaca,get_barset( 14 ticker, 15 timeframe: AttributeError: 'REST' object has no attribute 'get_barset'

Imports进口

import os
import pandas as pd
import alpaca_trade_api as tradeapi
from dotenv import load_dotenv
load_dotenv('.env')    # loading my environment variables.
  1. Import my API keys from the loaded environment variables.从加载的环境变量中导入我的 API 密钥。
alpaca_api_key = os.getenv("ALPACA_API_KEY")
alpaca_secret_key = os.getenv("ALPACA_SECRET_KEY")
  1. Create the alpaca REST object.创建羊驼 REST object。
alpaca = tradeapi.REST(
    alpaca_api_key,
    alpaca_secret_key,
    api_version="v2"
)
  1. Define stock data variables to use to fetch historic data.定义用于获取历史数据的库存数据变量。 I am getting the past year of closing prices for each day.我每天都得到过去一年的收盘价。
ticker = [list of stocks]
timeframe = "1D"    # 1-days worth of closing prices.
start_date = pd.Timestamp("2021-07-26", tz="America/New_York").isoformat()
end_date = pd.Timestamp("2022-07-26", tz="America/New_York").isoformat()
  1. Create a dataframe with the fetched stock data.使用获取的库存数据创建 dataframe。 This is where it fails.这就是失败的地方。
df_ticker = alpaca.get_barset(
    ticker,                           
    timeframe,                   # 1-day closing prices.
    start = start_date,   
    end = end_date,
    limit = 1000                 # put a limit that way there's not too mucb data returned and screws up program.
).df                             # format as a dataframe

It looks like get_barset() is part of the V1 API for alpaca, you need to use the get_bars() method with V2, or else specify the API V1 when creating the REST object. It looks like get_barset() is part of the V1 API for alpaca, you need to use the get_bars() method with V2, or else specify the API V1 when creating the REST object.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ModuleNotFoundError:没有名为“alpaca_trade_api”的模块 - ModuleNotFoundError: No module named 'alpaca_trade_api' API的属性错误 - 模块对象没有属性'UserViewSet' - Django Rest Framework - Attribute Error at API - module object has no attribute 'UserViewSet' - Django Rest Framework Object post has no attribute post.title - API 属性错误 - Object post has no attribute post.title - API attribute error 调用 API 时出现错误“...” object 没有属性“_default_manager” - Get Error '...' object has no attribute '_default_manager' when call API 无法使用 Alpaca API 获取实时数据 - Not able to get real time data with Alpaca API 使用 API 时 Django 'dict' object 没有属性 'META' 错误 - Django 'dict' object has no attribute 'META' error when using an API Django Rest 框架 - 属性错误:“函数”没有属性“get_extra_actions” - Django Rest Framework - Attribute Error: 'function' has no attribute 'get_extra_actions' AWS Lambda 错误:AttributeError 'list' 对象没有属性 'get' - AWS Lambda ERROR: AttributeError 'list' object has no attribute 'get' 获取 AttributeError 错误 'str' object has no attribute 'get' - Getting AttributeError error 'str' object has no attribute 'get' 类对象没有属性“get” - Class object has no attribute 'get'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM