getHistory API

The getHistory API is used to request historical time series data on stocks, indices, mutual funds, ETFs, futures, indices or forex pairs. Historical data is available as tick, minute or end-of-day data.

All APIs

Contact Us to Get Access

Inputs

symbol required

A symbol or code that identifies a financial instrument.

Type
string (A sequence of characters. (example: GOOG)) 
Example
AAPL 

type required

The type of historical data to return, including tick data, minute data, and end-of-day data.

Type
enum (A type which includes a list of valid possible values.) 
Example
minutes 

Valid Values:
ticks, minutes, nearbyMinutes, formTMinutes, daily, dailyNearest, dailyContinue, weekly, weeklyNearest, weeklyContinue, monthly, monthlyNearest, monthlyContinue, quarterly, quarterlyNearest, quarterlyContinue, yearly, yearlyNearest, yearlyContinue

startDate optional

The start date of the historical data query. This parameter should be set to the desired start date/time for the query (the result set will include records back to, and including, this value). If not set, the value will default to the beginning of the day specified in the end parameter, if end is specified, or to the beginning of the current day, if end is not specified. The value should conform to the format yyyymmdd[hhmm[ss]], where fields in brackets are optional (Do not include the brackets themselves). Any optional fields that are not explicitly set will default to 0 (i.e. 20090203 will default to 20090203000000 or February 3, 2009 at 00:00:00).

Type
dateTime (A date and time in the format of YYYY-MM-DD HH:MI:SS<TIMEZONE_OFFSET>.) 
Example
20100101 

endDate optional

The end data of the historical data query. This parameter should be set to the desired end date/time for the query (the result set will include records up to, but not including, this value). If not set, the value will default to the end of the day specified in the start parameter, if specified, or to the end of the current day, if start is not specified. The value should conform to the format yyyymmdd[hhmm[ss]], where fields in brackets are optional (Do not include the brackets themselves). Any optional fields that are not explicitly set will default to 0 (i.e. 20090203 will default to 20090203000000 or February 3, 2009 at 00:00:00).

Type
dateTime (A date and time in the format of YYYY-MM-DD HH:MI:SS<TIMEZONE_OFFSET>.) 
Example
20130101 

maxRecords optional

The maximum amount of records returned. This parameter should be set to the maximum number of records desired. If not specified, there number of records returned will be determined by the date/time parameters specified as well as any defaults that apply to the query.

Type
int (A numeric type defining a whole number. (example: 2)) 
Example
10 

interval optional

The number of minutes for a minute query.

Type
int (A numeric type defining a whole number. (example: 2)) 
Example
60 
Default

order optional

An arrangement of fields within a particular record (ascending or descending). This parameter can be set to one of two values ("asc" and "desc") in order to specify the chronological order of the result set returned. If this parameter is not specified, the order results is not guaranteed.

Type
enum (A type which includes a list of valid possible values.) 
Example
asc 
Default
asc 

Valid Values:
asc, desc

sessionFilter optional

This parameter modifies the default session codes/sale conditions used to return ticks for each exchange. For NYSE and AMEX, the default session filter is "@EFKX56V9" (meaning all ticks with sale conditions corresponding to one of the characters in the filter are included in the results), for NASDAQ the default is "@ABDEFKOSXY156", and for everything else all session codes/sale conditions are returned except the settle (session code '*'). If the session filter is set to a string of valid session codes (i.e. "EFK"), only ticks with the specified session codes are included in the results. If the string is prefixed with character '!' (i.e."!EFK"), all session codes except those in the string are included in the results. If the string is prefixed with character '+' (i.e. "+T"), then all the default session codes in addition to the ones specified in the string are included in the results. And if the string is prefixed with character '-' (i.e. "-EF") then all default session codes except the ones specified are included in the results. Please note that the '+' character should be escaped (to %2B) when entering the URL in a web browser or executing the query in an API that does not escape it by default.

Type
string (A sequence of characters. (example: GOOG)) 
Example
EFK 

splits optional

An adjustment of stock value due to corporate action. This parameter only applies to stocks and specifies whether the data returned should be adjusted for splits or not. Set to true to query for adjusted the data, or to false for non-adjusted data. If not specified, the default is true. In order to guarantee the same adjustment settings in the future, this parameter should be specified.

Type
boolean (A logical type representing the truth of a value as 'true' or 'false'.) 
Example
true 
Default

dividends optional

A distribution of a portion of a company's earnings. This parameter only applies to stocks and specifies whether the data returned should be adjusted for dividends or not. Set to true to query for adjusted the data, or to false for non-adjusted data. If not specified, the default is true. In order to guarantee the same adjustment settings in the future, this parameter should be specified.

Type
boolean (A logical type representing the truth of a value as 'true' or 'false'.) 
Example
true 
Default

volume optional

The quantity of shares or contracts traded. For futures, this parameter can be set to one of two values (contract and total) in order to specify whether the volume returned should be the contract volume or the total volume. For aggregates (such as weekly, monthly or yearly), this returns the average volume for the period specified. If the value is preceded by 'sum' (sumcontract and sumtotal), then it returns the sum of the volumes in each daily bar during the period specified. If not specified, the value will default to contract. For aggregate equities queries (such as weekly, monthly or yearly), this parameter can be set to sum to return the sum of the volumes in each daily bar during the period specified. If not specified, then the average volume is returned.

Type
enum (A type which includes a list of valid possible values.) 
Example
sum 

Valid Values:
total, sum, contract, sumcontract, sumtotal

nearby optional

This parameter specifies the offset from the front month for 'nearest' queries (data parameter set to dailynearest, weeklynearest, monthlynearest, quarterlynearest and yearlynearest). The default value for this parameter is 1, which sets nearest queries to the most current front month. If set to a value greater than 1, then the nth front month is used (for example, in August of 2010, ESU10 would be the current front month, so nearby=2 would use ESZ10, nearby=3 would use ESH11, etc.) This parameter is ignored for all other queries. Alternatively, the same functionality provided by the nearby parameter can be achieved using the symbol notation symbol=RS*n, where RS is the root symbol and n is the nth front month (i.e. symbol=ES*1, symbol=YM*3, etc.). When using this notation on the symbol parameter, the nearby parameter should be omitted.

Type
int (A numeric type defining a whole number. (example: 2)) 
Example

jerq optional

Whether to merge with JERQ data.

Type
boolean (A logical type representing the truth of a value as 'true' or 'false'.) 
Example
true 
Default

exchange optional

The list of valid exchange codes to limit symbol search.

Type
list (A comma or semi-colon delimited string.) 
Example
NYSE,AMEX,NASDAQ 

backAdjust optional

This parameter specifies whether the contracts in the series will be adjusted based on the roll-gap between the closing prices of the current contract and the previous contract on the day of the switch. Valid values are true and false. If not specified, the default value is false resulting in a non-adjusted query. This parameter only applies to multi-contract futures queries and is ignored for all other queries.

Type
enum (A type which includes a list of valid possible values.) 
Example
false 
Default
false 

Valid Values:
true, false

daysToExpiration optional

This parameter specifies the number of calendar days prior to a contract expiration when the series of contracts will be switched to the next contract in the series. Valid values are 0 through 60. A value of 0 will tell the system to use the day of expiration. If not specified, the default value (1) is used, resulting in each contract in the series to run until (and including) the day prior to its expiration. This parameter only applies to multi-contract futures queries and is ignored for all other queries.

Type
enum (A type which includes a list of valid possible values.) 
Example
Default

Valid Values:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60

contractRoll optional

For futures, multi-contract nearest queries (data parameter set to dailynearest, weeklynearest, monthlynearest, quarterlynearest or yearlynearest), this parameter can be set to one of two values (expiration, combined), and determines how the switch from one contract to the next in the series is calculated. When the value specified is 'expiration', the switch from one contract to the next in the series will be based on the expiration date (and the value of the 'daysToExpiration' parameter if specified). When the value specified is 'combined', a combination of volume and openinterest will be used to determine when to switch from one contract to the next in the series (when using this value, the 'daysToExpiration' parameter is ignored).

Type
enum (A type which includes a list of valid possible values.) 
Example
expiration 
Default
expiration 

Valid Values:
expiration, combined

Outputs

Name / Requirement
Description
Type
symbol
always returned
A symbol or code that identifies a financial instrument.
string
A sequence of characters. (example: GOOG)
timestamp
always returned
The exchange time of the price. Format: HH:MM:SS.FFF
dateTime
A date and time in the format of YYYY-MM-DD HH:MI:SS<TIMEZONE_OFFSET>.
tradingDay
always returned
The date of the trade. Format: YYYY-MM-DD
date
A date in the format of YYYY-MM-DD.
sessionCode
as requested
A code used to differentiate between composite market prices, overnight session prices, and day session prices for futures. Not all futures exchanges use session codes. "G" is electronic session and "R" is pit session.
string
A sequence of characters. (example: GOOG)
tickPrice
as requested
double
A numeric type defining a number with fractional parts. (example: 2.14)
tickSize
as requested
The volume traded for a single transaction.
int
A numeric type defining a whole number. (example: 2)
open
as requested
The opening (first) price for the period.
double
A numeric type defining a number with fractional parts. (example: 2.14)
high
as requested
The highest traded price for the period.
double
A numeric type defining a number with fractional parts. (example: 2.14)
low
as requested
The lowest traded price for the period.
double
A numeric type defining a number with fractional parts. (example: 2.14)
close
as requested
The last traded price for the period.
double
A numeric type defining a number with fractional parts. (example: 2.14)
volume
as requested
The quantity of shares or contracts traded per the period.
int
A numeric type defining a whole number. (example: 2)
openInterest
as requested
The total number of options and/or futures contracts that have not been offset.
int
A numeric type defining a whole number. (example: 2)

Status Code Responses

200
OK
Success
400
Bad Request
The request was invalid, please see the message for more information.
500
Internal Server Error
Something is not working correctly, please contact support.


JSON

GET

GET https://ondemand.websol.barchart.com/getHistory.json?apikey=<YOUR API KEY>&symbol=AAPL&type=minutes&startDate=20100101&endDate=20130101&maxRecords=10&interval=60&order=asc&sessionFilter=EFK&splits=true&dividends=true&volume=sum&nearby=1&jerq=true&exchange=NYSE%2CAMEX%2CNASDAQ&backAdjust=false&daysToExpiration=1&contractRoll=expiration
Host: ondemand.websol.barchart.com

POST

POST https://ondemand.websol.barchart.com/getHistory.json
Host: ondemand.websol.barchart.com
Content-Type: application/x-www-form-urlencoded
Content-Length: length

apikey=<YOUR API KEY>&symbol=AAPL&type=minutes&startDate=20100101&endDate=20130101&maxRecords=10&interval=60&order=asc&sessionFilter=EFK&splits=true&dividends=true&volume=sum&nearby=1&jerq=true&exchange=NYSE%2CAMEX%2CNASDAQ&backAdjust=false&daysToExpiration=1&contractRoll=expiration

Response

{
    "status": {
        "code": 200,
        "message": "Success."
    },
    "results": [
        {
            "symbol": "AAPL",
            "timestamp": "2017-11-21T13:00:00-05:00",
            "tradingDay": "2017-11-21",
            "open": 173.1764,
            "high": 173.23,
            "low": 172.94,
            "close": 173.1131,
            "volume": 1329762
        },
        {
            "symbol": "AAPL",
            "timestamp": "2017-11-21T14:00:00-05:00",
            "tradingDay": "2017-11-21",
            "open": 173.12,
            "high": 173.1401,
            "low": 172.6801,
            "close": 172.9648,
            "volume": 1627308
        },
        {
            "symbol": "AAPL",
            "timestamp": "2017-11-21T15:00:00-05:00",
            "tradingDay": "2017-11-21",
            "open": 172.9652,
            "high": 173.23,
            "low": 172.69,
            "close": 173.13,
            "volume": 2903866
        },
        {
            "symbol": "AAPL",
            "timestamp": "2017-11-22T09:00:00-05:00",
            "tradingDay": "2017-11-22",
            "open": 173.36,
            "high": 174.26,
            "low": 173.05,
            "close": 173.365,
            "volume": 4078597
        },
        {
            "symbol": "AAPL",
            "timestamp": "2017-11-22T10:00:00-05:00",
            "tradingDay": "2017-11-22",
            "open": 173.34,
            "high": 174.6,
            "low": 173.3,
            "close": 174.49,
            "volume": 3717230
        },
        {
            "symbol": "AAPL",
            "timestamp": "2017-11-22T11:00:00-05:00",
            "tradingDay": "2017-11-22",
            "open": 174.49,
            "high": 175,
            "low": 173.86,
            "close": 174.28,
            "volume": 3368138
        },
        {
            "symbol": "AAPL",
            "timestamp": "2017-11-22T12:00:00-05:00",
            "tradingDay": "2017-11-22",
            "open": 174.2735,
            "high": 174.53,
            "low": 174.01,
            "close": 174.27,
            "volume": 1530526
        },
        {
            "symbol": "AAPL",
            "timestamp": "2017-11-22T13:00:00-05:00",
            "tradingDay": "2017-11-22",
            "open": 174.27,
            "high": 174.35,
            "low": 173.91,
            "close": 174.339,
            "volume": 1499385
        },
        {
            "symbol": "AAPL",
            "timestamp": "2017-11-22T14:00:00-05:00",
            "tradingDay": "2017-11-22",
            "open": 174.35,
            "high": 174.7,
            "low": 174.2,
            "close": 174.49,
            "volume": 1396925
        },
        {
            "symbol": "AAPL",
            "timestamp": "2017-11-22T15:00:00-05:00",
            "tradingDay": "2017-11-22",
            "open": 174.48,
            "high": 175,
            "low": 174.35,
            "close": 174.94,
            "volume": 3152947
        }
    ]
}

XML

GET

GET https://ondemand.websol.barchart.com/getHistory.xml?apikey=<YOUR API KEY>&symbol=AAPL&type=minutes&startDate=20100101&endDate=20130101&maxRecords=10&interval=60&order=asc&sessionFilter=EFK&splits=true&dividends=true&volume=sum&nearby=1&jerq=true&exchange=NYSE%2CAMEX%2CNASDAQ&backAdjust=false&daysToExpiration=1&contractRoll=expiration
Host: ondemand.websol.barchart.com

POST

POST https://ondemand.websol.barchart.com/getHistory.xml
Host: ondemand.websol.barchart.com
Content-Type: application/x-www-form-urlencoded
Content-Length: length

apikey=<YOUR API KEY>&symbol=AAPL&type=minutes&startDate=20100101&endDate=20130101&maxRecords=10&interval=60&order=asc&sessionFilter=EFK&splits=true&dividends=true&volume=sum&nearby=1&jerq=true&exchange=NYSE%2CAMEX%2CNASDAQ&backAdjust=false&daysToExpiration=1&contractRoll=expiration

Response


<?xml version="1.0" encoding="utf-8"?>
 <getHistory>
  <status>
   <code>200</code>
   <message>Success.</message>
  </status>
  <item>
   <symbol>AAPL</symbol>
   <timestamp>2017-11-21T13:00:00-05:00</timestamp>
   <tradingDay>2017-11-21</tradingDay>
   <open>173.1764</open>
   <high>173.23</high>
   <low>172.94</low>
   <close>173.1131</close>
   <volume>1329762</volume>
  </item>
  <item>
   <symbol>AAPL</symbol>
   <timestamp>2017-11-21T14:00:00-05:00</timestamp>
   <tradingDay>2017-11-21</tradingDay>
   <open>173.12</open>
   <high>173.1401</high>
   <low>172.6801</low>
   <close>172.9648</close>
   <volume>1627308</volume>
  </item>
  <item>
   <symbol>AAPL</symbol>
   <timestamp>2017-11-21T15:00:00-05:00</timestamp>
   <tradingDay>2017-11-21</tradingDay>
   <open>172.9652</open>
   <high>173.23</high>
   <low>172.69</low>
   <close>173.13</close>
   <volume>2903866</volume>
  </item>
  <item>
   <symbol>AAPL</symbol>
   <timestamp>2017-11-22T09:00:00-05:00</timestamp>
   <tradingDay>2017-11-22</tradingDay>
   <open>173.36</open>
   <high>174.26</high>
   <low>173.05</low>
   <close>173.365</close>
   <volume>4078597</volume>
  </item>
  <item>
   <symbol>AAPL</symbol>
   <timestamp>2017-11-22T10:00:00-05:00</timestamp>
   <tradingDay>2017-11-22</tradingDay>
   <open>173.34</open>
   <high>174.6</high>
   <low>173.3</low>
   <close>174.49</close>
   <volume>3717230</volume>
  </item>
  <item>
   <symbol>AAPL</symbol>
   <timestamp>2017-11-22T11:00:00-05:00</timestamp>
   <tradingDay>2017-11-22</tradingDay>
   <open>174.49</open>
   <high>175</high>
   <low>173.86</low>
   <close>174.28</close>
   <volume>3368138</volume>
  </item>
  <item>
   <symbol>AAPL</symbol>
   <timestamp>2017-11-22T12:00:00-05:00</timestamp>
   <tradingDay>2017-11-22</tradingDay>
   <open>174.2735</open>
   <high>174.53</high>
   <low>174.01</low>
   <close>174.27</close>
   <volume>1530526</volume>
  </item>
  <item>
   <symbol>AAPL</symbol>
   <timestamp>2017-11-22T13:00:00-05:00</timestamp>
   <tradingDay>2017-11-22</tradingDay>
   <open>174.27</open>
   <high>174.35</high>
   <low>173.91</low>
   <close>174.339</close>
   <volume>1499385</volume>
  </item>
  <item>
   <symbol>AAPL</symbol>
   <timestamp>2017-11-22T14:00:00-05:00</timestamp>
   <tradingDay>2017-11-22</tradingDay>
   <open>174.35</open>
   <high>174.7</high>
   <low>174.2</low>
   <close>174.49</close>
   <volume>1396925</volume>
  </item>
  <item>
   <symbol>AAPL</symbol>
   <timestamp>2017-11-22T15:00:00-05:00</timestamp>
   <tradingDay>2017-11-22</tradingDay>
   <open>174.48</open>
   <high>175</high>
   <low>174.35</low>
   <close>174.94</close>
   <volume>3152947</volume>
  </item>
 </getHistory>

CSV

GET

GET https://ondemand.websol.barchart.com/getHistory.csv?apikey=<YOUR API KEY>&symbol=AAPL&type=minutes&startDate=20100101&endDate=20130101&maxRecords=10&interval=60&order=asc&sessionFilter=EFK&splits=true&dividends=true&volume=sum&nearby=1&jerq=true&exchange=NYSE%2CAMEX%2CNASDAQ&backAdjust=false&daysToExpiration=1&contractRoll=expiration
Host: ondemand.websol.barchart.com

POST

POST https://ondemand.websol.barchart.com/getHistory.csv
Host: ondemand.websol.barchart.com
Content-Type: application/x-www-form-urlencoded
Content-Length: length

apikey=<YOUR API KEY>&symbol=AAPL&type=minutes&startDate=20100101&endDate=20130101&maxRecords=10&interval=60&order=asc&sessionFilter=EFK&splits=true&dividends=true&volume=sum&nearby=1&jerq=true&exchange=NYSE%2CAMEX%2CNASDAQ&backAdjust=false&daysToExpiration=1&contractRoll=expiration

Response

symbol,timestamp,tradingDay,open,high,low,close,volume
"AAPL","2017-11-21T13:00:00-05:00","2017-11-21","173.1764","173.23","172.94","173.1131","1329762"
"AAPL","2017-11-21T14:00:00-05:00","2017-11-21","173.12","173.1401","172.6801","172.9648","1627308"
"AAPL","2017-11-21T15:00:00-05:00","2017-11-21","172.9652","173.23","172.69","173.13","2903866"
"AAPL","2017-11-22T09:00:00-05:00","2017-11-22","173.36","174.26","173.05","173.365","4078597"
"AAPL","2017-11-22T10:00:00-05:00","2017-11-22","173.34","174.6","173.3","174.49","3717230"
"AAPL","2017-11-22T11:00:00-05:00","2017-11-22","174.49","175","173.86","174.28","3368138"
"AAPL","2017-11-22T12:00:00-05:00","2017-11-22","174.2735","174.53","174.01","174.27","1530526"
"AAPL","2017-11-22T13:00:00-05:00","2017-11-22","174.27","174.35","173.91","174.339","1499385"
"AAPL","2017-11-22T14:00:00-05:00","2017-11-22","174.35","174.7","174.2","174.49","1396925"
"AAPL","2017-11-22T15:00:00-05:00","2017-11-22","174.48","175","174.35","174.94","3152947"


PHP

<?php

$ondemand = new SoapClient('https://ondemand.websol.barchart.com/service?wsdl');

$params = [
    'symbol' => 'AAPL',
    'type' => 'minutes',
    'startDate' => '20100101',
    'endDate' => '20130101',
    'maxRecords' => '10',
    'interval' => '60',
    'order' => 'asc',
    'sessionFilter' => 'EFK',
    'splits' => 'true',
    'dividends' => 'true',
    'volume' => 'sum',
    'nearby' => '1',
    'jerq' => 'true',
    'exchange' => 'NYSE,AMEX,NASDAQ',
    'backAdjust' => 'false',
    'daysToExpiration' => '1',
    'contractRoll' => 'expiration',
];

$result = $ondemand->getHistory($params);
var_dump($result);

Classic ASP

Dim ondemand
Dim result

Set ondemand = Server.CreateObject("MSSOAP.SoapClient30")
ondemand.ClientProperty("ServerHTTPRequest") = True
ondemand.MSSoapInit("https://ondemand.websol.barchart.com/service?wsdl")

Set result = ondemand.getHistory("AAPL", "minutes", "20100101", "20130101", "10", "60", "asc", "EFK", "true", "true", "sum", "1", "true", "NYSE,AMEX,NASDAQ", "false", "1", "expiration")

Perl

use SOAP::Lite;
use SOAP::WSDL;

my $ondemand = SOAP::Lite
    -> service('https://ondemand.websol.barchart.com/service?wsdl');

my $result = $ondemand->getHistory('AAPL', 'minutes', '20100101', '20130101', '10', '60', 'asc', 'EFK', 'true', 'true', 'sum', '1', 'true', 'NYSE,AMEX,NASDAQ', 'false', '1', 'expiration');

print $result;

Python

from suds.client import Client
ondemand = Client('https://ondemand.websol.barchart.com/service?wsdl')

result = client.service.getHistory('AAPL', 'minutes', '20100101', '20130101', '10', '60', 'asc', 'EFK', 'true', 'true', 'sum', '1', 'true', 'NYSE,AMEX,NASDAQ', 'false', '1', 'expiration')

print result

Ruby

require 'savon'

ondemand = Savon.client(wsdl: 'https://ondemand.websol.barchart.com/service?wsdl')

response = ondemand.call(
    :getHistory,
    message: {
        symbol: 'AAPL',
        type: 'minutes',
        startDate: '20100101',
        endDate: '20130101',
        maxRecords: '10',
        interval: '60',
        order: 'asc',
        sessionFilter: 'EFK',
        splits: 'true',
        dividends: 'true',
        volume: 'sum',
        nearby: '1',
        jerq: 'true',
        exchange: 'NYSE,AMEX,NASDAQ',
        backAdjust: 'false',
        daysToExpiration: '1',
        contractRoll: 'expiration',
    }
)

response.body