StockTickers

Using StockTickers datasource you can create subscriptions for stock tickers and get updates when a ticker reaches any price point.

Hooks Query Language lets you customize what data and when you want to receive based on TV Show.

Input Output Credits Freshness
Symbol (String) StockTicker iextrading.com Real-time

What you can get from this API

  • Get an update when a ticker reaches some price point
  • Get an update when a ticker price grows or falls by %

How to Use

As every datasource at Hooks, you can choose to pull the data in your preferred format or to set up a webhook to receive the data when something happens.  

As we offer many datasources, we have developed a custom SQL-Like language (Hooks Query Language) to be able to query each datasource in the same format. To create a subscription the first thing you need to do is to define an HQL query and then send this query to create subscription endpoint.

StockTickers datasource has a mandatory parameter Symbol (String) and you can use an optional WHERE clause to filter the output data (StockTicker) in order to receive just what you need. Hooks will then call your webhook once new data is available for your query. 

You can find the available symbols at https://iextrading.com/developer/docs/#symbols

Step 1: Customize subscription

Hooks provide an elegant mechanism for creating subscriptions using Hooks Query Language. It has a similar notation to SQL and lets you define each subscription with a simple HQL query.

The following query will create a subscription to “Send me an update when AAPL close price is more than 170”:

SELECT * FROM StockTickers('AAPL') 
WHERE close > 170

Once this HQL query has new results – when AAPL close price is more than 170 – Hooks will send StockTicker object to your webhook:

{
  "matches_count": 1,
  "results": [
    {
      "_entity_type": "StockTicker",
      "_id": "StockTicker_AAPL_422008",
      "avg_total_volume": 42298555,
      "calculation_price": "tops",
      "change": 1.52,
      "change_percent": 0.00884,
      "close": 171.85,
      "close_time": {
        "countdown": -66780,
        "datetime": "2018-02-20T21:00:00+0000",
        "timestamp": 1519160400
      },
      "company_name": "Apple Inc.",
      "delayed_price": 173.25,
      "delayed_price_time": {
        "countdown": -902,
        "datetime": "2018-02-21T15:17:58+0000",
        "timestamp": 1519226278
      },
      "high": 173.59,
      "iex_ask_price": 177.67,
      "iex_ask_size": 100,
      "iex_bid_price": 173.37,
      "iex_bid_size": 100,
      "iex_last_updated": {
        "countdown": -4,
        "datetime": "2018-02-21T15:32:56+0000",
        "timestamp": 1519227176
      },
      "iex_market_percent": 0.0293,
      "iex_realtime_price": 173.37,
      "iex_realtime_size": 100,
      "iex_volume": 187959,
      "latest_price": 173.37,
      "latest_source": "IEX real time price",
      "latest_time": "10:32:55 AM",
      "latest_update": {
        "countdown": -4,
        "datetime": "2018-02-21T15:32:56+0000",
        "timestamp": 1519227176
      },
      "latest_volume": 6414983,
      "low": 172.425,
      "market_cap": 879681633810,
      "open": 172.73,
      "open_time": {
        "countdown": -3780,
        "datetime": "2018-02-21T14:30:00+0000",
        "timestamp": 1519223400
      },
      "pe_ratio": 18.84,
      "previous_close": 171.85,
      "primary_exchange": "Nasdaq Global Select",
      "sector": "Technology",
      "symbol": "AAPL",
      "week52_high": 180.1,
      "week52_low": 135.28,
      "ytd_change": -0.0023801230697782223
    }
  ]
}

Please take a look at the above object. You can use WHERE clause to filter all the properties of StockTicker object and only get updates for what you need. 

Optional: Pull the data

You can use fetch endpoint to request the data currently available for your HQL query. Hooks will return the latest data available for HQL query. The result may be empty if we currently don’t have any data available for your query.

To pull the data for “AAPL current price and data” you can use.

SELECT * FROM StockTickers('AAPL')

This query will return a current stock data for AAPL ticker.

{
  "matches_count": 1,
  "results": [
    {
      "_entity_type": "StockTicker",
      "_id": "StockTicker_AAPL_422008",
      "avg_total_volume": 42298555,
      "calculation_price": "tops",
      "change": 1.75,
      "change_percent": 0.01018,
      "close": 171.85,
      "close_time": {
        "countdown": -67043,
        "datetime": "2018-02-20T21:00:00+0000",
        "timestamp": 1519160400
      },
      "company_name": "Apple Inc.",
      "delayed_price": 173.384,
      "delayed_price_time": {
        "countdown": -902,
        "datetime": "2018-02-21T15:22:21+0000",
        "timestamp": 1519226541
      },
      "high": 173.59,
      "iex_ask_price": 173.6,
      "iex_ask_size": 100,
      "iex_bid_price": 173.55,
      "iex_bid_size": 100,
      "iex_last_updated": {
        "countdown": -5,
        "datetime": "2018-02-21T15:37:18+0000",
        "timestamp": 1519227438
      },
      "iex_market_percent": 0.02939,
      "iex_realtime_price": 173.6,
      "iex_realtime_size": 100,
      "iex_volume": 201148,
      "latest_price": 173.6,
      "latest_source": "IEX real time price",
      "latest_time": "10:37:17 AM",
      "latest_update": {
        "countdown": -5,
        "datetime": "2018-02-21T15:37:18+0000",
        "timestamp": 1519227438
      },
      "latest_volume": 6844097,
      "low": 172.425,
      "market_cap": 880848656800,
      "open": 172.73,
      "open_time": {
        "countdown": -4043,
        "datetime": "2018-02-21T14:30:00+0000",
        "timestamp": 1519223400
      },
      "pe_ratio": 18.87,
      "previous_close": 171.85,
      "primary_exchange": "Nasdaq Global Select",
      "sector": "Technology",
      "symbol": "AAPL",
      "week52_high": 180.1,
      "week52_low": 135.28,
      "ytd_change": -0.0023801230697782223
    }
  ]
}

Step 2: Create subscription

To create a subscription you just need to send an HQL query and a title of your choice to subscriptions endpoint:

curl -H "Content-type: application/json" -d '{
	"query": "SELECT * FROM StockTickers('AAPL') WHERE close > 170"
}' 'http://api.hooksdata.io/v1/subscriptions'

Hooks will then create a subscription on our servers and call your webhook once new data is available for your query.

Examples

Using HQL you can customize what data you want to select from a datasource and also filter the output using a WHERE clause. The following examples show how you can use HQL to choose just the data you need:

AAPL close price is higher than 170.

SELECT * FROM StockTickers('AAPL') 
WHERE close > 170

APPL price change percent is higher than 10%.

SELECT * FROM StockTickers('AAPL') 
WHERE change_percent > 0.01