intrinio

package module
v0.0.0-...-10bd469 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

README

intrinio-realtime-go-sdk

Go SDK for working with Intrinio's Real-Time WebSocket Feeds. This package provides facilities for working with both equity and option feeds.

Intrinio provides real-time stock prices and option prices via two-way WebSocket connections. To get started, subscribe to a real-time equity data feed or real-time option data feed and follow the instructions below.

Requirements

  • Go 1.20 (or newer) recommended

Installation

Option 1 - Docker
  1. Source files can be downloaded from: github.com/intrinio/intrinio-realtime-go-sdk
  2. Navigate to the project root
  3. Update the ENV parameter in the dockerfile with your API key
  4. Run docker compose build
  5. Run docker compose run example
Option 2 - From source
  1. Source files can be downloaded from: github.com/intrinio/intrinio-realtime-go-sdk
  2. Navigate to the project root
  3. Open the example project at project-root/example
  4. Build your project using example.go as the base
Option 3 - Pre built package
  1. Create a new Go project
  2. import "github.com/intrinio/intrinio-realtime-go-sdk"
  3. Reference the package "intrinio"

Example Project

For a sample Go application see: intrinio-realtime-options-go-sdk

Features

  • Receive streaming, real-time equity price updates:
    • every trade
    • top-of-book ask and bid
  • Subscribe to updates from individual securities
  • Subscribe to updates for all securities
  • Receive streaming, real-time option price updates:
    • every trade
    • conflated bid and ask
    • open interest, open, close, high, low
    • unusual activity(block trades, sweeps, whale trades, unusual sweeps)
  • Subscribe to updates from individual option contracts (or option chains)
  • Subscribe to updates for the entire universe of option contracts (~1.5M option contracts)
  • Receive updates for both equity share and option contract updates, simultaneously

Example Usage


package main

import (
	"os"
	"os/signal"
	"sync"
	"syscall"

	"github.com/intrinio/intrinio-realtime-go-sdk"
)

func handleEquityTrade(trade intrinio.EquityTrade) {
}

func handleEquityQuote(quote intrinio.EquityQuote) {
}

func handleOptionRefresh(refresh intrinio.OptionRefresh) {
}

func handleOptionTrade(trade intrinio.OptionTrade) {
}

func handleOptionQuote(quote intrinio.OptionQuote) {
}

func handleOptionUA(ua intrinio.OptionUnusualActivity) {
}

func main() {
	var equitiesConfig intrinio.Config = intrinio.LoadConfig("equities-config.json")
	var optionsConfig intrinio.Config = intrinio.LoadConfig("options-config.json")
	var equitiesClient *intrinio.Client = intrinio.NewEquitiesClient(equitiesConfig, handleEquityTrade, handleEquityQuote)
	var optionsClient *intrinio.Client = intrinio.NewOptionsClient(optionsConfig, handleOptionTrade, nil, handleOptionRefresh, nil)
	close := make(chan os.Signal, 1)
	signal.Notify(close, syscall.SIGINT, syscall.SIGTERM)
	equitiesClient.Start()
	optionsClient.Start()
	symbols := []string{"GE", "MSFT"}
	equitiesClient.JoinMany(symbols)
	optionsClient.JoinMany(symbols)
	//client.JoinLobby()
	<-close
	equitiesClient.Stop()
	optionsClient.Stop()
}

Usage notes (applies to both equity and option clients)

There are thousands of securities and millions of options contracts, each with their own feed of activity. We highly encourage you to make your callback methods (e.g. onTrade, onQuote, onUnusualActivity, onRefresh) as short as possible and follow a queue pattern so your app can handle the large volume of activity. Note that quotes (ask and bid updates) comprise 90-99% of the volume of the entire feed. Be cautious when deciding to receive quote updates. With the option feed, you will receive the latest 'ask' and 'bid' price with each each trade update. You may subscribe to receive a quote updates for ask/bid prices (by providing an OnQuote callback to intrinio.NewOptionsClient or intrinio.NewEquitiesClient) but, again, we recommend caution when electing to do this.

Providers

Currently, Intrino offers realtime data for this SDK from the following providers:

  • DSIP - Delayed SIP
  • OPRA - The Option Price Reporting Authority

Please be sure that the correct provider is specified in the intrinio.Config object(s) that are passed to the intrinio.NewEquitiesClient or intrinio.NewOptionsClient routines. DSIP should be specified for an equities client and OPRA should be specified for an options client.

Data Format (Equities)

Trade Message
type EquityTrade struct
  • Symbol - Ticker symbol
  • Price - The trade price in USD
  • Size - The size of the trade
  • TotalVolume - The total number of shares traded so far, today.
  • Timestamp - The time of the trade, as a Unix timestamp (with microsecond precision)
Quote Message
type EquityQuote struct
  • Type - The quote type
    • Ask - Represents an 'Ask' type
    • Bid - Represents a 'Bid' type
  • Symbol - Ticker symbol
  • Price - The last, best ask or bid price in USD
  • Size - The last, best ask or bid size
  • Timestamp - The time of the quote, as a Unix timestamp (with microsecond precision)

Data Format (Options)

Trade Message
type OptionTrade struct
  • ContractId - Identifier for the option contract. This includes the ticker symbol, put/call, expiry, and strike price.
  • Exchange - The specific exchange through which the trade occurred (enum)
  • Price - The trade price in USD
  • Size - The size of the trade (note: each contract represents a lot of 100 underlying shares).
  • Qualifiers - A 4-byte array: each byte represents one trade qualifier. see list of possible Trade Qualifiers, below.
  • TotalVolume - The total number of contracts (with the given Id) traded so far, today.
  • Timestamp - The time of the trade, as a Unix timestamp (with microsecond precision)
  • AskPriceAtExecution - The best, last ask price in USD
  • BidPriceAtExecution - The best, last bid price in USD
  • UnderlyingPriceAtExecution - The price of the underlying security in USD
Trade Qualifiers

The trade qualifiers field is represented by a tuple containing 4 integers. Each integer can take one of the following values:

  • 0 - Regular transaction
  • 2 - Cancel
  • 3 - This is the last price and it's cancelled
  • 4 - Late but in sequence / sold last late
  • 5 - This was the open price and it's cancelled
  • 6 - Late report of opening trade and is out of sequence: or set the open
  • 7 - Cancel only trade reported
  • 8 - Transaction was executed electronically
  • 9 - Reopen of a previously halted contract
  • 11 - Spread
  • 23 - Intermarket Sweep
  • 30 - Extended hours
  • 33 - Crossed trade including Request For Cross RFC
  • 87 - Complex trade with equity leg
  • 107 - Auction
  • 123 - Stock option trade
  • 136 - Ex-Pit trade
  • 192 - Message received locally out-of-sequence
  • 222 - Combo trade
  • 0 - Blank

Each trade can be qualified by a maximum of 4(four) values. The combination of these values can have special values. These special values are:

  • 107, 23 - Single leg auction ISO
  • 23, 33 - Single leg cross ISO
  • 8, 11 - Multi leg auto-electronic trade
  • 107, 11 - Multi leg auction
  • 11, 33 - Multi leg cross
  • 136, 11 - Multi leg floor trade
  • 8, 11, 87 - Multi leg auto-electronic trade against single leg(s)
  • 107, 123 - Stock options auction
  • 107, 11, 87 - Multi leg auction against single leg(s)
  • 136, 11, 87 - Multi leg floor trade against single leg(s)
  • 8, 123 - Stock options auto-electronic trade
  • 123, 33 - Stock options cross
  • 136, 123 - Stock options floor trade
  • 8, 87, 123 - Stock options auto-electronic trade against single leg(s)
  • 107, 87, 123 - Stock options auction against single leg(s)
  • 136, 87, 123 - Stock options floor trade against single leg(s)
  • 136, 11, 222 - Multi leg floor trade of proprietary products
  • 222, 30 - Multilateral Compression Trade of Proprietary Data Products
Quote Message
type OptionQuote struct
  • ContractId - Identifier for the option contract. This includes the ticker symbol, put/call, expiry, and strike price.
  • AskPrice - The last, best ask price in USD
  • AskSize - The last, best ask size (note: each contract represents a lot of 100 underlying shares).
  • BidPrice - The last, best bid price in USD
  • BidSize - The last, best bid size (note: each contract represents a lot of 100 underlying shares).
  • Timestamp - The time of the quote, as a Unix timestamp (with microsecond precision)
Refresh Message
type OptionRefresh
  • ContractId - Identifier for the options contract. This includes the ticker symbol, put/call, expiry, and strike price.
  • OpenInterest - The total quantity of opened contracts, as reported at the start of the trading day
  • OpenPrice - The open price price in USD
  • ClosePrice - The close price in USD
  • HighPrice - The current high price in USD
  • LowPrice - The current low price in USD
Unusual Activity Message
type OptionUnusualActivity
  • ContractId - Identifier for the options contract. This includes the ticker symbol, put/call, expiry, and strike price.
  • Type - The type of unusual activity that was detected
    • Block - represents a 'block' trade of at least $20,000
    • Sweep - represents an intermarket sweep of at least $10,000
    • Large - represents a trade of at least $100,000
    • Unusual Sweep - represents an unusually large sweep (more than 2 standard deviation above the market-wide sweep mean).
  • Sentiment - The sentiment of the unusual activity event
    • Neutral - The event was executed with apparent neutral outlook of the underlying security
    • Bullish - The event was executed with apparent positive outlook of the underlying security
    • Bearish - The event was executed with apparent negative outlook of the underlying security
  • TotalValue - The total value of the event in USD. 'Sweeps' and 'blocks' can be comprised of multiple trades. This is the value of the entire event.
  • TotalSize - The total size of the event in number of contracts. 'Sweeps' and 'blocks' can be comprised of multiple trades. This is the total number of contracts exchanged during the event.
  • AveragePrice - The average price at which the event was executed. 'Sweeps' and 'blocks' can be comprised of multiple trades. This is the average trade price for the entire event.
  • AskPriceAtExecution - The 'ask' price of the contract at execution of the event.
  • BidPriceAtExecution - The 'bid' price of the contract at execution of the event.
  • UnderlyingPriceAtExecution - The last trade price of the underlying security at execution of the event.
  • Timestamp - The time of the event, as a Unix timestamp (with microsecond precision).

API Keys

You will receive your Intrinio API Key after creating an account. You will need a subscription to a realtime equity data feed or realtime option data feed as well.

Please be sure to include you API key in the intrinio.Config object passed to either the intrinio.NewEquitiesClient or intrinio.NewOptionsClient routine.

Alternatively, you may create an environment variable, INTRINIO_API_KEY, and set your API key as the value. The intrinio.LoadConfig(filename) function will pick it up from there, automatically.

Documentation

Overview

The Intrinio Realtime Client will handle authorization as well as establishment and management of all necessary WebSocket connections. All you need to get started is your API key. The first thing that you'll do is create a new intrinio.Client object using either the NewEquitiesClient or NewOptionsClient routine, passing in an intrinio.Config object as well as a series of callback functions. These callback methods tell the client what types of subscriptions you will be setting up. A helper function, intrinio.LoadConfig(filename string), is provided to automatically load a .json file that exists in your application's working directory. Please be sure that your API key is specified in the intrinio.Config object that is passed to one of the intrinio.New[Equities/Options]Client routine. Creating an intrinio.Client object will initialize the object but you will need to call the client object's Start() method in order to open the session and start communication with the server. After an intrinio.Client object has been created and started, you may subscribe to receive feed updates from the server. You may subscribe, dynamically, to individual or multiple ticker symbols (in the case of an Equities client) or to option contracts, option chains, or a mixed list thereof (in the case of an Options client). It is also possible to subscribe to the entire universe of ticker symbols or option contracts (i.e. the firehose) by calling the client object's JoinLobby() method. The volume of data provided by the Firehose can exceed 100Mbps and requires special authorization. You may update your subscriptions on the fly, using the client object's Join and Leave methods. The WebSocket client is designed for near-indefinite operation. It will automatically reconnect if a connection drops/fails and when then servers turn on every morning. If you wish to perform a shutdown of the application, please call the client's Stop method. See the example application for an example of how to handle system SIGINT (Ctrl+C) and SIGTERM signals

Methods

var client Client = NewEquitiesClient(config, onTrade, onQuote) - Creates an Intrinio Real-Time client for use with a real-time equity feed (DSIP).

  • Parameter config: Required. The configuration object necessary to set up the client.
  • Parameter onTrade: Required. The callback accepting intrinio.EquityTrade updates.
  • Parameter onQuote: Optional. The callback accepting intrinio.EquityQuote updates. If onQuote is nil, you will not receive quote (ask, bid) updates from the server.

var client Client = NewOptionsClient(config, onTrade, onQuote, onRefresh, onUnusualActivity) - Creates an Intrinio Real-Time client for use with a real-time option feed (OPRA).

  • Parameter config: Required. The configuration object necessary to set up the client.
  • Parameter onTrade: Optional. The callback accepting intrinio.OptionTrade updates. If onTrade is nil, you will not receive trade updates from the server.
  • Parameter onQuote: Optional. The callback accepting intrinio.OptionQuote updates. If onQuote is nil, you will not receive quote (ask, bid) updates from the server.
  • Parameter onRefresh: Optional. The callback accepting intrinio.OptionRefresh updates. If onRefresh is nil, you will not receive open interest, open, close, high, low data from the server. Note: open interest data is only updated at the beginning of every trading day. If this callback is provided you will recieve an update immediately, as well as every 15 minutes (approx).
  • Parameter onUnusualActivity: Optional. The callback accepting intrinio.OptionUnusualActivity updats. If onUnusualActivity is nil, you will not receive unusual activity updates from the server.

client.Start() - Starts the client (authenticates the user and establishes the websocket connection) client.Stop() - Leaves all joined channels and gracefully terminates the session.

client.Join(symbol string) - Joins the channel identified by the given symbol, contractId, or option chain (e.g. "AAPL" or "GOOG__210917C01040000") client.JoinMany(symbols []string) - Joins the channels identified by the given symbol slice (e.g. []string{"AAPL", "MSFT__210917C00180000", "GOOG__210917C01040000"}) client.JoinLobby() - Joins the lobby (i.e. 'Firehose') channel. This requires special account permissions.

client.LeaveAll() - Leaves all channels that have been subscribed to by the client client.Leave(symbol string) - Leaves the channel identified by the given symbol client.LeaveMany(symbols []string) - Leaves the channels identified by the given symbol slice client.LeaveLobby() - Leaves the lobby channel.

Configuration

Configuration is done through a configuration object (intrinio.Config) that is passed to the intrinio.New[Equities/Options]Client routine. You may create a configuration directly, in code, like so:

var config intrinio.Config = intrinio.Config{ApiKey: "YOUR-API-KEY", Provider: "OPRA/DSIP"}

Or, you can create .json config files, of the following form, and place them in your application root. An example of this is provided in the sample project.

{
	"ApiKey": "YOUR-API-KEY",
	"Provider": "OPRA/DSIP",
}

You can then create your config objects using:

var config intrinio.Config = intrinio.LoadConfig("[options/equities]Config.json")

Documentation

Index

Constants

View Source
const (
	HEARTBEAT_INTERVAL       int = 20
	MAX_OPTIONS_QUEUE_DEPTH  int = 20000
	MAX_EQUITIES_QUEUE_DEPTH int = 10000
)
View Source
const (
	MAX_OPTION_SYMBOL_SIZE  int = 21
	OPTION_TRADE_MSG_SIZE   int = 72
	OPTION_QUOTE_MSG_SIZE   int = 52
	OPTION_REFRESH_MSG_SIZE int = 52
	OPTION_UA_MSG_SIZE      int = 74
)
View Source
const TIME_FORMAT string = "060102"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewEquitiesClient

func NewEquitiesClient(
	c Config,
	onTrade func(EquityTrade),
	onQuote func(EquityQuote)) *Client

func NewOptionsClient

func NewOptionsClient(
	c Config,
	onTrade func(OptionTrade),
	onQuote func(OptionQuote),
	onRefresh func(OptionRefresh),
	onUnusualActivity func(OptionUnusualActivity)) *Client

func (*Client) Join

func (client *Client) Join(symbol string)

func (*Client) JoinLobby

func (client *Client) JoinLobby()

func (*Client) JoinMany

func (client *Client) JoinMany(symbols []string)

func (*Client) Leave

func (client *Client) Leave(symbol string)

func (*Client) LeaveAll

func (client *Client) LeaveAll()

func (*Client) LeaveLobby

func (client *Client) LeaveLobby(composeLeave func(string))

func (*Client) LeaveMany

func (client *Client) LeaveMany(symbols []string)

func (*Client) LogStats

func (client *Client) LogStats()

func (*Client) Start

func (client *Client) Start()

func (*Client) Stop

func (client *Client) Stop()

type Config

type Config struct {
	ApiKey    string
	Provider  Provider
	IPAddress string
}

func LoadConfig

func LoadConfig(filename string) Config

type EquityQuote

type EquityQuote struct {
	Type         QuoteType
	Symbol       string
	Source       uint8
	MarketCenter rune
	Price        float32
	Size         uint32
	Timestamp    float64
	Conditions   string
}

type EquityTrade

type EquityTrade struct {
	Symbol       string
	Source       uint8
	MarketCenter rune
	Price        float32
	Size         uint32
	TotalVolume  uint32
	Timestamp    float64
	Conditions   string
}

type Exchange

type Exchange uint8
const (
	NYSE_AMERICAN Exchange = 'A'
	BOSTON        Exchange = 'B'
	CBOE          Exchange = 'C'
	MIAMI_EMERALD Exchange = 'D'
	BATS_EDGX     Exchange = 'E'
	ISE_GEMINI    Exchange = 'H'
	ISE           Exchange = 'I'
	MERCURY       Exchange = 'J'
	MIAMI         Exchange = 'M'
	MIAMI_PEARL   Exchange = 'O'
	NYSE_ARCA     Exchange = 'P'
	NASDAQ        Exchange = 'Q'
	NASDAQ_BX     Exchange = 'T'
	MEMX          Exchange = 'U'
	CBOE_C2       Exchange = 'W'
	PHLX          Exchange = 'X'
	BATS_BZX      Exchange = 'Z'
)

func (Exchange) String

func (e Exchange) String() string

type OptionQuote

type OptionQuote struct {
	ContractId string
	AskPrice   float32
	BidPrice   float32
	AskSize    uint32
	BidSize    uint32
	Timestamp  float64
}

func (OptionQuote) GetExpirationDate

func (quote OptionQuote) GetExpirationDate() time.Time

func (OptionQuote) GetStrikePrice

func (quote OptionQuote) GetStrikePrice() float32

func (OptionQuote) GetUnderlyingSymbol

func (quote OptionQuote) GetUnderlyingSymbol() string

func (OptionQuote) IsCall

func (quote OptionQuote) IsCall() bool

func (OptionQuote) IsPut

func (quote OptionQuote) IsPut() bool

type OptionRefresh

type OptionRefresh struct {
	ContractId   string
	OpenInterest uint32
	OpenPrice    float32
	ClosePrice   float32
	HighPrice    float32
	LowPrice     float32
}

func (OptionRefresh) GetExpirationDate

func (refresh OptionRefresh) GetExpirationDate() time.Time

func (OptionRefresh) GetStrikePrice

func (refresh OptionRefresh) GetStrikePrice() float32

func (OptionRefresh) GetUnderlyingSymbol

func (refresh OptionRefresh) GetUnderlyingSymbol() string

func (OptionRefresh) IsCall

func (refresh OptionRefresh) IsCall() bool

func (OptionRefresh) IsPut

func (refresh OptionRefresh) IsPut() bool

type OptionTrade

type OptionTrade struct {
	ContractId                 string
	Exchange                   Exchange
	Price                      float32
	Size                       uint32
	Qualifiers                 [4]byte
	TotalVolume                uint64
	AskPriceAtExecution        float32
	BidPriceAtExecution        float32
	UnderlyingPriceAtExecution float32
	Timestamp                  float64
}

func (OptionTrade) GetExpirationDate

func (trade OptionTrade) GetExpirationDate() time.Time

func (OptionTrade) GetStrikePrice

func (trade OptionTrade) GetStrikePrice() float32

func (OptionTrade) GetUnderlyingSymbol

func (trade OptionTrade) GetUnderlyingSymbol() string

func (OptionTrade) IsCall

func (trade OptionTrade) IsCall() bool

func (OptionTrade) IsPut

func (trade OptionTrade) IsPut() bool

type OptionUnusualActivity

type OptionUnusualActivity struct {
	ContractId                 string
	Type                       UAType
	Sentiment                  UASentiment
	TotalValue                 float32
	TotalSize                  uint32
	AveragePrice               float32
	AskPriceAtExecution        float32
	BidPriceAtExecution        float32
	UnderlyingPriceAtExecution float32
	Timestamp                  float64
}

func (OptionUnusualActivity) GetExpirationDate

func (ua OptionUnusualActivity) GetExpirationDate() time.Time

func (OptionUnusualActivity) GetStrikePrice

func (ua OptionUnusualActivity) GetStrikePrice() float32

func (OptionUnusualActivity) GetUnderlyingSymbol

func (ua OptionUnusualActivity) GetUnderlyingSymbol() string

func (OptionUnusualActivity) IsCall

func (ua OptionUnusualActivity) IsCall() bool

func (OptionUnusualActivity) IsPut

func (ua OptionUnusualActivity) IsPut() bool

type Provider

type Provider string
const (
	OPRA         Provider = "OPRA"
	IEX          Provider = "IEX"
	DELAYED_SIP  Provider = "DELAYED_SIP"
	NASDAQ_BASIC Provider = "NASDAQ_BASIC"
	MANUAL       Provider = "MANUAL"
)

type QuoteType

type QuoteType uint8
const (
	ASK QuoteType = 1
	BID QuoteType = 2
)

type UASentiment

type UASentiment uint8
const (
	NEUTRAL UASentiment = 0
	BULLISH UASentiment = 1
	BEARISH UASentiment = 2
)

type UAType

type UAType uint8
const (
	BLOCK         UAType = 3
	SWEEP         UAType = 4
	LARGE         UAType = 5
	UNUSUAL_SWEEP UAType = 6
)

Jump to

Keyboard shortcuts

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