robinhood

package
v0.0.0-...-71b6df6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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.

View Source
const DefaultClientID = "c82SH0WZOsabOXGP2sxqcj34FxkvfnWRZBKlBjFS"

DefaultClientID is used by the website.

Variables

View Source
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 IsWeekDay

func IsWeekDay(t time.Time) bool

IsWeekDay returns whether the given time is a regular weekday

func MinuteOfDay

func MinuteOfDay(t time.Time) int

MinuteOfDay returns the minute of the day for a given time.Time (hr * 60 + min).

func NextMarketClose

func NextMarketClose() time.Time

NextMarketClose returns the time of the next market close.

func NextMarketExtendedClose

func NextMarketExtendedClose() time.Time

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

func NextMarketExtendedOpen() time.Time

NextMarketExtendedOpen returns the time of the next extended opening time, when stock equity may begin to fluctuate again.

func NextMarketOpen

func NextMarketOpen() time.Time

NextMarketOpen returns the time of the next opening bell, when regular trading begins.

func NextRobinhoodExtendedClose

func NextRobinhoodExtendedClose() time.Time

NextRobinhoodExtendedClose returns the time of the next robinhood extended closing time, when robinhood users must place their last extended-hours trade.

func NextRobinhoodExtendedOpen

func NextRobinhoodExtendedOpen() time.Time

NextRobinhoodExtendedOpen returns the time of the next robinhood extended opening time, when robinhood users can make trades.

func NextWeekday

func NextWeekday() time.Time

NextWeekday returns the next weekday.

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

func (c *Client) CancelOrder(o *model.Order) error

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

func (c *Client) DoAndDecode(req *http.Request, dest interface{}) (err error)

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

func (c *Client) GetAndDecode(url string, dest interface{}) error

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

func (c *Client) GetInstruments(w *model.Watchlist) ([]model.InstrumentData, error)

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

func (c *Client) GetOptionsOrders(ctx context.Context) (*[]model.OptionTransaction, error)

GetOptionsOrders returns all outstanding options orders

func (*Client) GetPortfolios

func (c *Client) GetPortfolios() ([]model.Portfolio, error)

GetPortfolios returns all the portfolios associated with a client's credentials and accounts

func (*Client) GetPositions

func (c *Client) GetPositions(a model.AccountInfo) ([]model.Position, error)

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

func (c *Client) GetQuote(stocks ...string) ([]model.Quote, error)

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

func (c *Client) GetStockSplits(sym string) (*[]interface{}, error)

Returns the stock splits (THIS DOESN'T WORK)

func (*Client) GetWatchlists

func (c *Client) GetWatchlists() ([]model.Watchlist, error)

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) Order

func (c *Client) Order(i *model.InstrumentData, o OrderOpts) (*model.Order, error)

Order places an order for a given instrument

func (*Client) OrderOptions

OrderOptions places a new order for options

func (*Client) RecentOrders

func (c *Client) RecentOrders() ([]model.Order, error)

RecentOrders returns any recent orders made by this client.

func (*Client) UpdateOrder

func (c *Client) UpdateOrder(o model.Order) error

UpdateOrder returns any errors and updates the item with any recent changes.

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.

func (*CredsCacher) Token

func (c *CredsCacher) Token() (*oauth2.Token, error)

Token implements TokenSource. It may fail if an error is encountered checking the file path provided, or if the underlying creds return an error when retrieving their token.

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

type Date struct {
	time.Time
}

Date is a specific json time format for dates only

func NewDate

func NewDate(y, m, d int) Date

NewDate returns a new Date in the local time zone

func NewZonedDate

func NewZonedDate(y, m, d int, z *time.Location) Date

NewZonedDate returns a date with a zone.

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (Date) String

func (d Date) String() string

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(bs []byte) error

UnmarshalJSON implements json.Unmarshaler

type ErrorMap

type ErrorMap map[string]interface{}

ErrorMap encapsulates the helpful error messages returned by the API server

func (ErrorMap) Error

func (e ErrorMap) Error() string

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

func (*OAuth) Token

func (p *OAuth) Token() (*oauth2.Token, error)

Token implements TokenSource

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 OrderSide

type OrderSide int

OrderSide is which side of the trade an order is on

type Pager

type Pager struct {
	Next, Previous string
}

Pager for paginating data

func (*Pager) GetNext

func (p *Pager) GetNext(c *Client, out interface{}) error

GetNext will decode the next set of pages if they exist

func (Pager) HasMore

func (p Pager) HasMore() bool

HasMore for determining when end of pages are reached

type PositionParams

type PositionParams struct {
	NonZero bool
}

PositionParams encapsulates parameters known to the RobinHood positions API endpoint.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL