Documentation ¶
Overview ¶
Package tradier provides a client for interacting with the Tradier API.
Usage:
import "github.com/google/go-github/github"
Getting started ¶
The quickest way to get started is to request a non-expiring access token (or more formally, a refresh token) from Tradier. Initantiate a new *tradier.Client and provide an http.Client that can properly handle access token, such as one returned from the oauth2 library. Afterwards, you can use the different services to call specific endpoints.
import "golang.org/x/oauth2" func main() { ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: "... your access token ..."}, ) tc := oauth2.NewClient(oauth2.NoContext, ts) client := tradier.NewClient(tc) // Returns the profile of the user profile, _, err := client.User.Profile() }
If the application is frontend-facing, then the authorization grant flow (https://tools.ietf.org/html/rfc6749#section-1.3.1) should be used to request an access token from the resource owner (the user). Detailed information regarding this process can be found on https://developer.tradier.com/documentation/oauth/getting-started.
Resources and structs ¶
All resources from Tradier are mapped to its corresponding structs. These structs use pointer values in their fields except in the case of slices, which is referenced directly and hold a collection of pointer values. This is to ensure that there is a difference between a nil and zero value when marshalling a resource into its JSON representation.
In most cases (except for the /profile endpoint), the Tradier API returns a collection of objects differently, depending on whether the response is an array of objects, a single object, or an empty collection. For example:
// Array of objects { orders: { order: [ ... ] } } // Single object { orders: { order: { ... } } } // Empty collection { orders: "null" }
There are structs, such as Orders, Watchlists, and Accounts, that represent these collections. In cases where a service method returns these structs, the underlying object can be accessed via indexing or length-checking. For example, if orders is an instance of Orders, acessing each of the orders can be done like so:
- If order is an array of objects, it can be accessed though indexing on orders[i].
- If order is a single object, it can be accessed on the zeroth element (i.e. orders[0]).
- If order is "null", orders length will be zero, len(orders) == 0.
Index ¶
- func Bool(v bool) *bool
- func Float64(v float64) *float64
- func Int(v int) *int
- func Int64(v int64) *int64
- func String(v string) *string
- type Account
- type AccountOrders
- type AccountService
- func (s *AccountService) Balances(accountID string) (*Balances, *Response, error)
- func (s *AccountService) GainLoss(accountID string) (*GainLoss, *Response, error)
- func (s *AccountService) History(accountID string) (*History, *Response, error)
- func (s *AccountService) OrderStatus(accountID, orderID string) (*Order, *Response, error)
- func (s *AccountService) Orders(accountID string) (*Orders, *Response, error)
- func (s *AccountService) Positions(accountID string) (*Positions, *Response, error)
- type Accounts
- type Balances
- type Client
- type ClosedPosition
- type Data
- type Event
- type GainLoss
- type History
- type Items
- type MarketsService
- type Order
- type OrderParams
- type OrderService
- func (s *OrderService) Create(accountID string, params *OrderParams) (*Order, *Response, error)
- func (s *OrderService) Delete(accountID, orderID string) (*Order, *Response, error)
- func (s *OrderService) Preview(accountID string, params *OrderParams) (*Order, *Response, error)
- func (s *OrderService) Update(accountID, orderID string, params *OrderParams) (*Order, *Response, error)
- type Orders
- type Position
- type Positions
- type Profile
- type Quote
- type Quotes
- type Response
- type Series
- type Time
- type TimeSalesParams
- type User
- type UserService
- func (s *UserService) Balances() (*User, *Response, error)
- func (s *UserService) GainLoss() (*User, *Response, error)
- func (s *UserService) History() (*User, *Response, error)
- func (s *UserService) Orders() (*User, *Response, error)
- func (s *UserService) Positions() (*User, *Response, error)
- func (s *UserService) Profile() (*User, *Response, error)
- type Watchlist
- type WatchlistItem
- type WatchlistParams
- type Watchlists
- type WatchlistsService
- func (s *WatchlistsService) All() (*Watchlists, *Response, error)
- func (s *WatchlistsService) Create(name string, params *WatchlistParams) (*Watchlist, *Response, error)
- func (s *WatchlistsService) Delete(watchlistID string) (*Watchlists, *Response, error)
- func (s *WatchlistsService) Get(watchlistID string) (*Watchlist, *Response, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.
func Float64 ¶
Float64 is a helper routine that allocates a new float64 value to store v and returns a pointer to it.
func Int ¶
Int is a helper routine that allocates a new int value to store v and returns a pointer to it.
Types ¶
type Account ¶
type Account struct { AccountNumber *string `json:"account_number,omitempty"` // Specific to orders Orders *AccountOrders `json:"orders,omitempty"` // Specific to profile Classification *string `json:"classification,omitempty"` DateCreated *time.Time `json:"date_created,omitempty"` DayTrader *bool `json:"day_trader,omitempty"` OptionLevel *int `json:"option_level,omitempty"` Status *string `json:"status,omitempty"` Type *string `json:"type,omitempty"` LastUpateDate *time.Time `json:"last_update_date,omitempty"` // Specific to positions Positions *Positions `json:"positions,omitempty"` // Specific to gainloss GainLoss *GainLoss `json:"gainloss,omitempty"` // Specific to history History *History `json:"history,omitempty"` // Specific to balances Balances *Balances `json:"balances,omitempty"` // contains filtered or unexported fields }
Account represents the account object.
func (*Account) MarshalJSON ¶
MarshalJSON marshals Account into JSON
func (*Account) UnmarshalJSON ¶
UnmarshalJSON unmarshals account into Account object.
type AccountOrders ¶
type AccountOrders Orders
AccountOrders is used to hold user orders
func (*AccountOrders) MarshalJSON ¶
func (o *AccountOrders) MarshalJSON() ([]byte, error)
MarshalJSON marshals Orders into JSON.
func (*AccountOrders) UnmarshalJSON ¶
func (o *AccountOrders) UnmarshalJSON(b []byte) (err error)
UnmarshalJSON unmarshals orders into Orders object.
type AccountService ¶
type AccountService service
AccountService handles routes related to account inquiry from the Tradier API.
func (*AccountService) Balances ¶
func (s *AccountService) Balances(accountID string) (*Balances, *Response, error)
Balances returns the account's balance for clientID.
func (*AccountService) GainLoss ¶
func (s *AccountService) GainLoss(accountID string) (*GainLoss, *Response, error)
GainLoss returns the account's cost basis for accountID.
func (*AccountService) History ¶
func (s *AccountService) History(accountID string) (*History, *Response, error)
History returns the account's trading history for accountID.
func (*AccountService) OrderStatus ¶
func (s *AccountService) OrderStatus(accountID, orderID string) (*Order, *Response, error)
OrderStatus returns the account's order status of orderID for accountID.
type Accounts ¶
type Accounts []*Account
Accounts holds a slice of *Account.
func (*Accounts) MarshalJSON ¶
MarshalJSON marshals Accounts into JSON.
func (*Accounts) UnmarshalJSON ¶
UnmarshalJSON unmarshals accounts into Accounts object.
type Balances ¶
type Balances struct { AccountNumber *string `json:"account_number,omitempty"` AccountType *string `json:"account_type,omitempty"` Cash *struct { CashAvailable *float64 `json:"cash_available,omitempty"` Sweep *float64 `json:"sweep,omitempty"` UnsettledFunds *float64 `json:"unsettled_funds,omitempty"` } `json:"cash,omitempty"` ClosePL *float64 `json:"close_pl,omitempty"` CurrentRequirement *float64 `json:"current_requirement,omitempty"` DividendBalance *float64 `json:"dividend_balance,omitempty"` Equity *float64 `json:"equity,omitempty"` LongLiquidValue *float64 `json:"long_liquid_value,omitempty"` LongLiquidMarket *float64 `json:"long_market_value,omitempty"` Margin *struct { FedCall *float64 `json:"fed_call,omitempty"` MaintenanceCall *float64 `json:"maintenance_call,omitempty"` OptionBuyingPower *float64 `json:"option_buying_power,omitempty"` StockBuyingPower *float64 `json:"stock_buying_power,omitempty"` StockShortValue *float64 `json:"stock_short_value,omitempty"` Sweep *float64 `json:"sweep,omitempty"` } `json:"margin,omitempty"` MarketValue *float64 `json:"market_value,omitempty"` NetValue *float64 `json:"net_value,omitempty"` OpenPL *float64 `json:"open_pl,omitempty"` OptionLongValue *float64 `json:"option_long_value,omitempty"` OptionRequirement *float64 `json:"option_requirement,omitempty"` OptionShortValue *float64 `json:"option_short_value,omitempty"` PDT *struct { DayTradeBuyingPower *float64 `json:"day_trade_buying_power,omitempty"` FedCall *float64 `json:"fed_call,omitempty"` MaintenanceCall *float64 `json:"maintenance_call,omitempty"` OptionBuyingPower *float64 `json:"option_buying_power,omitempty"` StockBuyingPower *float64 `json:"stock_buying_power,omitempty"` StockShortValue *float64 `json:"stock_short_value,omitempty"` } `json:"pdt,omitempty"` PendingCase *float64 `json:"pending_cash,omitempty"` PendingOrdersCount *int `json:"pending_orders_count,omitempty"` ShortLiquidValue *float64 `json:"short_liquid_value,omitempty"` ShortMarketValue *float64 `json:"short_market_value,omitempty"` StockLongValue *float64 `json:"stock_long_value,omitempty"` UnclearedFunds *float64 `json:"uncleared_funds,omitempty"` TotalCash *float64 `json:"total_cash,omitempty"` TotalEquity *float64 `json:"total_equity,omitempty"` }
Balances represents the balances object.
func (*Balances) MarshalJSON ¶
MarshalJSON marshals *Balances into its JSON representation
func (*Balances) UnmarshalJSON ¶
UnmarshalJSON unmarshals balances into *Balances object.
type Client ¶
type Client struct { BaseURL *url.URL UserAgent string User *UserService Account *AccountService Order *OrderService Watchlists *WatchlistsService Markets *MarketsService // contains filtered or unexported fields }
Client takes care of managing communication to the Tradier API.
func NewClient ¶
NewClient creates a new Tradier API client. To use API methods that require authentication, an http.Client that performs proper authentication must be provided, such as one created with the golang.org/x/oauth2 library.
type ClosedPosition ¶
type ClosedPosition struct { ClosedDate *time.Time `json:"close_date,omitempty"` Cost *float64 `json:"cost,omitempty"` GainLoss *float64 `json:"gain_loss,omitempty"` GainLossPercent *float64 `json:"gain_loss_percent,omitempty"` OpenDate *time.Time `json:"open_date,omitempty"` Proceeds *float64 `json:"proceeds,omitempty"` Quantity *int `json:"quantity,omitempty"` Symbol *string `json:"symbol,omitempty"` Term *int `json:"term,omitempty"` }
ClosedPosition represents the closed_position object.
type Data ¶
type Data struct { Price *float64 `json:"price,omitempty"` Time *Time `json:"time,omitempty"` Timestamp *int `json:"timestamp,omitempty"` Volume *int `json:"volume,omitempty"` }
Data represents the data JSON object from /markets/timesales.
type Event ¶
type Event struct { Amount *float64 `json:"amount,omitempty"` Date *time.Time `json:"date,omitempty"` Interest *struct { Description *string `json:"description,omitempty"` Quantity *int `json:"quantity,omitempty"` } `json:"interest,omitempty"` Journal *struct { Quantity *int `json:"quantity,omitempty"` } `json:"journal,omitempty"` Option *struct { Description *string `json:"description,omitempty"` OptionType *string `json:"option_type,omitempty"` Quantity *int `json:"quantity,omitempty"` } `json:"option,omitempty"` Type *string `json:"type,omitempty"` Trade *struct { Commission *float64 `json:"commission,omitempty"` Description *string `json:"description,omitempty"` Price *float64 `json:"price,omitempty"` Quantity *int `json:"quantity,omitempty"` Symbol *string `json:"symbol,omitempty"` TradeType *string `json:"trade_type,omitempty"` } `json:"trade,omitempty"` }
Event represents the event object.
type GainLoss ¶
type GainLoss struct {
ClosedPosition []*ClosedPosition `json:"closed_position,omitempty"`
}
GainLoss represents the gainloss object.
func (*GainLoss) MarshalJSON ¶
MarshalJSON marshals GrainLoss into its JSON representation.
func (*GainLoss) UnmarshalJSON ¶
UnmarshalJSON unmarshals gain_loss into GainLoss object.
type History ¶
type History struct {
Event []*Event `json:"event,omitempty"`
}
History represents the history object.
func (*History) MarshalJSON ¶
MarshalJSON marshals History into its JSON representation.
func (*History) UnmarshalJSON ¶
UnmarshalJSON unmarshals history into History object.
type Items ¶
type Items struct {
Item []*WatchlistItem `json:"item,omitempty"`
}
Items represents the items JSON object.
func (*Items) MarshalJSON ¶
MarshalJSON marshals Items into its JSON representation.
func (*Items) UnmarshalJSON ¶
UnmarshalJSON unmarshals items into Items object.
type MarketsService ¶
type MarketsService service
MarketsService handles routes related to orders from the Tradier API.
func (*MarketsService) Quotes ¶
func (s *MarketsService) Quotes(symbols []string) (*Quotes, *Response, error)
Quotes returns the quotes for a set of symbols.
func (*MarketsService) TimeSales ¶
func (s *MarketsService) TimeSales(params *TimeSalesParams) (*Series, *Response, error)
TimeSales returns the time and sales for a given symbol.
type Order ¶
type Order struct { AvgFillPrice *float64 `json:"avg_fill_price,omitempty"` Class *string `json:"class,omitempty"` CreateDate *time.Time `json:"create_date,omitempty"` Duration *string `json:"duration,omitempty"` ExecQuantity *float64 `json:"exec_quantity,omitempty"` ID *int `json:"id,omitempty"` LastFillPrice *float64 `json:"last_fill_price,omitempty"` LastFillQuantity *float64 `json:"last_fill_quantity,omitempty"` Quantity *float64 `json:"quantity,omitempty"` RemainingQuantity *float64 `json:"remaining_quantity,omitempty"` Side *string `json:"side,omitempty"` Status *string `json:"status,omitempty"` Symbol *string `json:"symbol,omitempty"` TransactionDate *time.Time `json:"transaction_date,omitempty"` Type *string `json:"type,omitempty"` // Specific to order creation PartnerID *string `json:"partner_id,omitempty"` // Specific to order preview Commission *float64 `json:"commission,omitempty"` Cost *float64 `json:"cost,omitempty"` ExtendedHours *bool `json:"extended_hours,omitempty"` Fees *float64 `json:"fees,omitempty"` MarginChange *float64 `json:"margin_change,omitempty"` OrderCost *float64 `json:"order_cost,omitempty"` Result *bool `json:"result,omitempty"` // Not present in documentation Strategy *string `json:"strategy,omitempty"` // Not present in documentation, specific to multileg // contains filtered or unexported fields }
Order represents the `order` JSON object.
func (*Order) MarshalJSON ¶
MarshalJSON marshals Order into its JSON representation.
func (*Order) UnmarshalJSON ¶
UnmarshalJSON unmarshals order into Order object.
type OrderParams ¶
type OrderParams struct { Class string `url:"class"` Symbol string `url:"symbol"` Duration string `url:"duration"` Side string `url:"side,omitempty"` Quantity int `url:"quantity,omitempty"` Type string `url:"type"` Price float64 `url:"price,omitempty"` Stop float64 `url:"stop,omitempty"` OptionSymbol string `url:"option_symbol,omitempty"` // Specific to multileg orders MultiSide []string `url:"side,omitempty,[]"` MultiQuantity []int `url:"quantity,omitempty,[]"` MultiOptionSymbol []string `url:"option_symbol,omitempty,[]"` // Specific to preview Preview bool `url:"preview,omitempty"` }
OrderParams specifies the query parameters for querying an order. Refer to https://godoc.org/github.com/google/go-querystring/query for building the struct mapping.
type OrderService ¶
type OrderService service
OrderService handles routes related to orders from the Tradier API.
func (*OrderService) Create ¶
func (s *OrderService) Create(accountID string, params *OrderParams) (*Order, *Response, error)
Create sends an order creation request. This method supports single-sided orders as well as multileg and combo orders.
func (*OrderService) Delete ¶
func (s *OrderService) Delete(accountID, orderID string) (*Order, *Response, error)
Delete sends an order deletion/cancellation request.
func (*OrderService) Preview ¶
func (s *OrderService) Preview(accountID string, params *OrderParams) (*Order, *Response, error)
Preview sends an order preview request.
func (*OrderService) Update ¶
func (s *OrderService) Update(accountID, orderID string, params *OrderParams) (*Order, *Response, error)
Update sends an order update request.
type Orders ¶
type Orders []*Order
Orders represents the orders JSON object.
func (*Orders) MarshalJSON ¶
MarshalJSON marshals Orders into JSON.
func (*Orders) UnmarshalJSON ¶
UnmarshalJSON unmarshals orders into Orders object.
type Position ¶
type Position struct { CostBasis *float64 `json:"cost_basis,omitempty"` DateAcquired *time.Time `json:"date_acquired,omitempty"` ID *int `json:"id,omitempty"` Quantity *float64 `json:"quantity,omitempty"` Symbol *string `json:"symbol,omitempty"` }
Position represents the position JSON object.
type Positions ¶
type Positions []*Position
Positions represents the positions JSON object.
func (*Positions) MarshalJSON ¶
MarshalJSON marshals Positions into JSON.
func (*Positions) UnmarshalJSON ¶
UnmarshalJSON unmarshals positions into Positions object.
type Profile ¶
type Profile struct { Account []*Account `json:"account,omitempty"` ID *string `json:"id,omitempty"` Name *string `json:"name,omitempty"` }
Profile represents the profile JSON object.
type Quote ¶
type Quote struct { Symbol *string `json:"symbol"` Description *string `json:"description"` Exch *string `json:"exch"` Type *string `json:"type"` Last *float64 `json:"last"` Change *float64 `json:"change"` ChangePercentage *float64 `json:"change_percentage"` Volume *int `json:"volume"` AverageVolume *int `json:"average_volume"` LastVolume *int `json:"last_volume"` TradeDate *int64 `json:"trade_date"` Open *float64 `json:"open"` High *float64 `json:"high"` Low *float64 `json:"low"` Close *float64 `json:"close"` Prevclose *float64 `json:"prevclose"` Week52High *float64 `json:"week_52_high"` Week52Low *float64 `json:"week_52_low"` Bid *float64 `json:"bid"` Bidsize *int `json:"bidsize"` Bidexch *string `json:"bidexch"` BidDate *int64 `json:"bid_date"` Ask *float64 `json:"ask"` Asksize *int `json:"asksize"` Askexch *string `json:"askexch"` AskDate *int64 `json:"ask_date"` RootSymbols *string `json:"root_symbols"` }
Quote represents the quote JSON object.
func (*Quote) MarshalJSON ¶
MarshalJSON marshals Quote into its JSON representation.
func (*Quote) UnmarshalJSON ¶
UnmarshalJSON unmarshals quote into Quote object.
type Quotes ¶
type Quotes []*Quote
Quotes represents the quotes JSON object.
func (*Quotes) MarshalJSON ¶
MarshalJSON marshals Quotes into its JSON representation.
func (*Quotes) UnmarshalJSON ¶
UnmarshalJSON unmarshals quotes into Quotes object.
type Response ¶
Response is the Tradier API response. It wraps the standard http.Response from Traider along with rate limits from the header so that it can be more easily accessed
type Series ¶
type Series struct {
Data []*Data `json:"data,omitempty"`
}
Series represents the series JSON object from /markets/timesales.
func (*Series) MarshalJSON ¶
MarshalJSON marshals Series into its JSON representation.
func (*Series) UnmarshalJSON ¶
UnmarshalJSON unmarshals series into Series object.
type Time ¶
Time is the custom time-formatted time
func (*Time) MarshalJSON ¶
MarshalJSON marshals Time into timesales compatible time format
func (*Time) UnmarshalJSON ¶
UnmarshalJSON unmarshals custom JSON time format for timesales date
type TimeSalesParams ¶
type TimeSalesParams struct { Symbol string `url:"symbol"` Interval string `url:"interval,omitempty"` Start string `url:"start,omitempty"` End string `url:"end,omitempty"` SessionFilter string `url:"session_filter,omitempty"` }
TimeSalesParams specifies the query parameters for querying time and sales for a particular symbol.
type User ¶
type User struct { // Profile is specific to users/profile Profile *Profile `json:"profile,omitempty"` Accounts *Accounts `json:"accounts,omitempty"` }
User represents the user JSON object.
func (*User) MarshalJSON ¶
MarshalJSON marshals Accounts into JSON
type UserService ¶
type UserService service
UserService handles routes related to user inquiry from the Tradier API.
func (*UserService) Balances ¶
func (s *UserService) Balances() (*User, *Response, error)
Balances returns the user's balances for all accounts.
func (*UserService) GainLoss ¶
func (s *UserService) GainLoss() (*User, *Response, error)
GainLoss returns the user's cost basis for all accounts.
func (*UserService) History ¶
func (s *UserService) History() (*User, *Response, error)
History returns the user's trading history for all accounts.
func (*UserService) Orders ¶
func (s *UserService) Orders() (*User, *Response, error)
Orders returns the user's orders for all accounts.
type Watchlist ¶
type Watchlist struct { Name *string `json:"name,omitempty"` ID *string `json:"id,omitempty"` PublicID *string `json:"public_id,omitempty"` Items *Items `json:"items,omitempty"` // contains filtered or unexported fields }
Watchlist represents the watchlist JSON object.
func (*Watchlist) MarshalJSON ¶
MarshalJSON marshals Watchlist into its JSON representation.
func (*Watchlist) UnmarshalJSON ¶
UnmarshalJSON unmarshals watchlist into Watchlist object.
type WatchlistItem ¶
type WatchlistItem struct { Symbol *string `json:"symbol,omitempty"` ID *string `json:"id,omitempty"` }
WatchlistItem represents the item JSON object from the watclist item collection.
type WatchlistParams ¶
type WatchlistParams struct { Name string `url:"name"` Symbols []string `url:"symbols,omitempty,comma"` }
WatchlistParams specifies the query parameters for handling watchlist creation. Refer to https://godoc.org/github.com/google/go-querystring/query for building the struct mapping.
type Watchlists ¶
type Watchlists []*Watchlist
Watchlists represents the watchlists JSON object.
func (*Watchlists) MarshalJSON ¶
func (w *Watchlists) MarshalJSON() ([]byte, error)
MarshalJSON marshals Watchlists into its JSON representation.
func (*Watchlists) UnmarshalJSON ¶
func (w *Watchlists) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals watchlists into Watchlists object.
type WatchlistsService ¶
type WatchlistsService service
WatchlistsService handles routes related to watchlists from the Tradier API.
func (*WatchlistsService) All ¶
func (s *WatchlistsService) All() (*Watchlists, *Response, error)
All returns all watchlists for the user.
func (*WatchlistsService) Create ¶
func (s *WatchlistsService) Create(name string, params *WatchlistParams) (*Watchlist, *Response, error)
Create sends an watchlist creation request.
func (*WatchlistsService) Delete ¶
func (s *WatchlistsService) Delete(watchlistID string) (*Watchlists, *Response, error)
Delete sends an watchlist deletion request.
Source Files ¶
- account.go
- account_balances.go
- account_gainloss.go
- account_history.go
- account_order_status.go
- account_orders.go
- account_positions.go
- accounts.go
- balances.go
- doc.go
- gainloss.go
- history.go
- markets.go
- markets_quotes.go
- markets_timesales.go
- order.go
- order_create.go
- order_delete.go
- order_preview.go
- order_update.go
- orders.go
- positions.go
- profile.go
- quotes.go
- time.go
- timesales.go
- tradier.go
- user.go
- user_balances.go
- user_gainloss.go
- user_history.go
- user_orders.go
- user_positions.go
- user_profile.go
- watchlist_create.go
- watchlist_delete.go
- watchlist_get.go
- watchlists.go
- watchlists_all.go
Directories ¶
Path | Synopsis |
---|---|
Package errors handles multiple errors that can be returned from the Tradier API Example: { "errors": { "error": [ "Backoffice rejected override of the order.", "InitialMargin" ] } }
|
Package errors handles multiple errors that can be returned from the Tradier API Example: { "errors": { "error": [ "Backoffice rejected override of the order.", "InitialMargin" ] } } |