api

package
v0.0.0-...-66d8c45 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package api contains a wrapper for the stockfighter.io API.

Index

Constants

View Source
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

type ErrorResult struct {
	Ok      bool   `json:"ok"`
	Message string `json:"error"`
}

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

func (s *ExecutionStream) Stop()

Stop stops the Stream.

func (*ExecutionStream) Stopped

func (s *ExecutionStream) Stopped() bool

Stopped returns true if the stream was stopped.

type Fill

type Fill struct {
	Price    int       `json:"price"`
	Quantity int       `json:"qty"`
	TS       time.Time `json:"ts"`
}

The Fill struct represents a (partial) fulfillment of an order.

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

Instance is the basic unit of operation for all API actions.

func New

func New(apiKey string) (i *Instance)

New creates a new API instance without any presets.

func NewInstance

func NewInstance(apiKey, account, venue, symbol string) (i *Instance)

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

func (i *Instance) AccountOrderStatus() []Order

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

func (i *Instance) AvailableStocks() []Stock

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

func (i *Instance) CancelOrder(ID int) (v Order)

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

func (i *Instance) GetAccount() string

GetAccount gets the current account of an instance.

func (*Instance) GetErr

func (i *Instance) GetErr() error

GetErr returns the last error of an API instance.

func (*Instance) GetSymbol

func (i *Instance) GetSymbol() string

GetSymbol gets the current stock symbol of an instance.

func (*Instance) GetVenue

func (i *Instance) GetVenue() string

GetVenue gets the current venue 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

func (i *Instance) OrderStatus(ID int) (v Order)

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

func (i *Instance) Orderbook() (v 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

func (i *Instance) Quote() (v 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) SetAPIKey

func (i *Instance) SetAPIKey(apiKey string)

SetAPIKey changes the API-Key of an instance.

func (*Instance) SetAccount

func (i *Instance) SetAccount(account string)

SetAccount changes the current account of an instance. Waits until all current read operations are completed and blocks while changing.

func (*Instance) SetInstanceID

func (i *Instance) SetInstanceID(instanceID int)

SetInstanceID changes the current instanceID. Waits until all current read operations are completed and blocks while changing.

func (*Instance) SetSymbol

func (i *Instance) SetSymbol(symbol string)

SetSymbol changes the current stock symbol of an instance. Waits until all current read operations are completed and blocks while changing.

func (*Instance) SetVenue

func (i *Instance) SetVenue(venue string)

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

func (i *Instance) StockOrderStatus() []Order

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

func (s *QuoteStream) Stop()

Stop stops the Stream.

func (*QuoteStream) Stopped

func (s *QuoteStream) Stopped() bool

Stopped returns true if the stream was stopped.

type Stock

type Stock struct {
	Name   string `json:"name"`
	Symbol string `json:"symbol"`
}

The Stock struct contains the name and the ticker symbol of a stock.

Jump to

Keyboard shortcuts

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