api

package
v4.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NY, _ = time.LoadLocation("America/New_York")

	CacheDir  = ""
	FromCache = false
)

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 represention

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 represention

func SetAPIKey

func SetAPIKey(key string)

func SetBaseURL

func SetBaseURL(url 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(
	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(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(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 {
	Symbol string `json:"sym"`
	Volume int    `json:"v"`

	Open        float64 `json:"o"`
	Close       float64 `json:"c"`
	High        float64 `json:"h"`
	Low         float64 `json:"l"`
	EpochMillis int64   `json:"s"`
	// contains filtered or unexported fields
}

type PolyQuote

type PolyQuote struct {
	Symbol string `json:"sym"`

	BidPrice float64 `json:"bp"`
	BidSize  int     `json:"bs"`

	AskPrice float64 `json:"ap"`
	AskSize  int     `json:"as"`

	Timestamp int64 `json:"t"`
	// contains filtered or unexported fields
}

type PolyTrade

type PolyTrade struct {
	Symbol string `json:"sym"`

	Price      float64 `json:"p"`
	Size       int     `json:"s"`
	Timestamp  int64   `json:"t"`
	Conditions []int   `json:"c"`
	// contains filtered or unexported fields
}

Streaming Schema from Polygon

// Stocks QUOTE:

{
    "ev": "Q",              // Event Type
    "sym": "MSFT",          // Symbol Ticker
    "bx": "4",              // Bix Exchange ID
    "bp": 114.125,          // Bid Price
    "bs": 100,              // Bid Size
    "ax": "7",              // Ask Exchange ID
    "ap": 114.128,          // Ask Price
    "as": 160,              // Ask Size
    "c": 0,                 // Quote Condition
    "t": 1536036818784      // Quote Timestamp ( Unix MS )
}

// Stocks Aggregate:

{
    "ev": "AM",             // Event Type ( A = Second Agg, AM = Minute Agg )
    "sym": "MSFT",          // Symbol Ticker
    "v": 10204,             // Tick Volume
    "av": 200304,           // Accumlated Volume ( Today )
    "op": 114.04,           // Todays official opening price
    "vw": 114.4040,         // VWAP (Volume Weighted Average Price)
    "o": 114.11,            // Tick Open Price
    "c": 114.14,            // Tick Close Price
    "h": 114.19,            // Tick High Price
    "l": 114.09,            // Tick Low Price
    "a": 114.1314,          // Tick Average / VWAP Price
    "s": 1536036818784,     // Tick Start Timestamp ( Unix MS )
    "e": 1536036818784,     // Tick End Timestamp ( Unix MS )
}

Streaming data

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)

servers := utils.Settings["WS_SERVERS"]

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 ListTickers

func ListTickers() ([]Ticker, error)

func ListTickersPerPage added in v4.0.2

func ListTickersPerPage(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