Documentation ¶
Overview ¶
Package allyinvest wraps the Ally Invest API.
Example (APIGetOptions) ¶
k := allyinvest.ApplicationKeys{ ConsumerKey: "CONSUMER_KEY", ConsumerSecret: "CONSUMER_SECRET", AccessToken: "ACCESS_TOKEN", AccessSecret: "ACCESS_SECRET", } api := allyinvest.New(k) // Gets all SPY options expiring April 1, 2021 with a strike prices of 353.00 out, err := api.SearchOptions(allyinvest.SearchOptionsInput{ Symbol: allyinvest.String("SPY"), Query: &allyinvest.OptionSearchQuery{ { ExpirationDate: allyinvest.Int(20210409), QueryOperator: allyinvest.QueryOperatorEqual, }, { StrikePrice: allyinvest.Float64(353.00), QueryOperator: allyinvest.QueryOperatorEqual, }, }, }) fmt.Println(err) fmt.Println(out)
Output:
Index ¶
- Constants
- func Float64(f float64) *float64
- func GoFloat64(f *float64) float64
- func GoInt(i *int) int
- func GoString(s *string) string
- func Int(i int) *int
- func String(s string) *string
- type API
- type AccountBalance
- type AccountBalanceSummary
- type AccountHistoryDateRange
- type AccountHistoryTransaction
- type AccountHolding
- type AccountHoldings
- type AccountSummary
- type Accounts
- type ApplicationKeys
- type BuyingPower
- type ExtendedQuote
- type GetAccountBalancesInput
- type GetAccountBalancesOutput
- type GetAccountBalancesResponse
- type GetAccountHistoryInput
- type GetAccountHistoryOutput
- type GetAccountHistoryResponse
- type GetAccountHoldingsInput
- type GetAccountHoldingsOutput
- type GetAccountHoldingsResponse
- type GetAccountInput
- type GetAccountOutput
- type GetAccountResponse
- type GetAccountsBalancesOutput
- type GetAccountsBalancesResponse
- type GetAccountsOutput
- type GetAccountsResponse
- type GetOptionsExpirationsInput
- type GetOptionsExpirationsOutput
- type GetOptionsExpirationsResponse
- type GetOptionsStrikesInput
- type GetOptionsStrikesOutput
- type GetOptionsStrikesResponse
- type HTTPClient
- type Instrument
- type Money
- type OptionQuote
- type OptionSearchQuery
- type OptionSearchQueryElement
- type OptionsQuotes
- type OptionsStrikeExpirations
- type OptionsStrikePrices
- type QueryOperator
- type Quote
- type SearchOptionsInput
- type SearchOptionsOutput
- type SearchOptionsResponse
- type Securities
- type Security
- type TotalBalance
- type Transaction
- type TransactionDetails
- type Transactions
Examples ¶
Constants ¶
const ( AccountTypeCash = 1 AccountTypeMarginLong = 2 AccountTypeMarginShort = 5 )
const ( InstrumentKindCommonStock = 0 InstrumentKindOption = 1 )
const ( SecurityTypeOption = "OPT" SecurityTypeCommonStock = "CS" )
const ( OptionKindPut = "put" OptionKindCall = "call" )
const ( UniqueStrikePrice = "strikeprice" UniqueExpirationDate = "xdate" )
const ( ChangeDirectionEven = "e" ChangeDirectionUp = "u" ChangeDirectionDown = "d" )
const ( SettlementDesignationStandard = "S" SettlementDesignationNonStandard = "N" SettlementDesignationNA = "X" )
const ( OptionStyleAmerican = "A" OptionStyleEuropean = "E" )
const ( OptionSubclassStandard = 0 OptionSubclassLeap = 1 OptionSubclassShortTerm = 3 )
const ( SecurityClassStock = 0 SecurityClassOption = 1 )
const ( SessionPreMarket = "pre" SessionOpenMarket = "open" SessionPostMarket = "post" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type API ¶
type API interface { GetAccounts() (GetAccountsOutput, error) GetAccountsBalances() (GetAccountsBalancesOutput, error) GetAccount(GetAccountInput) (GetAccountOutput, error) GetAccountBalances(GetAccountBalancesInput) (GetAccountBalancesOutput, error) GetAccountHistory(GetAccountHistoryInput) (GetAccountHistoryOutput, error) GetAccountHoldings(GetAccountHoldingsInput) (GetAccountHoldingsOutput, error) GetOrders() CreateOrder() PreviewOrder() GetMarketClock() GetMarketNews() SearchMarketNews() GetMarketTimesales() GetMarketToplists() GetQuotes() SearchOptions(SearchOptionsInput) (SearchOptionsOutput, error) GetOptionsStrikes(GetOptionsStrikesInput) (GetOptionsStrikesOutput, error) GetOptionsExpirations(GetOptionsExpirationsInput) (GetOptionsExpirationsOutput, error) GetMemberProfile() GetUtilityStatus() GetUtilityVersion() GetWatchlists() CreateWatchlist() GetWatchlist() DeleteWatchlist() AddSymbolToWatchlist() DeleteSymbolFromWatchlist() }
API is the Ally Invest API.
func NewWithClient ¶
func NewWithClient(client HTTPClient) API
NewWithClient creates a new API with a custom HTTPClient
type AccountBalance ¶
type AccountBalance struct { Account int `json:"account,string"` AccountValue float64 `json:"accountvalue,string"` BuyingPower BuyingPower `json:"buyingpower"` FedCall string `json:"fedcall"` HouseCall string `json:"housecall"` Money Money `json:"money"` Securities Securities `json:"securities"` }
type AccountBalanceSummary ¶
type AccountHistoryDateRange ¶
type AccountHistoryDateRange string
AccountHistoryDateRange are the valid date range values.
const ( AccountHistoryDateRangeAll AccountHistoryDateRange = "all" AccountHistoryDateRangeToday AccountHistoryDateRange = "today" AccountHistoryDateRangeCurrentWeek AccountHistoryDateRange = "current_week" AccountHistoryDateRangeCurrentMonth AccountHistoryDateRange = "current_month" AccountHistoryDateRangeLastMonth AccountHistoryDateRange = "last_month" )
func AccountHistoryDateRangePtr ¶
func AccountHistoryDateRangePtr(a AccountHistoryDateRange) *AccountHistoryDateRange
AccountHistoryDateRangePtr returns a pointer to a.
func GoAccountHistoryDateRange ¶
func GoAccountHistoryDateRange(a *AccountHistoryDateRange) AccountHistoryDateRange
GoAccountHistoryDateRange returns the value held by a.
type AccountHistoryTransaction ¶
type AccountHistoryTransaction string
AccountHistoryTransaction are the valid kinds of transactions.
const ( AccountHistoryTransactionAll AccountHistoryTransaction = "all" AccountHistoryTransactionBookkeeping AccountHistoryTransaction = "bookkeeping" AccountHistoryTransactionTrade AccountHistoryTransaction = "trade" )
func AccountHistoryTransactionPtr ¶
func AccountHistoryTransactionPtr(a AccountHistoryTransaction) *AccountHistoryTransaction
AccountHistoryTransactionPtr returns a pointer to a.
func GoAccountHistoryTransaction ¶
func GoAccountHistoryTransaction(a *AccountHistoryTransaction) AccountHistoryTransaction
GoAccountHistoryTransaction returns the value held by a.
type AccountHolding ¶
type AccountHolding struct { AccountType int `json:"accounttype,string"` CostBasis float64 `json:"costbasis,string"` GainLoss float64 `json:"gainloss,string"` Instrument Instrument `json:"instrument"` MarketValue float64 `json:"marketvalue,string"` MarketValueChange float64 `json:"marketvaluechange,string"` Price float64 `json:"price,string"` PurchasePrice float64 `json:"purchaseprice,string"` Quantity float64 `json:"qty,string"` Quote Quote `json:"quote"` SODCostBasis int `json:"sodcostbasis,string"` Underyling string `json:"underlying"` }
type AccountHoldings ¶
type AccountHoldings struct { Holding []AccountHolding `json:"holding"` TotalSecurities float64 `json:"totalsecurities,string"` }
type AccountSummary ¶
type AccountSummary struct { Account int `json:"account,string"` AccountBalance AccountBalance `json:"accountbalance"` AccountHoldings AccountHoldings `json:"accountholdings"` }
type Accounts ¶
type Accounts struct {
AccountSummary AccountSummary `json:"accountsummary"`
}
type ApplicationKeys ¶
type ApplicationKeys struct { ConsumerKey string ConsumerSecret string AccessToken string AccessSecret string }
ApplicationKeys are the OAuth keys associated with a given account.
type BuyingPower ¶
type BuyingPower struct { CashAvailableForWithdrawal float64 `json:"cashavailableforwithdrawal,string"` DayTrading float64 `json:"daytrading,string"` EquityPercentage float64 `json:"equitypercentage,string"` Options float64 `json:"options,string"` SODDayTrading float64 `json:"soddaytrading,string"` SODOptions float64 `json:"sodoptions,string"` SODStock float64 `json:"sodstock,string"` Stock float64 `json:"stock,string"` }
type ExtendedQuote ¶
type ExtendedQuote struct {
DividentData string `json:"dividenddata"`
}
type GetAccountBalancesInput ¶
type GetAccountBalancesInput struct { // REQUIRED: The account ID for which you are requesting balances. AccountID *string `validate:"required"` }
GetAccountBalancesInput are the required or optional parameters to GetAccountBalances.
type GetAccountBalancesOutput ¶
type GetAccountBalancesOutput struct {
Response GetAccountBalancesResponse `json:"response"`
}
type GetAccountBalancesResponse ¶
type GetAccountBalancesResponse struct { ID string `json:"@id"` AccountBalance AccountBalance `json:"accountbalance"` ElapsedTime int `json:"elapsedtime,string"` Error string `json:"error"` }
type GetAccountHistoryInput ¶
type GetAccountHistoryInput struct { // REQUIRED: The account ID for which you are requesting history. AccountID *string `validate:"required"` // OPTIONAL: Date range of transacations. Valid values: // // AccountHistoryDateRangeAll: "all" // AccountHistoryDateRangeToday: "today" // AccountHistoryDateRangeCurrentWeek: "current_week" // AccountHistoryDateRangeCurrentMonth: "current_month" // AccountHistoryDateRangeLastMonth: "last_month" Range *AccountHistoryDateRange // OPTIONAL: The kind of transactions to show. Valid values: // // AccountHistoryTransactionAll: "all" // AccountHistoryTransactionBookkeeping: "bookkeeping" // AccountHistoryTransactionTrade: "trade" Transactions *AccountHistoryTransaction }
GetAccountHistoryInput are the required or optional parameters to GetAccountHistory.
func (GetAccountHistoryInput) Encode ¶
func (g GetAccountHistoryInput) Encode() string
Encode encodes g to a query string.
type GetAccountHistoryOutput ¶
type GetAccountHistoryOutput struct {
Response GetAccountHistoryResponse `json:"response"`
}
type GetAccountHistoryResponse ¶
type GetAccountHistoryResponse struct { ID string `json:"@id"` Transactions Transactions `json:"transactions"` ElapsedTime int `json:"elapsedtime,string"` Error string `json:"error"` }
type GetAccountHoldingsInput ¶
type GetAccountHoldingsInput struct { // REQUIRED: The account ID for which you are requesting holdings. AccountID *string `validate:"required"` }
GetAccountHodingsInput are the required or optional parameters to GetAccountHoldings.
type GetAccountHoldingsOutput ¶
type GetAccountHoldingsOutput struct {
Response GetAccountHoldingsResponse `json:"response"`
}
type GetAccountHoldingsResponse ¶
type GetAccountHoldingsResponse struct { ID string `json:"@id"` AccountHoldings AccountHoldings `json:"accountholdings"` ElapsedTime int `json:"elapsedtime,string"` Error string `json:"error"` }
type GetAccountInput ¶
type GetAccountInput struct { // REQUIRED: The account ID for which you are requesting the summary. AccountID *string `validate:"required"` }
GetAccountInput are the required or optional parameters to GetAccount.
type GetAccountOutput ¶
type GetAccountOutput struct {
Response GetAccountResponse `json:"response"`
}
type GetAccountResponse ¶
type GetAccountResponse struct { ID string `json:"@id"` AccountBalance AccountBalance `json:"accountbalance"` AccountHoldings AccountHoldings `json:"accountholdings"` ElapsedTime int `json:"elapsedtime,string"` Error string `json:"error"` }
type GetAccountsBalancesOutput ¶
type GetAccountsBalancesOutput struct {
Response GetAccountsBalancesResponse `json:"response"`
}
type GetAccountsBalancesResponse ¶
type GetAccountsBalancesResponse struct { ID string `json:"@id"` AccountBalance AccountBalanceSummary `json:"accountbalance"` TotalBalance TotalBalance `json:"totalbalance"` ElapsedTime int `json:"elapsedtime,string"` Error string `json:"error"` }
type GetAccountsOutput ¶
type GetAccountsOutput struct {
Response GetAccountsResponse `json:"response"`
}
type GetAccountsResponse ¶
type GetOptionsExpirationsInput ¶
type GetOptionsExpirationsInput struct { // REQUIRED: The symbol you are searching for. Symbol *string `validate:"required"` }
GetOptionsExpirationsInput are the required or optional parameters to GetOptiosnExpirations.
func (GetOptionsExpirationsInput) Encode ¶
func (g GetOptionsExpirationsInput) Encode() string
Encode encodes g to a query string.
type GetOptionsExpirationsOutput ¶
type GetOptionsExpirationsOutput struct {
Response GetOptionsExpirationsResponse `json:"response"`
}
type GetOptionsExpirationsResponse ¶
type GetOptionsExpirationsResponse struct { ID string `json:"@id"` Expirations OptionsStrikeExpirations `json:"expirationdates"` ElapsedTime int `json:"elapsedtime,string"` Error string `json:"error"` }
type GetOptionsStrikesInput ¶
type GetOptionsStrikesInput struct { // REQUIRED: The symbol you are searching for. Symbol *string `validate:"required"` }
GetOptionsStrikesInput are the required or optional parameters to GetOptionsStrikes.
func (GetOptionsStrikesInput) Encode ¶
func (g GetOptionsStrikesInput) Encode() string
Encode encodes g to a query string.
type GetOptionsStrikesOutput ¶
type GetOptionsStrikesOutput struct {
Response GetOptionsStrikesResponse `json:"response"`
}
type GetOptionsStrikesResponse ¶
type GetOptionsStrikesResponse struct { ID string `json:"@id"` Prices OptionsStrikePrices `json:"prices"` ElapsedTime int `json:"elapsedtime,string"` Error string `json:"error"` }
type HTTPClient ¶
HTTPClient defines the HTTP client to be used by the application. The stdlib's *http.Client implements this interface.
type Instrument ¶
type Instrument struct { CFI string `json:"cfi"` CUSIP string `json:"cusip"` Description string `json:"desc"` Factor float64 `json:"factor,string"` MaturityDate time.Time `json:"matdt"` MaturityMonthYear string `json:"mmy"` Multiplier int `json:"mult,string"` PutCall int `json:"putcall,string"` SecurityType string `json:"sectyp"` StrikePrice float64 `json:"strkpx,string"` Symbol string `json:"sym"` }
type Money ¶
type Money struct { AccruedInterest float64 `json:"accruedinterest,string"` Cash float64 `json:"cash,string"` CashAvailable float64 `json:"cashavailable,string"` MarginBalance float64 `json:"marginbalance,string"` MMF float64 `json:"mmf,string"` Total float64 `json:"total,string"` UnclearedPositions float64 `json:"uncleareddeposits,string"` UnsettledFunds float64 `json:"unsettledfunds,string"` Yield float64 `json:"yield,string"` }
type OptionQuote ¶
type OptionQuote struct { Ask float64 `json:"ask,string"` AskTime string `json:"ask_time"` AskSize int `json:"asksz,string"` Basis string `json:"basis"` Bid float64 `json:"bid,string"` BidTime string `json:"bid_time"` BidSize int `json:"bidsz,string"` Change float64 `json:"chg,string"` ChangeDirection string `json:"chg_sign"` ChangeText string `json:"chg_t"` Close float64 `json:"cl,string"` ContractSize int `json:"contract_size,string"` Date string `json:"date"` DateTime time.Time `json:"datetime"` DaysToExpiration int `json:"days_to_expiration,string"` Exchange string `json:"exch"` ExchangeDescription string `json:"exch_desc"` DayHigh float64 `json:"hi,string"` Delta float64 `json:"idelta,string"` Gamma float64 `json:"igamma,string"` ImpliedVolatility float64 `json:"imp_Volatility,string"` LastTradeVolume string `json:"incr_vl"` Rho float64 `json:"irho,string"` Description string `json:"issue_desc"` Theta float64 `json:"itheta,string"` Vega float64 `json:"ivega,string"` Last float64 `json:"last,string"` DayLow float64 `json:"lo,string"` SettlementDesignation string `json:"op_delivery"` HasOptions int `json:"op_flag,string"` OptionStyle string `json:"op_style"` OptionSubclass int `json:"ob_subclass,string"` OpenInterest int `json:"openinterest,string"` Open float64 `json:"opn,string"` PercentChange float64 `json:"pchg,string"` PercentChangeSign string `json:"pchg_sign"` PriorDayClose float64 `json:"pcls,string"` PriorDayHigh float64 `json:"phi,string"` PriorDayLow float64 `json:"plo,string"` PriorDayOpen float64 `json:"popn,string"` PriorLastDate string `json:"pr_date"` PriorOpenInterest string `json:"pr_openinterest"` PriorChange float64 `json:"prchg,string"` PremiumMultiplier int `json:"prem_mult,string"` PriorDatyVolume int `json:"pvol,string"` RootSymbol string `json:"rootsymbol"` SecurityClass int `json:"secclass,string"` Session string `json:"sesn"` StrikePrice float64 `json:"strikeprice,string"` Symbol string `json:"symbol"` TradeCondition string `json:"tcond"` Timestamp int `json:"timestamp,string"` NumberTradesSinceOpen int `json:"tr_num,string"` Tradetick string `json:"tradetick"` UnderlyingCUSIP string `json:"under_cusip"` UnderlyingSymbol string `json:"undersymbol"` Volume int `json:"vl,string"` VolumeWeightedAveragePrice string `json:"vwap"` Week52High float64 `json:"wk52hi,string"` Week52HighDate string `json:"wk52hidate"` Week52Low float64 `json:"wk52lo,string"` Week52LowDate string `json:"wk52lodate"` ExpirationDate string `json:"xdate"` ExpirationDay string `json:"xday"` ExpirationMonth string `json:"xmonth"` Expirationyear string `json:"xyear"` }
type OptionSearchQuery ¶
type OptionSearchQuery []OptionSearchQueryElement
func (OptionSearchQuery) Encode ¶
func (o OptionSearchQuery) Encode() string
Encode encodes o into a custom query string.
type OptionSearchQueryElement ¶
type OptionSearchQueryElement struct { StrikePrice *float64 ExpirationDate *int ExpirationMonth *int ExpirationYear *int OptionKind *string Unique *string QueryOperator QueryOperator }
func (OptionSearchQueryElement) Encode ¶
func (o OptionSearchQueryElement) Encode() string
Encode encodes o into a custom query string.
type OptionsQuotes ¶
type OptionsQuotes struct {
Quote []OptionQuote `json:"quote"`
}
type OptionsStrikeExpirations ¶
type OptionsStrikeExpirations struct {
Date []string `json:"date"`
}
type OptionsStrikePrices ¶
type OptionsStrikePrices struct {
Price []string `json:"price"`
}
type QueryOperator ¶
type QueryOperator string
const ( QueryOperatorLessThan QueryOperator = "-lt:" QueryOperatorGreaterThan QueryOperator = "-gt:" QueryOperatorLessThanOrEqual QueryOperator = "-lte:" QueryOperatorGreaterThanOrEqual QueryOperator = "-gte:" QueryOperatorEqual QueryOperator = "-eq:" )
type Quote ¶
type Quote struct { Change float64 `json:"change,string"` Format string `json:"format"` ExtendedQuote ExtendedQuote `json:"extendedquote"` LastPrice float64 `json:"lastprice,string"` }
type SearchOptionsInput ¶
type SearchOptionsInput struct { // REQUIRED: The symbol you are searching for. Symbol *string `validate:"required"` // OPTIONAL: Query to apply when searching for the provided symbol. Query *OptionSearchQuery // OPTIONAL: Fields to return from the search. If ommitted, all fields // are returned. Fields []string }
SearchOptionsInput are the required or optional parameters to SearchOptions.
func (SearchOptionsInput) Encode ¶
func (s SearchOptionsInput) Encode() string
Encode encodes s to a query string.
type SearchOptionsOutput ¶
type SearchOptionsOutput struct {
Response SearchOptionsResponse `json:"response"`
}
type SearchOptionsResponse ¶
type SearchOptionsResponse struct { ID string `json:"@id"` Quotes OptionsQuotes `json:"quotes"` ElapsedTime int `json:"elapsedtime,string"` Error string `json:"error"` }
type Securities ¶
type Securities struct { LongOptions float64 `json:"longoptions,string"` LongStocks float64 `json:"longstocks,string"` Options float64 `json:"options,string"` ShortOptions float64 `json:"shortoptions,string"` ShortStocks float64 `json:"shortstocks,string"` Stocks float64 `json:"stocks,string"` Total float64 `json:"total,string"` }
type TotalBalance ¶
type TotalBalance struct {
AccountValue float64 `json:"accountvalue,string"`
}
type Transaction ¶
type TransactionDetails ¶
type TransactionDetails struct { AccountType int `json:"accounttype,string"` Commission float64 `json:"commission,string"` Description string `json:"description"` Fee float64 `json:"fee,string"` Price float64 `json:"price,string"` Quantity int `json:"quantity,string"` SecurityFee float64 `json:"secfee,string"` Security Security `json:"security"` SettlementDate time.Time `json:"settlementdate"` Side int `json:"side,string"` Source string `json:"source"` TradeDate time.Time `json:"tradedate"` TransactionID int `json:"transactionid,string"` TransactionType string `json:"transactiontype"` }
type Transactions ¶
type Transactions struct {
Transaction []Transaction `json:"transaction"`
}