Documentation ¶
Index ¶
- Constants
- Variables
- func IsExtendedTradingTime() bool
- func IsRegularTradingTime() bool
- func IsRobinhoodExtendedTradingTime() bool
- func IsWeekDay(t time.Time) bool
- func MinuteOfDay(t time.Time) int
- func NextMarketClose() time.Time
- func NextMarketExtendedClose() time.Time
- func NextMarketExtendedOpen() time.Time
- func NextMarketOpen() time.Time
- func NextRobinhoodExtendedClose() time.Time
- func NextRobinhoodExtendedOpen() time.Time
- func NextWeekday() time.Time
- func OIsForDate(os []*model.OptionInstrument, d Date) []*model.OptionInstrument
- type Client
- func (c *Client) CancelCryptoOrder(o model.CryptoOrderOutput) error
- func (c *Client) CancelOrder(o *model.Order) error
- func (c *Client) CryptoOrder(cryptoPair model.CryptoCurrencyPair, o CryptoOrderOpts) (*model.CryptoOrderOutput, error)
- func (c *Client) DoAndDecode(req *http.Request, dest interface{}) (err error)
- func (c *Client) GetAccounts() ([]model.AccountInfo, error)
- func (c *Client) GetAndDecode(url string, dest interface{}) error
- func (c *Client) GetCryptoAccounts() ([]model.CryptoAccount, error)
- func (c *Client) GetCryptoCurrencyPairs() ([]model.CryptoCurrencyPair, error)
- func (c *Client) GetCryptoInstrument(symbol string) (*model.CryptoCurrencyPair, error)
- func (c *Client) GetCryptoPortfolios() (model.CryptoPortfolio, error)
- func (c *Client) GetEvents(sym string) (*[]model.OptionAssignment, error)
- func (c *Client) GetFundamentals(stocks ...string) ([]model.FundamentalsData, error)
- func (c *Client) GetHistoricalOptionsInstrument(ctx context.Context, url string) (*model.OptionInstrument, error)
- func (c *Client) GetInstrument(instURL string) (*model.InstrumentData, error)
- func (c *Client) GetInstrumentForSymbol(sym string) (*model.InstrumentData, error)
- func (c *Client) GetInstruments(w *model.Watchlist) ([]model.InstrumentData, error)
- func (c *Client) GetOptionChains(ctx context.Context, is ...*model.InstrumentData) ([]model.OptionChain, error)
- func (c *Client) GetOptionsInstrument(ctx context.Context, o model.OptionChain, tradeType string, date Date) ([]model.OptionInstrument, error)
- func (c *Client) GetOptionsOrders(ctx context.Context) (*[]model.OptionTransaction, error)
- func (c *Client) GetPortfolios() ([]model.Portfolio, error)
- func (c *Client) GetPositions(a model.AccountInfo) ([]model.Position, error)
- func (c *Client) GetPositionsParams(a model.AccountInfo, p PositionParams) ([]model.Position, error)
- func (c *Client) GetQuote(stocks ...string) ([]model.Quote, error)
- func (c *Client) GetStockOrders() ([]model.Transaction, error)
- func (c *Client) GetStockSplits(sym string) (*[]interface{}, error)
- func (c *Client) GetWatchlists() ([]model.Watchlist, error)
- func (c *Client) MarketData(opts ...model.OptionInstrument) ([]*model.MarketData, error)
- func (c *Client) Order(i *model.InstrumentData, o OrderOpts) (*model.Order, error)
- func (c *Client) OrderOptions(q *model.OptionInstrument, o OptionsOrderOpts) (json.RawMessage, error)
- func (c *Client) RecentOrders() ([]model.Order, error)
- func (c *Client) UpdateOrder(o model.Order) error
- type CredsCacher
- type CryptoOrderOpts
- type Date
- type ErrorMap
- type Meta
- type OAuth
- type OptionsOrderOpts
- type OrderOpts
- type OrderSide
- type Pager
- type PositionParams
Constants ¶
const ( EPBase = "https://api.robinhood.com/" EPCryptoBase = "https://nummus.robinhood.com/" EPCryptoOrders = EPCryptoBase + "orders/" EPCryptoAccount = EPCryptoBase + "accounts/" EPCryptoCurrencyPairs = EPCryptoBase + "currency_pairs/" EPCryptoHoldings = EPCryptoBase + "holdings/" EPCryptoPortfolio = EPCryptoBase + "portfolios/" EPLogin = EPBase + "oauth2/token/" EPAccounts = EPBase + "accounts/" EPQuotes = EPBase + "quotes/" EPPortfolios = EPBase + "portfolios/" EPWatchlists = EPBase + "watchlists/" EPInstruments = EPBase + "instruments/" EPFundamentals = EPBase + "fundamentals/" EPOptionOrders = EPBase + "options/positions/" EPOrders = EPBase + "orders/" EPOptions = EPBase + "options/" EPEvents = EPBase + "options/events/" EPMarket = EPBase + "marketdata/" EPOptionQuote = EPMarket + "options/" )
Endpoints for the Robinhood API
const ( HrExtendedOpen = 4 HrRHExtendedOpen = 9 HrClose = 12 + 4 HrRHExtendedClose = 12 + 6 HrExtendedClose = 12 + 8 MinExtendedOpen = HrExtendedOpen * 60 MinRHExtendedOpen = HrRHExtendedOpen * 60 MinOpen = 9*60 + 30 MinClose = HrClose * 60 MinRHExtendedClose = HrRHExtendedClose * 60 MinExtendedClose = HrExtendedClose * 60 )
Common constants for hours and minutes from midnight at which market events occur.
const DefaultClientID = "c82SH0WZOsabOXGP2sxqcj34FxkvfnWRZBKlBjFS"
DefaultClientID is used by the website.
Variables ¶
var ErrMFARequired = fmt.Errorf("Two Factor Auth code required and not supplied")
ErrMFARequired indicates the MFA was required but not provided.
Functions ¶
func IsExtendedTradingTime ¶
func IsExtendedTradingTime() bool
IsExtendedTradingTime returns whether or not extended hours equity will be updated because extended-hours trades may still be allowed in the markets.
func IsRegularTradingTime ¶
func IsRegularTradingTime() bool
IsRegularTradingTime returns whether or not the markets are currently open for regular trading.
func IsRobinhoodExtendedTradingTime ¶
func IsRobinhoodExtendedTradingTime() bool
IsRobinhoodExtendedTradingTime returns whether or not trades can still be placed during the robinhood gold extended trading hours.
func MinuteOfDay ¶
MinuteOfDay returns the minute of the day for a given time.Time (hr * 60 + min).
func NextMarketClose ¶
NextMarketClose returns the time of the next market close.
func NextMarketExtendedClose ¶
NextMarketExtendedClose returns the time of the next extended market close, when stock equity numbers will stop being updated until the next extended open.
func NextMarketExtendedOpen ¶
NextMarketExtendedOpen returns the time of the next extended opening time, when stock equity may begin to fluctuate again.
func NextMarketOpen ¶
NextMarketOpen returns the time of the next opening bell, when regular trading begins.
func NextRobinhoodExtendedClose ¶
NextRobinhoodExtendedClose returns the time of the next robinhood extended closing time, when robinhood users must place their last extended-hours trade.
func NextRobinhoodExtendedOpen ¶
NextRobinhoodExtendedOpen returns the time of the next robinhood extended opening time, when robinhood users can make trades.
func OIsForDate ¶
func OIsForDate(os []*model.OptionInstrument, d Date) []*model.OptionInstrument
OIsForDate filters OptionInstruments for expiration date.
Types ¶
type Client ¶
type Client struct { Account *model.AccountInfo CryptoAccount *model.CryptoAccount *http.Client }
A Client is a helpful abstraction around some common metadata required for API operations.
func Dial ¶
func Dial(s oauth2.TokenSource) (*Client, error)
Dial returns a client given a TokenGetter. TokenGetter implementations are available in this package, including a Cookie-based cache.
func (*Client) CancelCryptoOrder ¶
func (c *Client) CancelCryptoOrder(o model.CryptoOrderOutput) error
CancelCryptoOrder to cancel order
func (*Client) CancelOrder ¶
CancelOrder attempts to cancel an odrer
func (*Client) CryptoOrder ¶
func (c *Client) CryptoOrder(cryptoPair model.CryptoCurrencyPair, o CryptoOrderOpts) (*model.CryptoOrderOutput, error)
CryptoOrder will actually place the order
func (*Client) DoAndDecode ¶
DoAndDecode provides useful abstractions around common errors and decoding issues.
func (*Client) GetAccounts ¶
func (c *Client) GetAccounts() ([]model.AccountInfo, error)
GetAccounts returns all the accounts associated with a login/client.
func (*Client) GetAndDecode ¶
GetAndDecode retrieves from the endpoint and unmarshals resulting json into the provided destination interface, which must be a pointer.
func (*Client) GetCryptoAccounts ¶
func (c *Client) GetCryptoAccounts() ([]model.CryptoAccount, error)
GetCryptoAccounts will return associated cryto account
func (*Client) GetCryptoCurrencyPairs ¶
func (c *Client) GetCryptoCurrencyPairs() ([]model.CryptoCurrencyPair, error)
GetCryptoCurrencyPairs will give which crypto currencies are tradeable and corresponding ids
func (*Client) GetCryptoInstrument ¶
func (c *Client) GetCryptoInstrument(symbol string) (*model.CryptoCurrencyPair, error)
GetCryptoInstrument will take standard crypto symbol and return usable information to place the order
func (*Client) GetCryptoPortfolios ¶
func (c *Client) GetCryptoPortfolios() (model.CryptoPortfolio, error)
GetCryptoPortfolios returns crypto portfolio info
func (*Client) GetEvents ¶
func (c *Client) GetEvents(sym string) (*[]model.OptionAssignment, error)
RecentOrders returns any events
Returns the events related to a options all events shown here will be assigned
func (*Client) GetFundamentals ¶
func (c *Client) GetFundamentals(stocks ...string) ([]model.FundamentalsData, error)
GetFundamentals returns fundemental data for the list of stocks provided.
func (*Client) GetHistoricalOptionsInstrument ¶
func (c *Client) GetHistoricalOptionsInstrument(ctx context.Context, url string) (*model.OptionInstrument, error)
Get Historical Data regarding an options trade
func (*Client) GetInstrument ¶
func (c *Client) GetInstrument(instURL string) (*model.InstrumentData, error)
GetInstrument returns an Instrument given a URL
func (*Client) GetInstrumentForSymbol ¶
func (c *Client) GetInstrumentForSymbol(sym string) (*model.InstrumentData, error)
GetInstrumentForSymbol returns an Instrument given a ticker symbol
func (*Client) GetInstruments ¶
GetInstruments returns the list of Instruments associated with a Watchlist.
func (*Client) GetOptionChains ¶
func (c *Client) GetOptionChains(ctx context.Context, is ...*model.InstrumentData) ([]model.OptionChain, error)
GetOptionChains returns options for the given instruments
func (*Client) GetOptionsInstrument ¶
func (c *Client) GetOptionsInstrument(ctx context.Context, o model.OptionChain, tradeType string, date Date) ([]model.OptionInstrument, error)
GetOptionsInstrument returns a list of option-typed instruments given a list of expiration dates for a given trade type. The request will continue until the provided context is cancelled. This is done to mimic the way the web UI fetches many, many options instruments repeatedly, since I haven't yet figured out how/when they decide to stop.
func (*Client) GetOptionsOrders ¶
GetOptionsOrders returns all outstanding options orders
func (*Client) GetPortfolios ¶
GetPortfolios returns all the portfolios associated with a client's credentials and accounts
func (*Client) GetPositions ¶
GetPositions returns all the positions associated with an account.
func (*Client) GetPositionsParams ¶
func (c *Client) GetPositionsParams(a model.AccountInfo, p PositionParams) ([]model.Position, error)
GetPositionsParams returns all the positions associated with a count, but passes the encoded PositionsParams object along to the RobinHood API as part of the query string.
func (*Client) GetQuote ¶
GetQuote returns all the latest stock quotes for the list of stocks provided
func (*Client) GetStockOrders ¶
func (c *Client) GetStockOrders() ([]model.Transaction, error)
GetStockOrders returns orders made by this client.
func (*Client) GetStockSplits ¶
Returns the stock splits (THIS DOESN'T WORK)
func (*Client) GetWatchlists ¶
GetWatchlists retrieves the watchlists for a given set of credentials/accounts.
func (*Client) MarketData ¶
func (c *Client) MarketData(opts ...model.OptionInstrument) ([]*model.MarketData, error)
MarketData returns market data for all the listed Option instruments
func (*Client) OrderOptions ¶
func (c *Client) OrderOptions(q *model.OptionInstrument, o OptionsOrderOpts) (json.RawMessage, error)
OrderOptions places a new order for options
func (*Client) RecentOrders ¶
RecentOrders returns any recent orders made by this client.
type CredsCacher ¶
type CredsCacher struct { Creds oauth2.TokenSource Path string }
A CredsCacher takes user credentials and a file path. The token obtained from the RobinHood API will be cached at the file path, and a new token will not be obtained.
type CryptoOrderOpts ¶
type CryptoOrderOpts struct { Side model.Side Type model.ExecutionType AmountInDollars float64 Quantity float64 Price float64 TimeInForce model.TimeInForce ExtendedHours bool Stop, Force bool }
CryptoOrderOpts encapsulates differences between order types
type Date ¶
Date is a specific json time format for dates only
func NewZonedDate ¶
NewZonedDate returns a date with a zone.
func (Date) MarshalJSON ¶
MarshalJSON implements json.Marshaler
func (*Date) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler
type ErrorMap ¶
type ErrorMap map[string]interface{}
ErrorMap encapsulates the helpful error messages returned by the API server
type Meta ¶
type Meta struct { CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` URL string `json:"url"` }
Meta holds metadata common to many RobinHood types.
type OAuth ¶
type OAuth struct {
Endpoint, ClientID, Username, Password, MFA string
}
OAuth implements oauth2 using the robinhood implementation
type OptionsOrderOpts ¶
type OptionsOrderOpts struct { Quantity float64 Price float64 Direction model.Direction TimeInForce model.TimeInForce Type model.ExecutionType Side model.Side Trigger model.Trigger }
OptionsOrderOpts encapsulates common Options order choices
type OrderOpts ¶
type OrderOpts struct { Side model.Side Type model.ExecutionType Quantity uint64 Price float64 TimeInForce model.TimeInForce ExtendedHours bool Stop, Force bool }
OrderOpts encapsulates differences between order types
type Pager ¶
type Pager struct {
Next, Previous string
}
Pager for paginating data
type PositionParams ¶
type PositionParams struct {
NonZero bool
}
PositionParams encapsulates parameters known to the RobinHood positions API endpoint.