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.
- Go 1.20 (or newer) recommended
- Source files can be downloaded from: github.com/intrinio/intrinio-realtime-go-sdk
- Navigate to the project root
- Update the ENV parameter in the dockerfile with your API key
- Run
docker compose build
- Run
docker compose run example
- Source files can be downloaded from: github.com/intrinio/intrinio-realtime-go-sdk
- Navigate to the project root
- Open the example project at project-root/example
- Build your project using example.go as the base
- Create a new Go project
- import "github.com/intrinio/intrinio-realtime-go-sdk"
- Reference the package "intrinio"
For a sample Go application see: intrinio-realtime-options-go-sdk
- 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
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()
}
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.
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.
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)
type EquityQuote struct
- Type - The quote type
Ask
- Represents an 'Ask' typeBid
- 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)
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
The trade qualifiers field is represented by a tuple containing 4 integers. Each integer can take one of the following values:
0
- Regular transaction2
- Cancel3
- This is the last price and it's cancelled4
- Late but in sequence / sold last late5
- This was the open price and it's cancelled6
- Late report of opening trade and is out of sequence: or set the open7
- Cancel only trade reported8
- Transaction was executed electronically9
- Reopen of a previously halted contract11
- Spread23
- Intermarket Sweep30
- Extended hours33
- Crossed trade including Request For Cross RFC87
- Complex trade with equity leg107
- Auction123
- Stock option trade136
- Ex-Pit trade192
- Message received locally out-of-sequence222
- Combo trade0
- 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 ISO23, 33
- Single leg cross ISO8, 11
- Multi leg auto-electronic trade107, 11
- Multi leg auction11, 33
- Multi leg cross136, 11
- Multi leg floor trade8, 11, 87
- Multi leg auto-electronic trade against single leg(s)107, 123
- Stock options auction107, 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 trade123, 33
- Stock options cross136, 123
- Stock options floor trade8, 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 products222, 30
- Multilateral Compression Trade of Proprietary Data Products
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)
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
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,000Sweep
- represents an intermarket sweep of at least $10,000Large
- represents a trade of at least $100,000Unusual 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 securityBullish
- The event was executed with apparent positive outlook of the underlying securityBearish
- 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).
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.
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
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 acceptingintrinio.EquityTrade
updates. - Parameter
onQuote
: Optional. The callback acceptingintrinio.EquityQuote
updates. IfonQuote
isnil
, 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 acceptingintrinio.OptionTrade
updates. IfonTrade
isnil
, you will not receive trade updates from the server. - Parameter
onQuote
: Optional. The callback acceptingintrinio.OptionQuote
updates. IfonQuote
isnil
, you will not receive quote (ask, bid) updates from the server. - Parameter
onRefresh
: Optional. The callback acceptingintrinio.OptionRefresh
updates. IfonRefresh
isnil
, 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 acceptingintrinio.OptionUnusualActivity
updats. IfonUnusualActivity
isnil
, 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 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")