How to stream stock trades and quotes

Overview

In this how to guide, we show how simple it is to use Intrinio start streaming realtime stock price data. In this example we will be using Java however, you can use any one of our realtime client SDKs.


Prerequisites

  1. Create an account to get an API key
  2. Sign up for a free trial (of IEX)
  3. Contact sales if you wish to trial Nasdaq Basic or Delayed SIP
  4. Choose which SDK you wish to use Java, C#, Python, javascript, Go, Ruby
  5. Install Docker (recommended)
  6. Testing the code during market hours IEX or Nasdaq Basic & Delayed SIP.

Procedure

Clone the latest source from github.

$ git clone https://github.com/intrinio/intrinio-realtime-java-sdk.git
$ cd intrinio-realtime-java-sdk

The simplest way to run the sdk at anytime regardless of SDK is to use docker. Use the following command to run your app after every step. Use ctrl + c to exit the app.

$ docker compose up --build

The docker image should build and run sample app but you will get an unauthorized message. To update the config.json with your API key view the README for SDK specific instructions. For java, it is located at src/intrinio/config.json. If you are using Nasdaq Basic or Delayed SIP, change the provider to NASDAQ_BASIC or DELAYED_SIP.

// src/intrinio/config.json
{	
"apiKey": "",	
"provider": "REALTIME",
"symbols": [ "GOOG", "MSFT", "AAPL" ],
"tradesOnly": false,	
"numThreads": 2
}

You have two options to subscribe to the symbols. You can statically specify your symbol subscriptions in the config.json or you can dynamically subscribe at runtime. By default the sample code loads from the config.json.

In order to get the entire market, switch the symbols array to "lobby".

{	
"apiKey": "",	
"provider": "REALTIME",
"symbols": [ "lobby" ],
"tradesOnly": false,	
"numThreads": 2
}

Or you can subscribe to specific symbols or the lobby dynamically at runtime. For Java the sample app is located at src/SampleApp/SampleApp.java (view the README or dockerfile for your specific SDK's sample app). You can update the public static void main method to test this yourself.

Client client = new Client(tradeHandler, quoteHandler);
//client.join();  //Joins channels specified in the config.json
client.join(new String[] {"TSLA"});

Or subscribe to the lobby dynamically at runtime.

Client client = new Client(tradeHandler, quoteHandler);
client.joinLobby();

Now that you are streaming quotes and trades, let's do something with the data. For this simple example let's modify the onTrade method of the sample app's TradeHandler.

	public void onTrade(Trade trade) {
		Client.Log("Sample App - Trade Event Fired");
		Client.Log("%s - Trade (price = %f, size = %d, time = %s)", 
			trade.symbol(), 
			trade.price(),
			trade.size(),
			trade.timestamp()
		);
	}

Conclusion

The rest is up to you. Just kidding. We're here to help. Questions? Comments? Ready to buy? Contact sales@intrinio.com.