api

package
v4.1.23 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CacheDir  = ""
	FromCache = false
)

QuoteConditionMapping provides a mapping from Polygon integer format to Marketstore's internal representation. nolint:dupl // config map.

TradeConditionMapping provides a mapping from Polygon integer format to Marketstore's internal representation.

Functions

func ConvertExchangeCode added in v4.1.0

func ConvertExchangeCode(exchange int) enum.Exchange

ConvertExchangeCode converts a Polygon exchange id to the internal representation.

func ConvertQuoteCondition added in v4.1.0

func ConvertQuoteCondition(condition int) enum.QuoteCondition

ConvertQuoteCondition converts between Polygon trade condition format and Marketstore's internal representing.

func ConvertTapeCode added in v4.1.0

func ConvertTapeCode(tape int) enum.Tape

ConvertTapeCode converts between Polygons' TapeID and Marketstore's internal representation.

func ConvertTradeCondition added in v4.1.0

func ConvertTradeCondition(condition int) enum.TradeCondition

ConvertTradeCondition converts between Polygon trade condition format and Marketstore's internal representing.

func SetAPIKey

func SetAPIKey(key string)

func SetBaseURL

func SetBaseURL(bURL string)

func SetWSServers

func SetWSServers(serverList string)

Types

type AggResult added in v4.0.1

type AggResult struct {
	// Volume should be int but json.Decode fails with: "cannot unmarshal number 1.70888e+06 into Go struct"
	Volume            float64 `json:"v"`
	Open              float64 `json:"o"`
	Close             float64 `json:"c"`
	High              float64 `json:"h"`
	Low               float64 `json:"l"`
	EpochMilliseconds int64   `json:"t"`
	NumberOfItems     int     `json:"n"`
}

AggResult is the structure that defines the actual Aggregate result.

type GetAggregatesResponse

type GetAggregatesResponse struct {
	Symbol  string `json:"symbol"`
	AggType string `json:"aggType"`
	Map     struct {
		O string `json:"o"`
		C string `json:"c"`
		H string `json:"h"`
		L string `json:"l"`
		V string `json:"v"`
		D string `json:"d"`
	} `json:"map"`
	Ticks []struct {
		Open        float64 `json:"o"`
		Close       float64 `json:"c"`
		High        float64 `json:"h"`
		Low         float64 `json:"l"`
		Volume      int     `json:"v"`
		EpochMillis int64   `json:"d"`
	} `json:"ticks"`
}

type HistoricAggregates

type HistoricAggregates struct {
	Ticker      string      `json:"ticker"`
	Status      string      `json:"status"`
	Adjusted    bool        `json:"adjusted"`
	QueryCount  int         `json:"queryCount"`
	ResultCount int         `json:"resultCount"`
	Results     []AggResult `json:"results"`
}

HistoricAggregates is the structure that defines aggregate data served through polygon's REST API.

func GetHistoricAggregates

func GetHistoricAggregates(
	client *http.Client,
	ticker,
	timespan string,
	multiplier int,
	from, to time.Time,
	limit *int,
	unadjusted bool,
) (*HistoricAggregates, error)

GetHistoricAggregates requests polygon's REST API for aggregates for the provided resolution based on the provided parameters.

type HistoricQuotes

type HistoricQuotes struct {
	Day string `json:"day"`
	Map struct {
		AE string `json:"aE"`
		AP string `json:"aP"`
		AS string `json:"aS"`
		BE string `json:"bE"`
		BP string `json:"bP"`
		BS string `json:"bS"`
		C  string `json:"c"`
		T  string `json:"t"`
	} `json:"map"`
	MsLatency int         `json:"msLatency"`
	Status    string      `json:"status"`
	Symbol    string      `json:"symbol"`
	Ticks     []QuoteTick `json:"ticks"`
	Type      string      `json:"type"`
}

HistoricQuotes is the structure that defines quote data served through polygon's REST API.

func GetHistoricQuotes

func GetHistoricQuotes(client *http.Client, symbol, date string, batchSize int,
) (totalQuotes *HistoricQuotes, err error)

GetHistoricQuotes requests polygon's REST API for historic quotes on the provided date.

type HistoricTrades

type HistoricTrades struct {
	Ticker       string      `json:"ticker"`
	Success      bool        `json:"success"`
	ResultsCount int         `json:"results_count"`
	Results      []TradeTick `json:"results"`
	DBLatency    int         `json:"db_latency"`
}

HistoricTrades is the structure that defines trade data served through polygon's REST API.

func GetHistoricTrades

func GetHistoricTrades(client *http.Client, symbol, date string, batchSize int,
) (totalTrades *HistoricTrades, err error)

GetHistoricTrades requests polygon's REST API for historic trades on the provided date .

type ListTickersResponse

type ListTickersResponse struct {
	Page    int      `json:"page"`
	PerPage int      `json:"perPage"`
	Count   int      `json:"count"`
	Status  string   `json:"status"`
	Tickers []Ticker `json:"tickers"`
}

type PolyAggregate

type PolyAggregate struct {
	// eventType    string  `json:"-"` //ev
	Symbol string `json:"sym"`
	Volume int    `json:"v"`
	// accumVolume  int     `json:"-"`
	// officialOpen float64 `json:"-"`
	// vWAP         float64 `json:"-"`
	Open        float64 `json:"o"`
	Close       float64 `json:"c"`
	High        float64 `json:"h"`
	Low         float64 `json:"l"`
	EpochMillis int64   `json:"s"`
}

type PolyQuote

type PolyQuote struct {
	// eventType   string  `json:"-"` //ev
	Symbol string `json:"sym"`
	// bidExchange int     `json:"-"`
	BidPrice float64 `json:"bp"`
	BidSize  int     `json:"bs"`
	// askExchange int     `json:"-"`
	AskPrice float64 `json:"ap"`
	AskSize  int     `json:"as"`
	// condition   int     `json:"-"`
	Timestamp int64 `json:"t"`
}

type PolyTrade

type PolyTrade struct {
	// eventType string `json:"-"` // ev
	Symbol string `json:"sym"`
	// exchange   int     `json:"-"` // x
	Price      float64 `json:"p"`
	Size       int     `json:"s"`
	Timestamp  int64   `json:"t"`
	Conditions []int   `json:"c"`
}

type PolygonWebSocket

type PolygonWebSocket struct {
	Servers []*url.URL
	// contains filtered or unexported fields
}

func NewPolygonWebSocket

func NewPolygonWebSocket(servers, apiKey string, pref Prefix, symbols []string, oChan chan interface{},
) *PolygonWebSocket

type Prefix

type Prefix string
const (
	OfficialOpeningPrice Prefix = "OO."
	OfficialClosingPrice Prefix = "OC."
	OpeningPrice         Prefix = "O."
	ReOpeningPrice       Prefix = "RO."
	ClosingPrice         Prefix = "C."
	Trade                Prefix = "T."
	Quote                Prefix = "Q."
	Agg                  Prefix = "AM."
)

type QuoteTick

type QuoteTick struct {
	Timestamp   int64   `json:"t"`
	BidExchange int     `json:"bE"`
	AskExchange int     `json:"aE"`
	BidPrice    float64 `json:"bP"`
	AskPrice    float64 `json:"aP"`
	BidSize     int     `json:"bS"`
	AskSize     int     `json:"aS"`
	Condition   int     `json:"c"`
	Tape        int     `json:"z"`
}

QuoteTick is the structure that contains the actual tick data included in a HistoricQuotes response.

type Subscription

type Subscription struct {
	Incoming chan interface{}

	sync.Mutex
	// contains filtered or unexported fields
}

func NewSubscription

func NewSubscription(t Prefix, symbols []string) (s *Subscription)

func (*Subscription) GetHandled

func (s *Subscription) GetHandled() int

func (*Subscription) Hangup

func (s *Subscription) Hangup()

func (*Subscription) IncrementHandled

func (s *Subscription) IncrementHandled()

func (*Subscription) IsActive

func (s *Subscription) IsActive() bool

func (*Subscription) ResetHandled

func (s *Subscription) ResetHandled()

func (*Subscription) Subscribe

func (s *Subscription) Subscribe(handler func(msg []byte))

Subscribe to a websocket connection for a given data type by providing a channel that the messages will be written to.

type SubscriptionScope

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

func NewSubscriptionScope

func NewSubscriptionScope(scope Prefix, symbols []string) *SubscriptionScope

func (SubscriptionScope) GetSubScope

func (s SubscriptionScope) GetSubScope() string

type Ticker added in v4.0.2

type Ticker struct {
	Ticker      string `json:"ticker"`
	Name        string `json:"name"`
	Market      string `json:"market"`
	Locale      string `json:"locale"`
	Type        string `json:"type"`
	Currency    string `json:"currency"`
	Active      bool   `json:"active"`
	PrimaryExch string `json:"primaryExch"`
	Updated     string `json:"updated"`
	Codes       struct {
		Cik     string `json:"cik"`
		Figiuid string `json:"figiuid"`
		Scfigi  string `json:"scfigi"`
		Cfigi   string `json:"cfigi"`
		Figi    string `json:"figi"`
	} `json:"codes"`
	URL string `json:"url"`
}

func ListTickersPerPage added in v4.0.2

func ListTickersPerPage(client *http.Client, page int) ([]Ticker, error)

type TradeTick

type TradeTick struct {
	ParticipantTimestamp int64   `json:"y"` // Participant/Exchange timestamp
	TrfTimestamp         int64   `json:"f"`
	SIPTimestamp         int64   `json:"t"` // Optional
	Price                float64 `json:"p"`
	Size                 int     `json:"s"`
	Exchange             int     `json:"x"`
	Conditions           []int   `json:"c"`
	ID                   string  `json:"i"`
	Correction           int     `json:"e"`
	SequenceNumber       int     `json:"q"`
	TrfID                int     `json:"r"`
	Tape                 int     `json:"z"`
	OrigID               string  `string:"I"`
}

TradeTick is the structure that contains the actual tick data included in a HistoricTrades response.

Jump to

Keyboard shortcuts

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