Documentation ¶
Overview ¶
Package api contains a wrapper for the stockfighter.io API.
Index ¶
- Constants
- func SetBaseURL(URL string)
- func SetBaseWSURL(URL string)
- type ErrorResult
- type Execution
- type ExecutionStream
- type Fill
- type Instance
- func (i *Instance) AccountOrderStatus() []Order
- func (i *Instance) AvailableStocks() []Stock
- func (i *Instance) CancelOrder(ID int) (v Order)
- func (i *Instance) Debug()
- func (i *Instance) Executions(stockOnly bool, account string) *ExecutionStream
- func (i *Instance) GetAccount() string
- func (i *Instance) GetErr() error
- func (i *Instance) GetSymbol() string
- func (i *Instance) GetVenue() string
- func (i *Instance) Heartbeat() ErrorResult
- func (i *Instance) JudgeLevel() (v ErrorResult)
- func (i *Instance) NewOrder(price int, quantity int, direction orderDirection, orderType orderType) (v Order)
- func (i *Instance) OrderStatus(ID int) (v Order)
- func (i *Instance) Orderbook() (v Orderbook)
- func (i *Instance) Quote() (v Quote)
- func (i *Instance) Quotes(stockOnly bool) *QuoteStream
- func (i *Instance) ResetErr()
- func (i *Instance) RestartLevel() (v LevelState)
- func (i *Instance) ResumeLevel() (v LevelState)
- func (i *Instance) SetAPIKey(apiKey string)
- func (i *Instance) SetAccount(account string)
- func (i *Instance) SetInstanceID(instanceID int)
- func (i *Instance) SetSymbol(symbol string)
- func (i *Instance) SetVenue(venue string)
- func (i *Instance) StartLevel(level string) (v LevelState)
- func (i *Instance) StockOrderStatus() []Order
- func (i *Instance) StopLevel() (v ErrorResult)
- func (i *Instance) VenueHeartbeat() ErrorResult
- type Instructions
- type LevelState
- type MarketRequest
- type Order
- type Orderbook
- type Quote
- type QuoteStream
- type Stock
Constants ¶
const ( Limit orderType = "limit" Market orderType = "market" FillOrKill orderType = "fill-or-kill" ImmediateOrCancel orderType = "immediate-or-cancel" Buy orderDirection = "buy" Sell orderDirection = "sell" )
Constants used for order creation.
Variables ¶
This section is empty.
Functions ¶
func SetBaseURL ¶
func SetBaseURL(URL string)
func SetBaseWSURL ¶
func SetBaseWSURL(URL string)
Types ¶
type ErrorResult ¶
ErrorResult gets returned inside every response of an API method. Allows for an alternative way of error checking (without calling i.GetErr()).
type Execution ¶
type Execution struct { ErrorResult Order Order `json:"order"` StandingID int `json:"standingId"` IncomingID int `json:"incomingId"` Price int `json:"price"` Filled int `json:"filled"` FilledAt time.Time `json:"filledAt"` StandingComplete bool `json:"standingComplete"` IncomingComplete bool `json:"incomingComplete"` }
The Execution struct gets only returned by websocket based calls.
type ExecutionStream ¶
type ExecutionStream struct { Values chan Execution // contains filtered or unexported fields }
ExecutionStream contains a Values chan which streams Executions. Implements streamer interface.
func (*ExecutionStream) Stopped ¶
func (s *ExecutionStream) Stopped() bool
Stopped returns true if the stream was stopped.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance is the basic unit of operation for all API actions.
func NewInstance ¶
NewInstance creates a new API instance and sets defaults. Shorcut for New() -> SetAccount() -> SetVenue() -> SetSymbol()
func NewTestInstance ¶
func NewTestInstance() *Instance
NewTestInstance calls NewInstance with useful presets for package testing.
func (*Instance) AccountOrderStatus ¶
AccountOrderStatus returns the current status for all orders of the current account on the current venue. See https://starfighter.readme.io/docs/status-for-all-orders for further info about the actual API call.
func (*Instance) AvailableStocks ¶
AvailableStocks returns the available stock on a venue. See https://starfighter.readme.io/docs/list-stocks-on-venue for further info about the actual API call.
func (*Instance) CancelOrder ¶
CancelOrder cancels an order given it's id. See https://starfighter.readme.io/docs/cancel-an-order for further info about the actual API call.
func (*Instance) Debug ¶
func (i *Instance) Debug()
Debug enables comprehensive logging for the instance.
func (*Instance) Executions ¶
func (i *Instance) Executions(stockOnly bool, account string) *ExecutionStream
Executions returns a stream which streams all executions for the current venue or only the current stock. Authentication is done with the account number A stream can be terminated with: stream.Stop() See https://starfighter.readme.io/docs/executions-fills-websocket for further info about API call.
func (*Instance) GetAccount ¶
GetAccount gets the current account of an instance.
func (*Instance) Heartbeat ¶
func (i *Instance) Heartbeat() ErrorResult
Heartbeat checks if the API is up and returns true if it is. See: https://starfighter.readme.io/docs/heartbeat for further info about API call.
func (*Instance) JudgeLevel ¶
func (i *Instance) JudgeLevel() (v ErrorResult)
JudgeLevel tells the API to judge the current level and clears the instance state. An instanceID needs to already set.
func (*Instance) NewOrder ¶
func (i *Instance) NewOrder(price int, quantity int, direction orderDirection, orderType orderType) (v Order)
NewOrder makes a new order and submits it to the API. See the package constants for available orderDirection and orderType types. NewOrder returns a Order struct of the created order. See https://starfighter.readme.io/docs/place-new-order for further info about the actual API call.
func (*Instance) OrderStatus ¶
OrderStatus returns the current order status for the given order id. See https://starfighter.readme.io/docs/status-for-an-existing-order for further info about the actual API call.
func (*Instance) Orderbook ¶
Orderbook returns the orderbook for the current stock on the current venue. See: https://starfighter.readme.io/docs/get-orderbook-for-stock for further info about the actual API call. Returns an empty Oderbook struct if there was an error.
func (*Instance) Quote ¶
Quote returns the quote for the current stock on the current venue. See https://starfighter.readme.io/docs/a-quote-for-a-stock for further info about the actual API call. Returns an empty Oderbook struct if there was an error.
func (*Instance) Quotes ¶
func (i *Instance) Quotes(stockOnly bool) *QuoteStream
Quotes returns a stream which streams all quotes for the current venue or only the current stock. A stream can be terminated with: stream.Stop() See https://starfighter.readme.io/docs/quotes-ticker-tape-websocket for further info about API call.
func (*Instance) ResetErr ¶
func (i *Instance) ResetErr()
ResetErr resets the error of an API instance to nil.
func (*Instance) RestartLevel ¶
func (i *Instance) RestartLevel() (v LevelState)
RestartLevel restarts the current level. An instanceID needs to already set.
func (*Instance) ResumeLevel ¶
func (i *Instance) ResumeLevel() (v LevelState)
ResumeLevel resumes the current level (and sets the instance state) and returns the levelstate. An instanceID needs to already set.
func (*Instance) SetAccount ¶
SetAccount changes the current account of an instance. Waits until all current read operations are completed and blocks while changing.
func (*Instance) SetInstanceID ¶
SetInstanceID changes the current instanceID. Waits until all current read operations are completed and blocks while changing.
func (*Instance) SetSymbol ¶
SetSymbol changes the current stock symbol of an instance. Waits until all current read operations are completed and blocks while changing.
func (*Instance) SetVenue ¶
SetVenue changes the current venue of an instance. Waits until all current read operations are completed and blocks while changing.
func (*Instance) StartLevel ¶
func (i *Instance) StartLevel(level string) (v LevelState)
StartLevel starts a level and sets the instance state. It returns the levelstate.
func (*Instance) StockOrderStatus ¶
StockOrderStatus returns the current status for all orders of the current stock on the current venue and account. See https://starfighter.readme.io/docs/status-for-all-orders-in-a-stock for further info about the actual API call.
func (*Instance) StopLevel ¶
func (i *Instance) StopLevel() (v ErrorResult)
StopLevel stops the current level and clears the instance state. An instanceID needs to already set.
func (*Instance) VenueHeartbeat ¶
func (i *Instance) VenueHeartbeat() ErrorResult
VenueHeartbeat works like Heartbeat() but for the current venue. See https://starfighter.readme.io/docs/venue-healthcheck for further info about the actual API call.
type Instructions ¶
type Instructions struct { Instructions string `json:"Instructions"` OrderTypes string `json:"Order Types"` }
Instructions returned from the stockfighter GameMaster-API.
type LevelState ¶
type LevelState struct { ErrorResult Account string `json:"account"` InstanceID int `json:"instanceId"` Instructions Instructions `json:"instructions"` SecondsPerTradingDay int `json:"secondsPerTradingDay"` Venues []string `json:"venues"` Symbols []string `json:"tickers"` }
LevelState contains all data returned by API call to GameMaster-API.
type MarketRequest ¶
type MarketRequest struct { Price int `json:"price"` Quantity int `json:"qty"` IsBuy bool `json:"isBuy"` }
A MarketRequest struct represents an open position (either bid or ask() in the orderbook.
type Order ¶
type Order struct { ErrorResult Account string `json:"account"` Venue string `json:"venue"` Symbol string `json:"symbol"` Price int `json:"price"` OriginalQuantity int `json:"orignialQty"` Quantity int `json:"qty"` Direction orderDirection `json:"direction"` OrderType orderType `json:"orderType"` ID int `json:"id"` TS time.Time `json:"ts"` Fills []Fill `json:"fills"` TotalFilled int `json:"totalFilled"` Open bool `json:"open"` }
The Order struct contains information about an order.
type Orderbook ¶
type Orderbook struct { ErrorResult Venue string `json:"venue"` Symbol string `json:"symbol"` Bids []MarketRequest `json:"bids"` Asks []MarketRequest `json:"asks"` TS time.Time `json:"ts"` }
The Orderbook struct contains everything that gets returned on the Orderbook() API call.
type Quote ¶
type Quote struct { ErrorResult Venue string `json:"venue"` Symbol string `json:"symbol"` Bid int `json:"bid"` Ask int `json:"ask"` BidSize int `json:"bidSize"` AskSize int `json:"askSize"` BidDepth int `json:"bidDepth"` AskDepth int `json:"askDepth"` LastPrice int `json:"last"` LastSize int `json:"lastSize"` LastTrade time.Time `json:"lastTrade"` QuoteTime time.Time `json:"quoteTime"` }
The Quote struct contains all data that gets returned on a Quote() call.
type QuoteStream ¶
type QuoteStream struct { Values chan Quote // contains filtered or unexported fields }
QuoteStream contains a Values chan which streams Quotes. Implements streamer interface.
func (*QuoteStream) Stopped ¶
func (s *QuoteStream) Stopped() bool
Stopped returns true if the stream was stopped.