簡體   English   中英

羊駝貿易 api 錯誤:'REST' object 沒有屬性 'get_barset'

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

我使用羊駝紙市場。 我正在嘗試從 ALPACA 市場獲取庫存數據以放入 dataframe 並遇到錯誤。

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'

進口

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. 從加載的環境變量中導入我的 API 密鑰。
alpaca_api_key = os.getenv("ALPACA_API_KEY")
alpaca_secret_key = os.getenv("ALPACA_SECRET_KEY")
  1. 創建羊駝 REST object。
alpaca = tradeapi.REST(
    alpaca_api_key,
    alpaca_secret_key,
    api_version="v2"
)
  1. 定義用於獲取歷史數據的庫存數據變量。 我每天都得到過去一年的收盤價。
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. 使用獲取的庫存數據創建 dataframe。 這就是失敗的地方。
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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM