robinhood

package module
v0.0.0-...-e4d37ae Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2018 License: MIT Imports: 11 Imported by: 0

README

Robinhood Go API

Work In Progress.

This library is under development. It is already functional for the following:

  • Initialize with user's credentials.
  • Fetch portfolio and account information.
  • Get real-time quotes.
  • Get options chains.
  • Enter simple stock orders.

TODO:

  • Option orders.
  • Multi-leg option orders.
  • More testing.

To start using:

import (
  "fmt"
  
  rh "github.com/edpin/robinhood"
)

func main() {
  client := &rh.Client{
		Username: "username",
		Password: "password",
  }

  err := client.GetToken()
  if err != nil {
		panic(err)
  }

	accs, err := client.GetAccounts()
	if err != nil {
		panic(err)
	}
	fmt.Println("Accounts:")
	for _, acc := range accs {
		fmt.Printf("Account: %v\n", acc.AccountNumber)
	}
}

See cmd for more examples.

Documentation

Overview

Package robinhood is a client of Robinhood's trading and screening API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	AccountNumber string `json:"account_number"`
	URL           string `json:"url"`
}

Account contains the user's AccountNumber.

type Chain

type Chain struct {
	Strike     float64
	Expiration time.Time
	Symbol     string
	Type       string // "put" or "call". TODO: use an enum?
	// contains filtered or unexported fields
}

Chain represents a complete option with strike price, expiration, type (put/call) and an underlying symbol.

type Client

type Client struct {
	// AccountID is the account number this client will use. It is required for
	// all operations that operate directly on a user's account, such as calls to
	// get the portfolio and entering and cancelling orders.
	AccountID string

	// Token is the access token used for authentication. If it's not present,
	// then Username and Password must be present.
	Token string

	// Username is the user's username with Robinhood. It may be blank if the
	// client has a Token already.
	Username string

	// Password is the user's password. It may be blank if the client has a Token
	// already.
	Password string

	// BearerToken is present when a call to GetBearerToken is successful. It is
	// only necessary for real-time quotes.
	BearerToken string

	// BearerTokenExpiration is the wall clock time that the bearer token expires.
	BearerTokenExpiration time.Time
	// contains filtered or unexported fields
}

Client is the Robinhood API client. It supports a single account. For users with multiple accounts, create a new Client for each account.

func (*Client) Chains

func (c *Client) Chains(symbol string, expiration time.Time) ([]Chain, error)

Chains returns all chains (i.e. a complete option with strike price) for an option on the underlying symbol and an expiration date.

func (*Client) EnsureBearerToken

func (c *Client) EnsureBearerToken() error

EnsureBearerToken ensures the client has a bearer token with at least another 30 seconds of time to live.

func (*Client) Expirations

func (c *Client) Expirations(symbol string) ([]time.Time, error)

Expirations returns all expiration dates for options for the underlying symbol.

func (*Client) GetAccounts

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

GetAccounts returns the list of all account numbers associated with a user. Client must be authenticated (i.e. a Token must be supplied).

func (*Client) GetBearerToken

func (c *Client) GetBearerToken() error

GetBearerToken fetches the bearer token and stores it implicitly.

func (*Client) GetToken

func (c *Client) GetToken() error

GetToken gets a new token, based on this client's Username and Password. It implicitly saves the new token.

func (*Client) Option

func (c *Client) Option(chain Chain) (Option, error)

Option returns a quote for an option chain.

func (*Client) Order

func (c *Client) Order(o Order) error

Order creates a new trade order for this client's account.

func (*Client) Portfolio

func (c *Client) Portfolio() ([]Position, error)

Portfolio returns a slice of Position a user has in their account.

func (*Client) Quote

func (c *Client) Quote(symbol []string) ([]Quote, error)

Quote returns a slice of quotes for the requested security symbols. Does not work on option symbols.

type Duration

type Duration int

Duration is the duration of a buy/sell order.

const (
	// Day means the order is valid for today only.
	Day Duration = iota

	// GTC means Good-Till-Cancelled.
	GTC
)

func (Duration) String

func (d Duration) String() string

String implements Stringer.

type Instrument

type Instrument string

Instrument represents a Robinhood resource.

func (Instrument) GetID

func (i Instrument) GetID() string

GetID returns the ID part of the Instrument.

type Option

type Option struct {
	Symbol      string // the underlying symbol.
	Strike      float64
	Expiration  time.Time
	Type        string // "put" or "call". TODO: use an enum?
	Bid         float64
	Ask         float64
	Last        float64
	MarketPrice float64 // Close to midpoint, but not quite.
	Volume      int64
	IV          float64
	// contains filtered or unexported fields
}

Option represents a real-time quote for an option.

type Order

type Order struct {
	Symbol    string
	Quantity  int64
	Duration  Duration
	Type      OrderType
	Side      Side
	Price     float64
	StopPrice float64 // only present for STOP or STOP_LIMIT orders.
}

Order describes a buy or sell order.

type OrderType

type OrderType int

OrderType describes whether the order is market, stop, limit, etc.

const (
	Market OrderType = iota
	Limit
	Stop
	StopLimit
)

See description for OrderType.

func (OrderType) String

func (t OrderType) String() string

String implements Stringer.

type Position

type Position struct {
	Symbol   string
	Name     string
	BuyPrice float64
	Quantity float64
}

Position identifies a position in a portfolio.

type Quote

type Quote struct {
	Symbol string
	Ask    float64
	Bid    float64
}

Quote is the real-time price quote for a security.

type Side

type Side int

Side represents the side of the order, either a buy or a sell and for short orders, the opening or closing side.

const (
	Buy Side = iota
	Sell
	BuyToOpen
	BuyToClose
	SellToOpen
	SellToClose
)

See description for Side.

func (Side) String

func (s Side) String() string

String implements Stringer.

Directories

Path Synopsis
cmd
chains
chains returns option chains of a given underlying symbol and expiration.
chains returns option chains of a given underlying symbol and expiration.
expirations
expirations returns all expirations for options of a given underlying symbol.
expirations returns all expirations for options of a given underlying symbol.
get_token
get_token is a simple utility to get a user's token, given their username and password.
get_token is a simple utility to get a user's token, given their username and password.
options
options returns live quota for the specified option.
options returns live quota for the specified option.
portfolio
portfolio retrieves the user's portfolio.
portfolio retrieves the user's portfolio.
quotes
quotes retrieves quotes from the Robinhood API for a given symbol(s).
quotes retrieves quotes from the Robinhood API for a given symbol(s).

Jump to

Keyboard shortcuts

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