robinhood

package module
v0.0.0-...-3b7dd48 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2019 License: LGPL-3.0 Imports: 11 Imported by: 0

README

go-robinhood

A Go library for accessing the Robinhood (unofficial) API.

GoDoc Build Status Coverage Status Go Report Card

go-robinhood is a library to access the Robinhood unofficial API from Go. It provides a thin wrapper for working with the JSON REST endpoints documented in sanko/Robinhood.

Robinhood is not affiliated and does not endorse or recommend this library. By using the Robinhood API, you agree to the Terms and Conditions.

Usage

Contributing

Pull requests and issues are welcomed!

License

go-robinhood is released under the GNU Lesser General Public License, Version 3.0

Documentation

Overview

Package robinhood provides an API for accessing and using Robinhood's (unofficial) API.

Index

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 GetAccountURL(accountNumber string) string

func GetInstrumentURL

func GetInstrumentURL(instrumentID string) string

func ParseAccountNumber

func ParseAccountNumber(accountURL string) (string, error)

Helper function to extract the account ID from an account URL.

func ParseInstrumentID

func ParseInstrumentID(instrumentURL string) (string, error)

Helper function to extract the instrument ID from an instrument URL.

Types

type APIError

type APIError struct {
	StatusCode int
	Errors     map[string]interface{}
}

func (APIError) Error

func (e APIError) Error() string

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

func (c *Client) GetAccount(accountNumber string) (*Account, error)

func (*Client) GetInstrument

func (c *Client) GetInstrument(id string) (*Instrument, error)

Get info for a particular instrument ID.

func (*Client) GetOrder

func (c *Client) GetOrder(orderId string) (*OrderTicket, error)

func (*Client) GetPortfolio

func (c *Client) GetPortfolio(accountNumber string) (*Portfolio, error)

func (*Client) ListAccounts

func (c *Client) ListAccounts() ([]*Account, error)

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

func (c *Client) ListPositions(nonzero bool) ([]*Position, error)

func (*Client) ListPositionsForAccount

func (c *Client) ListPositionsForAccount(accountNumber string, nonzero bool) ([]*Position, error)

func (*Client) PlaceOrder

func (c *Client) PlaceOrder(o *Order) (*OrderTicket, error)

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (resp *http.Response, err error)
}

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 ListOrdersRequest struct {
	Since         time.Time `url:"since,omitempty"`
	InstrumentURL string    `url:"instrument,omitempty"`
}

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.

func (*OAuth) Token

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

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 OrderExecution struct {
	Timestamp      time.Time
	Price          float64 `json:",string"`
	SettlementDate string
	ID             string
	Quantity       float64 `json:",string"`
}

type OrderSide

type OrderSide string
const (
	Buy  OrderSide = "buy"
	Sell OrderSide = "sell"
)

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 OrderType

type OrderType string
const (
	Market OrderType = "market"
	Limit  OrderType = "limit"
)

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"`
	SharesHeldForStockGrants float64 `json:"shares_held_for_stock_grants,string"`
	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"`
	SharesHeldForBuys        float64   `json:"shares_held_for_buys,string"`
	AverageBuyPrice          float64   `json:"average_buy_price,string"`
	InstrumentURL            string    `json:"instrument"`
	SharesHeldForSells       float64   `json:"shares_held_for_sells,string"`
	Quantity                 float64   `json:",string"`
}

type TimeInForce

type TimeInForce string
const (
	GoodForDay        TimeInForce = "gfd"
	GoodTilCanceled   TimeInForce = "gtc"
	ImmediateOrCancel TimeInForce = "ioc"
	OPG               TimeInForce = "opg"
)

type Trigger

type Trigger string
const (
	Immediate Trigger = "immediate"
	Stop      Trigger = "stop"
)

Jump to

Keyboard shortcuts

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