Documentation ¶
Overview ¶
Package robinhood provides an API for accessing and using Robinhood's (unofficial) API.
Index ¶
- Constants
- Variables
- func GetAccountURL(accountNumber string) string
- func GetInstrumentURL(instrumentID string) string
- func ParseAccountNumber(accountURL string) (string, error)
- func ParseInstrumentID(instrumentURL string) (string, error)
- type APIError
- type Account
- type AccountType
- type CashBalances
- type Client
- func (c *Client) CancelOrder(orderId string) (*OrderTicket, error)
- func (c *Client) GetAccount(accountNumber string) (*Account, error)
- func (c *Client) GetInstrument(id string) (*Instrument, error)
- func (c *Client) GetOrder(orderId string) (*OrderTicket, error)
- func (c *Client) GetPortfolio(accountNumber string) (*Portfolio, error)
- func (c *Client) ListAccounts() ([]*Account, error)
- func (c *Client) ListAllInstruments() ([]*Instrument, error)
- func (c *Client) ListInstrumentsForSymbol(symbol string) ([]*Instrument, error)
- func (c *Client) ListOrders(req *ListOrdersRequest) ([]*OrderTicket, error)
- func (c *Client) ListPositions(nonzero bool) ([]*Position, error)
- func (c *Client) ListPositionsForAccount(accountNumber string, nonzero bool) ([]*Position, error)
- func (c *Client) PlaceOrder(o *Order) (*OrderTicket, error)
- type HTTPClient
- type Instrument
- type ListOrdersRequest
- type MarginBalances
- type OAuth
- type OAuthResponse
- type Order
- type OrderExecution
- type OrderSide
- type OrderState
- type OrderTicket
- type OrderType
- type Portfolio
- type Position
- type TimeInForce
- type Trigger
Constants ¶
View Source
const ( Queued OrderState = "queued" Unconfirmed = "unconfirmed" Confirmed = "confirmed" PartiallyFilled = "partially_filled" Filled = "filled" Rejected = "rejected" Canceled = "cancelled" Failed = "failed" )
View Source
const DefaultClientID = "c82SH0WZOsabOXGP2sxqcj34FxkvfnWRZBKlBjFS"
DefaultClientID is the OAuth2 ID used by the robinhood.com website.
View Source
const (
Endpoint = "https://api.robinhood.com"
)
Variables ¶
View Source
var ErrMFARequired = errors.New("two-factor auth (2FA) code required and not supplied")
Functions ¶
func GetAccountURL ¶
func GetInstrumentURL ¶
func ParseAccountNumber ¶
Helper function to extract the account ID from an account URL.
func ParseInstrumentID ¶
Helper function to extract the instrument ID from an instrument URL.
Types ¶
type Account ¶
type Account struct { Deactivated bool URL string CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` CashBalances *CashBalances `json:"cash_balances"` MarginBalances *MarginBalances `json:"margin_balances"` PortfolioURL string `json:"portfolio"` WithdrawalHalted bool `json:"withdrawal_halted"` CashAvailableForWithdrawal float64 `json:"cash_available_for_withdrawal,string"` Type AccountType SMA float64 `json:",string"` SweepEnabled bool `json:"sweep_enabled"` DepositHalted bool `json:"deposit_halted"` BuyingPower float64 `json:"buying_power,string"` UserURL string `json:"user"` MaxACHEarlyAccessAmount float64 `json:"max_ach_early_access_amount,string"` CashHeldForOrders float64 `json:"cash_held_for_orders,string"` OnlyPositionClosingTrades bool `json:"only_position_closing_trades"` PositionsURL string `json:"positions"` Cash float64 `json:",string"` SMAHeldForOrders float64 `json:"sma_held_for_orders,string"` AccountNumber string `json:"account_number"` UnclearedDeposits float64 `json:"uncleared_deposits,string"` UnsettledFunds float64 `json:"unsettled_funds,string"` }
type AccountType ¶
type AccountType string
const ( CashAccount AccountType = "cash" MarginAccount AccountType = "margin" )
type CashBalances ¶
type CashBalances struct { CashHeldForOrders float64 `json:"cash_held_for_orders,string"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` Cash float64 `json:",string"` BuyingPower float64 `json:"buying_power,string"` CashAvailableForWithdrawal float64 `json:"cash_available_for_withdrawal,string"` UnclearedDeposits float64 `json:"uncleared_deposits,string"` UnsettledFunds float64 `json:"unsettled_funds,string"` }
type Client ¶
type Client struct {
HTTPClient
}
func NewClient ¶
func NewClient(tokenSource oauth2.TokenSource) *Client
func (*Client) CancelOrder ¶
func (c *Client) CancelOrder(orderId string) (*OrderTicket, error)
func (*Client) GetInstrument ¶
func (c *Client) GetInstrument(id string) (*Instrument, error)
Get info for a particular instrument ID.
func (*Client) GetPortfolio ¶
func (*Client) ListAccounts ¶
func (*Client) ListAllInstruments ¶
func (c *Client) ListAllInstruments() ([]*Instrument, error)
List all known instruments.
func (*Client) ListInstrumentsForSymbol ¶
func (c *Client) ListInstrumentsForSymbol(symbol string) ([]*Instrument, error)
Get info for a particular symbol.
func (*Client) ListOrders ¶
func (c *Client) ListOrders(req *ListOrdersRequest) ([]*OrderTicket, error)
func (*Client) ListPositionsForAccount ¶
func (*Client) PlaceOrder ¶
func (c *Client) PlaceOrder(o *Order) (*OrderTicket, error)
type HTTPClient ¶
HTTPClient is an interface for the methods we use of http.Client. It enables using a mock HTTP client for tests.
type Instrument ¶
type Instrument struct { MarginInitialRatio float64 `json:"margin_initial_ratio,string"` RHSTradability string `json:"rhs_tradability"` ID string MarketURL string `json:"market"` SimpleName string `json:"simple_name"` MinTickSize *float64 `json:"min_tick_size,string"` MaintenanceRatio float64 `json:"maintenance_ratio,string"` Tradability string State string Type string Tradeable bool FundamentalsURL string `json:"fundamentals"` QuoteURL string `json:"quote"` Symbol string DayTradeRatio float64 `json:"day_trade_ratio,string"` Name string TradableChainID *string `json:"tradable_chain_id"` SplitsURL string `json:"splits"` URL string BloombergUnique string `json:"bloomberg_unique"` ListDate string `json:"list_date"` Country string }
type ListOrdersRequest ¶
type MarginBalances ¶
type MarginBalances struct { DayTradeBuyingPower float64 `json:"day_trade_buying_power,string"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` OvernightBuyingPowerHeldForOrders float64 `json:"overnight_buying_power_held_for_orders,string"` CashHeldForOrders float64 `json:"cash_held_for_orders,string"` DayTradeBuyingPowerHeldForOrders float64 `json:"day_trade_buying_power_held_for_orders,string"` MarkedPatternDayTraderDate *time.Time Cash float64 `json:",string"` UnallocatedMarginCash float64 `json:"unallocated_margin_cash,string"` CashAvailableForWithdrawal float64 `json:"cash_available_for_withdrawal,string"` MarginLimit float64 `json:"margin_limit,string"` OvernightBuyingPower float64 `json:"overnight_buying_power,string"` UnclearedDeposits float64 `json:"uncleared_deposits,string"` UnsettledFunds float64 `json:"unsettled_funds,string"` DayTradeRatio float64 `json:"day_trade_ratio,string"` OvernightRatio float64 `json:"overnight_ratio,string"` }
type OAuth ¶
type OAuth struct {
Endpoint, ClientID, Username, Password, MFA string
}
OAuth implements oauth2.TokenSource for Robinhood.
type OAuthResponse ¶
type OAuthResponse struct { oauth2.Token ExpiresIn int `json:"expires_in"` MFARequired bool `json:"mfa_required"` MFAType string `json:"mfa_type"` }
OAuthResponse is the JSON-encoded response returned from OAuth2 token requests.
type Order ¶
type Order struct { AccountURL string `json:"account" url:"account,omitempty"` InstrumentURL string `json:"instrument" url:"instrument,omitempty"` Symbol string `url:"symbol,omitempty"` Type OrderType `url:"type,omitempty"` TimeInForce TimeInForce `json:"time_in_force" url:"time_in_force,omitempty"` Trigger Trigger `url:"trigger,omitempty"` Price *float64 `json:",string" url:"price,omitempty"` StopPrice *float64 `json:"stop_price,string" url:"stop_price,omitempty"` Quantity float64 `json:"quantity,string" url:"quantity,omitempty"` Side OrderSide `url:"side,omitempty"` ClientID *string `json:"client_id" url:"client_id,omitempty"` ExtendedHours bool `json:"extended_hours" url:"extended_hours,omitempty"` OverrideDayTradeChecks bool `json:"override_day_trade_checks" url:"override_day_trade_checks,omitempty"` OverrideDTBPChecks bool `json:"override_dtbp_checks" url:"override_dtbp_checks,omitempty"` }
type OrderExecution ¶
type OrderState ¶
type OrderState string
type OrderTicket ¶
type OrderTicket struct { *Order ID string UpdatedAt time.Time `json:"updated_at"` Executions []OrderExecution Fees float64 `json:"fees,string"` CancelURL string `json:"cancel"` CumulativeQuantity float64 `json:"cumulative_quantity,string"` RejectReason string `json:"reject_reason"` State OrderState LastTransactionAt time.Time `json:"last_transaction_at"` URL string CreatedAt time.Time `json:"created_at"` PositionURL string `json:"position"` AveragePrice *float64 `json:"average_price,string"` }
type Portfolio ¶
type Portfolio struct { URL string AdjustedEquityPreviousClose float64 `json:"adjusted_equity_previous_close,string"` AccountURL string `json:"account"` LastCoreMarketValue float64 `json:"last_core_market_value,string"` LastCoreEquity float64 `json:"last_core_equity,string"` Equity float64 `json:",string"` MarketValue float64 `json:"market_value,string"` EquityPreviousClose float64 `json:"equity_previous_close,string"` }
type Position ¶
type Position struct { AccountURL string `json:"account"` IntradayQuantity float64 `json:"intraday_quantity,string"` IntradayAverageBuyPrice float64 `json:"intraday_average_buy_price,string"` URL string CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` AverageBuyPrice float64 `json:"average_buy_price,string"` InstrumentURL string `json:"instrument"` Quantity float64 `json:",string"` }
type TimeInForce ¶
type TimeInForce string
const ( GoodForDay TimeInForce = "gfd" GoodTilCanceled TimeInForce = "gtc" ImmediateOrCancel TimeInForce = "ioc" OPG TimeInForce = "opg" )
Click to show internal directories.
Click to hide internal directories.