获取Robinhood api Py上的所有自有股票信息

2024-05-16 21:30:41 发布

您现在位置:Python中文网/ 问答频道 /正文

是否有一种方式或方法可以获取所有自有股票/密码的信息,例如其数量

例如,如果我总共拥有2只股票,即“CCL”和“CUK”,我如何获得名称/符号的列表-类似于[“CCL”,“CUK”]


Tags: 方法名称信息密码列表数量方式符号
2条回答

有一个名为pyrh的库用于访问RobinHood API

在像库文档中描述的那样进行身份验证之后,您可以使用类pyrh.robinood提供的方法来收集数据

像这样的东西可能有用

from pyrh import Robinhood

rh = Robinhood()
rh.login(username="YOUR_EMAIL", password="YOUR_PASSWORD")

data = rh.portfolio()

我不确定投资组合数据以何种形式出现,因此您可能需要对其进行迭代以将其转换为列表

Robinhood API当前维护的python库是robin_stocks

为了获得投资组合中的股票,您首先需要通过以下方式进行验证:

import robin_stocks as r
r.login("yourusername","yourpassword")

然后使用build_holdings()之类的函数,它将返回有关您帐户持有情况的信息

holdings = r.account.build_holdings()

返回:

Returns a dictionary where the keys are the stock tickers and the value is another dictionary that has the stock price, quantity held, equity, percent change, equity change, type, name, id, pe ratio, percentage of portfolio, and average buy price.

包括所有持有的股票。图书馆文档是here

相关问题 更多 >