q/kdb+ api for getting market and financial data from IEX

Few months ago, I wrote an api for getting market and financial data from IEX in python. As discussed earlier, IEX makes a lot of its data available to the public through its webservice api (link).

In this post, I will show you how to use the api I wrote in q/kdb+. Let’s get started.

You can find the code here.

get_last_trade

Use this function to get last trade data (price and size) for one or more securities.

q)get_last_trade`aapl`ibm
sym  price  size time
----------------------------------------------
AAPL 174.66 100  2017.11.10D20:59:58.008999936
IBM  149.18 300  2017.11.10D20:59:59.724999936 


 

get_prev_day_summary

Use this function to get summary data for a security for previous trading day. The summary includes high, open, close, volume, vwap, change etc

q)get_prev_day_summary`aapl
sym  date       open   high   low    close  volume      unadjustedVolume change changePercent vwap
------------------------------------------------------------------------------------------------------
AAPL 2017.11.10 175.11 175.38 174.27 174.67 2.51455e+07 2.51455e+07      -1.21  -0.688        174.8423

 

get_historical_summary

Use this function to get bucketed historical data for a security. Available buckets are: 1d, 1m, 3m, 6m, ytd, 1y, 2y and 5y.

q)get_historical_summary[`aapl;`1d]
sym  minute label      high    low     average volume notional numberOfTrades changeOverTime
--------------------------------------------------------------------------------------------
AAPL 09:30  "09:30 AM" 175.3   175.145 175.236 1651   289314   24             0
AAPL 09:31  "09:31 AM" 175.34  175.01  175.265 1762   308816.3 7              0.0001654911
AAPL 09:32  "09:32 AM" 174.82  174.545 174.697 1028   179588.3 11             -0.003075852
AAPL 09:33  "09:33 AM" 174.81  174.54  174.684 4750   829747   24             -0.003150038
AAPL 09:34  "09:34 AM" 174.81  174.64  174.713 5678   992023   35             -0.002984547
AAPL 09:35  "09:35 AM" 174.755 174.27  174.4   23624  4120017  76             -0.004770709
AAPL 09:36  "09:36 AM" 174.59  174.3   174.452 9903   1727598  35             -0.004473967
......

 

get_minutely_summary

Similar to the function above, you can get minutely bucketed data for a specific date.

q)get_minutely_summary[`aapl;`20171103]
sym  date       minute label      high    low     average volume notional     numberOfTrades changeOverTime
-----------------------------------------------------------------------------------------------------------
AAPL 2017.11.03 09:30  "09:30 AM" 174.26  173.77  174.043 12340  2147686      84             0
AAPL 2017.11.03 09:31  "09:31 AM" 173.9   173.4   173.622 8424   1462594      73             -0.002418942
AAPL 2017.11.03 09:32  "09:32 AM" 173.5   173.14  173.321 9401   1629396      88             -0.0041484
AAPL 2017.11.03 09:33  "09:33 AM" 173.53  173.12  173.368 18171  3150272      106            -0.003878352
AAPL 2017.11.03 09:34  "09:34 AM" 173.5   173.26  173.35  20372  3531493      108            -0.003981775
AAPL 2017.11.03 09:35  "09:35 AM" 173.47  173.1   173.308 7745   1342272      62             -0.004223094

 

get_company_info

Use this function to get information about a company such as exchange, industry, website, description, CEO etc.

q)get_company_info[`aapl]
sym  companyName  exchange               industry            website                description                                                    ..
---------------------------------------------------------------------------------------------------------------------------------------------------..
AAPL "Apple Inc." "Nasdaq Global Select" "Computer Hardware" "http://www.apple.com" "Apple Inc is designs, manufactures and markets mobile communic..

 

get_key_stats

Use this function to get key statistics about a security such as market cap, beta, revenue, debt etc.

q)get_key_stats`aapl
sym  companyName  marketcap    beta     week52high week52low week52change shortInterest shortDate  dividendRate dividendYield exDividendDate latest..
---------------------------------------------------------------------------------------------------------------------------------------------------..
AAPL "Apple Inc." 8.968103e+11 1.214983 176.24     104.08    60.6634      3.424262e+07  2017.10.13 2.52         1.429868                     9.2   ..

 

get_company_news

Use this function to get latest news relating to a security.

q)get_company_news`aapl
sym  datetime                      headline                                                                       source          url              ..
---------------------------------------------------------------------------------------------------------------------------------------------------..
AAPL 2017.11.10D16:06:00.000000000 "Netflix dropped 5 percent this week, after rallying all year"                 "CNBC"          "https://api.iext..
AAPL 2017.11.10D14:16:00.000000000 "Apple will issue a fix for iPhone X devices that seize up in the cold"        "CNBC"          "https://api.iext..
AAPL 2017.11.10D12:04:00.000000000 "Apple acknowledges iPhone X issue in some devices, plans fix"                 "SeekingAlpha"  "https://api.iext..
AAPL 2017.11.10D11:01:00.000000000 "Your first trade for Friday, November 10"                                     "CNBC"          "https://api.iext..
AAPL 2017.11.10D08:30:00.000000000 "Apple's chart points to trillion dollar valuation by year-end: technician"    "CNBC"          "https://api.iext..
AAPL 2017.11.10D07:39:00.000000000 "Veterans And The Wall Street - Cramer's Mad Money (11/9/17)"                  "SeekingAlpha"  "https://api.iext..
AAPL 2017.11.10D01:30:00.000000000 "Cirrus Logic's Long Conference: A Watershed Moment"                           "SeekingAlpha"  "https://api.iext..
AAPL 2017.11.09D21:14:00.000000000 "My 3 Favorite Stocks After Q3 Earnings"                                       "SeekingAlpha"  "https://api.iext..
AAPL 2017.11.09D18:12:00.000000000 "Cramer: Successful CEOs and military leaders have these 5 traits in common"   "CNBC"          "https://api.iext..
AAPL 2017.11.09D16:35:00.000000000 "Intel AMD Graphics Partnership Agreement Has Negative Implications To Nvidia" "SeekingAlpha"  "https://api.iext..
AAPL 2017.11.09D13:00:00.000000000 "Clips Introduces Selfie Scenes for Immersive, 360-Degree Selfies on iPhone X" "Business Wire" "https://api.iext..

 

get_company_financials

Use this function to get financial information about a security.

q)get_company_financials`aapl
sym  reportDate grossProfit costOfRevenue operatingRevenue totalRevenue operatingIncome netIncome  researchAndDevelopment operatingExpense currentA..
---------------------------------------------------------------------------------------------------------------------------------------------------..
AAPL 2017.09.30 1.9931e+10  3.2648e+10    5.2579e+10       5.2579e+10   1.312e+10       1.0714e+10 2.997e+09              6.811e+09        1.28645e..
AAPL 2017.06.30 1.7488e+10  2.792e+10     4.5408e+10       4.5408e+10   1.0768e+10      8.717e+09  2.937e+09              6.72e+09         1.12875e..
AAPL 2017.03.31 2.0591e+10  3.2305e+10    5.2896e+10       5.2896e+10   1.4097e+10      1.1029e+10 2.776e+09              6.494e+09        1.0199e+..
AAPL 2016.12.31 3.0176e+10  4.8175e+10    7.8351e+10       7.8351e+10   2.3359e+10      1.7891e+10 2.871e+09              6.817e+09        1.03332e..

 

get_company_earnings

Use this function to get financial information about a security.

q)get_company_earnings`aapl
sym  actualEPS consensusEPS estimatedEPS announceTime numberOfEstimates EPSSurpriseDollar EPSReportDate fiscalPeriod fiscalEndDate
----------------------------------------------------------------------------------------------------------------------------------
AAPL 1.67      1.57         1.57         "AMC"        13                0.1               2017.08.01    "Q3 2017"    2017.06.30
AAPL 2.1       2.02         2.02         "AMC"        14                0.08              2017.05.02    "Q2 2017"    2017.03.31
AAPL 3.36      3.22         3.22         "AMC"        15                0.14              2017.01.31    "Q1 2017"    2016.12.31
AAPL 1.67      1.66         1.66         "AMC"        14                0.01              2016.10.25    "Q4 2016"    2016.09.30

 

get_most_active_stocks

Use this function to get most ‘active’ stocks for last trade date with additional info such as close price, open price etc.

q)get_most_active_stocks[]
sym   companyName                                primaryExchange           sector                   calculationPrice open  openTime                ..
---------------------------------------------------------------------------------------------------------------------------------------------------..
BAC   "Bank of America Corporation"              "New York Stock Exchange" "Financial Services"     "close"          26.57 2017.11.10D14:30:07.7440..
GE    "General Electric Company"                 "New York Stock Exchange" "Industrials"            "close"          19.98 2017.11.10D14:30:21.3809..
CMCSA "Comcast Corporation Class A Common Stock" "Nasdaq Global Select"    "Consumer Cyclical"      "close"          36.5  2017.11.10D14:30:00.0259..
T     "AT&T Inc."                                "New York Stock Exchange" "Communication Services" "close"          34.14 2017.11.10D14:30:19.0700..

 

get_most_gainers_stocks

Use this function to get stocks with highest gains for last trade date with additional info such as close price, open price etc.

q)get_most_gainers_stocks[]
sym  companyName                                   primaryExchange           sector              calculationPrice open  openTime                   ..
---------------------------------------------------------------------------------------------------------------------------------------------------..
NLNK "NewLink Genetics Corporation"                "NASDAQ Global Market"    "Healthcare"        "close"          8.75  2017.11.10D14:30:00.7500001..
RH   "RH"                                          "New York Stock Exchange" "Consumer Cyclical" "close"          82.15 2017.11.10D14:30:00.6030000..
EGAN "eGain Corporation"                           "NASDAQ Capital Market"   "Technology"        "close"          3.3   2017.11.10D14:30:00.3160000..
FRTA "Forterra Inc."                               "Nasdaq Global Select"    "Basic Materials"   "close"          8.08  2017.11.10D14:30:00.6209999..

 

get_most_losers_stocks

Use this function to get stocks with most loss for last trade date with additional info such as close price, open price etc.

q)get_most_losers_stocks[]
sym  companyName                              primaryExchange           sector               calculationPrice open  openTime                      c..
---------------------------------------------------------------------------------------------------------------------------------------------------..
NCS  "NCI Building Systems Inc."              "New York Stock Exchange" "Industrials"        "close"          15.8  2017.11.10D14:30:00.740000000 1..
GURE "Gulf Resources Inc."                    "Nasdaq Global Select"    "Basic Materials"    "close"          1.41  2017.11.10D14:30:00.312999936 1..
ALNY "Alnylam Pharmaceuticals Inc."           "Nasdaq Global Select"    "Healthcare"         "close"          137.6 2017.11.10D14:30:00.599000064 1..
FNHC "Federated National Holding Company"     "NASDAQ Global Market"    "Financial Services" "close"          14.13 2017.11.10D14:30:00.676000000 1..
AIRG "Airgain Inc."                           "NASDAQ Capital Market"   "Technology"         "close"          7.7   2017.11.10D14:30:00.652000000 8..

You can find the code here.

2 responses to “q/kdb+ api for getting market and financial data from IEX”

  1. Tahsin Alam says:

    Great work!

Leave a Reply

Your email address will not be published. Required fields are marked *