getSectors API

The getSectors API provides returns using weighted alpha on sectors covering multiple periods, including 1-day, 1-month, 3-month, 6-month, 9-month, 12-month and year-to-date.

All APIs

Contact Us to Get Access

Inputs

sector optional

The symbol of the sector. Multiple sectors separated by a comma may be used.

Type
list (A comma or semi-colon delimited string.) 
Example
-MEDR 

sectorPeriod required

The period used to calculate the weighted alpha return by the sector, includes: 1-day ("1DA"), 1-month ("1MO"), 3-month ("3MO"), 6-month ("6MO"), 9-month ("9MO"), 12-month ("12MO") and year-to-date ("YTD").

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

Valid Values:
1DA, 1MO, 3MO, 6MO, 9MO, 12MO, YTD

dailyData optional

Whether to include daily data: Open, High, Low, Close, Previous Close, 52-week high and 52-week low

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

components optional

Whether to include components of the sector.

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

sortDir optional

Sorting method that should be applied.

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

Outputs

Name / Requirement
Description
Type
symbol
always returned
The symbol of the sector.
string
A sequence of characters. (example: GOOG)
sector
always returned
The name of the sector.
string
A sequence of characters. (example: GOOG)
weightAlpha
always returned
The weighted alpha of the sector.
double
A numeric type defining a number with fractional parts. (example: 2.14)
lastTrade
always returned
The last traded price of the sector.
double
A numeric type defining a number with fractional parts. (example: 2.14)
change
always returned
The change in last traded price of the sector.
double
A numeric type defining a number with fractional parts. (example: 2.14)
percentChange
always returned
The percent change in the last traded price of the sector.
double
A numeric type defining a number with fractional parts. (example: 2.14)
stocks
always returned
The number of stocks the sector is comprised of.
integer
A numeric type defining a whole number. (example: 2)
open
as requested
The opening price for the sector for the current day.
double
A numeric type defining a number with fractional parts. (example: 2.14)
high
as requested
The high price for the sector for the current day.
double
A numeric type defining a number with fractional parts. (example: 2.14)
low
as requested
The low price for the sector for the current day.
double
A numeric type defining a number with fractional parts. (example: 2.14)
close
as requested
The closing price for the sector for the current day.
double
A numeric type defining a number with fractional parts. (example: 2.14)
previousClose
as requested
The closing price for the sector for the previous day.
double
A numeric type defining a number with fractional parts. (example: 2.14)
fiftyTwoWeekHigh
as requested
The highest price for the sector over the previous 52-weeks
double
A numeric type defining a number with fractional parts. (example: 2.14)
fiftyTwoWeekLow
as requested
The lowest price for the sector over the previous 52-weeks
double
A numeric type defining a number with fractional parts. (example: 2.14)
components
as requested
The symbol for a component of the sector.
enum
A type which includes a list of valid possible values.
componentSymbol
as requested
The symbol for a component of the sector.
enum
A type which includes a list of valid possible values.
componentName
as requested
The name of a component of the sector.
enum
A type which includes a list of valid possible values.
timestamp
always returned
The timestamp for the data.
dateTime
A date and time in the format of YYYY-MM-DD HH:MI:SS<TIMEZONE_OFFSET>.

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/getSectors.json?apikey=<YOUR API KEY>&sector=-MEDR&sectorPeriod=1DA&dailyData=0&components=0&sortDir=ASC
Host: ondemand.websol.barchart.com

POST

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

apikey=<YOUR API KEY>&sector=-MEDR&sectorPeriod=1DA&dailyData=0&components=0&sortDir=ASC

Response

{
    "status": {
        "code": 200,
        "message": "Success."
    },
    "results": [
        {
            "symbol": "-MEDR",
            "sector": "Medical - Drugs",
            "weightAlpha": 12.97,
            "lastTrade": 12.96,
            "change": 0.16,
            "percentChange": 1.25,
            "stocks": "148",
            "timestamp": "2017-11-24T09:02:03-06:00"
        }
    ]
}

XML

GET

GET https://ondemand.websol.barchart.com/getSectors.xml?apikey=<YOUR API KEY>&sector=-MEDR&sectorPeriod=1DA&dailyData=0&components=0&sortDir=ASC
Host: ondemand.websol.barchart.com

POST

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

apikey=<YOUR API KEY>&sector=-MEDR&sectorPeriod=1DA&dailyData=0&components=0&sortDir=ASC

Response


<?xml version="1.0" encoding="utf-8"?>
 <getSectors>
  <status>
   <code>200</code>
   <message>Success.</message>
  </status>
  <item>
   <symbol>-MEDR</symbol>
   <sector>Medical - Drugs</sector>
   <weightAlpha>12.97</weightAlpha>
   <lastTrade>12.96</lastTrade>
   <change>0.16</change>
   <percentChange>1.25</percentChange>
   <stocks>148</stocks>
   <timestamp>2017-11-24T09:02:03-06:00</timestamp>
  </item>
 </getSectors>

CSV

GET

GET https://ondemand.websol.barchart.com/getSectors.csv?apikey=<YOUR API KEY>&sector=-MEDR&sectorPeriod=1DA&dailyData=0&components=0&sortDir=ASC
Host: ondemand.websol.barchart.com

POST

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

apikey=<YOUR API KEY>&sector=-MEDR&sectorPeriod=1DA&dailyData=0&components=0&sortDir=ASC

Response

symbol,sector,weightAlpha,lastTrade,change,percentChange,stocks,timestamp
"-MEDR","Medical - Drugs","12.97","12.96","0.16","1.25","148","2017-11-24T09:02:03-06:00"


PHP

<?php

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

$params = [
    'sector' => '-MEDR',
    'sectorPeriod' => '1DA',
    'dailyData' => '0',
    'components' => '0',
    'sortDir' => 'ASC',
];

$result = $ondemand->getSectors($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.getSectors("-MEDR", "1DA", "0", "0", "ASC")

Perl

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

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

my $result = $ondemand->getSectors('-MEDR', '1DA', '0', '0', 'ASC');

print $result;

Python

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

result = client.service.getSectors('-MEDR', '1DA', '0', '0', 'ASC')

print result

Ruby

require 'savon'

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

response = ondemand.call(
    :getSectors,
    message: {
        sector: '-MEDR',
        sectorPeriod: '1DA',
        dailyData: '0',
        components: '0',
        sortDir: 'ASC',
    }
)

response.body