Comments (1)
Also got this. The issue occurs because Robinhood's API appears to be including another 'symbol' column in both positions and instruments which are then bound by cbind
. The result is a dataframe with two columns labeled 'symbol', so when the function calls merge
it doesn't know which 'symbol' column to merge by. Here's a very rough replacement until this is fixed in the package. You should be able to swap in custom_get_positions
for get_positions
in your script. It removes the duplicated columns so you can run merge
correctly
custom_get_positions = function (RH, limit_output = TRUE){
RobinHood::check_rh(RH)
positions <- RobinHood::api_positions(RH)
if (nrow(positions) == 0) {
return(cat("You have no current positions"))
}
instrument_id <- positions$instrument
instruments <- c()
for (i in 1:length(instrument_id)) {
instrument <- RobinHood::api_instruments(RH, instrument_url = instrument_id[i])
x <- data.frame(simple_name = ifelse(is.null(instrument$simple_name),
instrument$name, instrument$simple_name), symbol = instrument$symbol)
instruments <- rbind(instruments, x)
}
positions <- cbind(instruments, positions)
symbols <- paste(as.character(positions$symbol), collapse = ",")
symbols_url <- paste(RobinHood::api_endpoints(endpoint = "quotes"),
symbols, sep = "")
quotes <- RobinHood::api_quote(RH, symbols_url)
quotes <- quotes[, c("last_trade_price", "symbol")]
positions <- merge(positions[,!duplicated(colnames(positions))], quotes, by.x = 'symbol', by.y = 'symbol')
positions <- positions[, !names(positions) %in% c("account",
"url", "instrument")]
positions$updated_at <- lubridate::ymd_hms(positions$updated_at)
positions$created_at <- lubridate::ymd_hms(positions$created_at)
positions$quantity <- as.numeric(positions$quantity)
positions$average_buy_price <- as.numeric(positions$average_buy_price)
positions$last_trade_price <- as.numeric(positions$last_trade_price)
positions$shares_held_for_stock_grants <- as.numeric(positions$shares_held_for_stock_grants)
positions$shares_held_for_options_events <- as.numeric(positions$shares_held_for_options_events)
positions$shares_held_for_options_collateral <- as.numeric(positions$shares_held_for_options_collateral)
positions$shares_held_for_buys <- as.numeric(positions$shares_held_for_buys)
positions$shares_held_for_sells <- as.numeric(positions$shares_held_for_sells)
positions$shares_pending_from_options_events <- as.numeric(positions$shares_pending_from_options_events)
positions$pending_average_buy_price <- as.numeric(positions$pending_average_buy_price)
positions$intraday_average_buy_price <- as.numeric(positions$intraday_average_buy_price)
positions$intraday_quantity <- as.numeric(positions$intraday_quantity)
positions$cost <- positions$average_buy_price * positions$quantity
positions$current_value <- positions$last_trade_price *
positions$quantity
if (limit_output == TRUE) {
positions <- positions[, c("simple_name", "symbol",
"quantity", "average_buy_price", "last_trade_price",
"cost", "current_value", "updated_at")]
}
if (limit_output == FALSE) {
positions <- positions[, c("symbol", "simple_name",
"quantity", "average_buy_price", "last_trade_price",
"cost", "current_value", "shares_held_for_stock_grants",
"shares_held_for_options_events", "shares_held_for_options_collateral",
"shares_held_for_buys", "shares_held_for_sells",
"shares_pending_from_options_events", "pending_average_buy_price",
"intraday_average_buy_price", "intraday_quantity",
"created_at", "updated_at")]
}
return(positions)
}
environment(custom_get_positions) <- asNamespace('RobinHood')
assignInNamespace("get_positions", custom_get_positions, ns = "RobinHood")
from robinhood.
Related Issues (20)
- fractional shares and "sell all" HOT 2
- get_positions_options: Column `updated_at` doesn't exist HOT 4
- get_positions_options: Column `state` doesn't exist HOT 1
- Buy in dollars rather than shares? HOT 2
- feature request: trailing stop for stocks
- HTTP 400 error for get_tcierks(RH, add_fundamentals = T)
- Getting Bad Request (HTTP 400) Error HOT 14
- argument "mfa_code" is missing, with no default HOT 3
- Cannot place order HOT 3
- MFA Requirement HOT 30
- HTTP 400 Bad Request on api_login
- Error in get_historicals_options HOT 4
- 404 on vignette getting started HOT 1
- logout() function is returning Internal server error 500 HOT 2
- Placing an order in extended hours
- Current Bugs
- Retirement Accounts
- Have you considered using MFA HOT 1
- Can't place orders HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from robinhood.