API Reference
Namespaces
Classes
Events
Global
Externals

Class: Lookup

CIQ.ChartEngine.Driver. Lookup


new Lookup(exchanges)

Base class that drives the chart symbol lookup functionality.

Provides back-end search fuctionality for the cq-lookup web component.

You should derive your own lookup driver that interacts with your data feed (see the example below; also see the "Data Integration" section of the Web Component Interface tutorial).

Parameters:
Name Type Description
exchanges Array.<string>

Array of financial exchange names. The lookup driver searches the exchanges for symbols that match the text entered in the cq-lookup web component's input field.

Note: This parameter is overridden by the cq-exchanges attribute of cq-lookup.

Since:
  • 6.0.0

See:
Example

Custom Implementation (See also the example in the acceptText method.)

CIQ.ChartEngine.Driver.Lookup.ChartIQ = function (exchanges) {
	this.exchanges = exchanges;
	if (!this.exchanges)
		this.exchanges = [
			"XNYS",
			"XASE",
			"XNAS",
			"XASX",
			"IND_CBOM",
			"INDXASE",
			"INDXNAS",
			"IND_DJI",
			"ARCX",
			"INDARCX",
			"forex",
		];
	this.url = "https://symbols.chartiq.com/chiq.symbolserver.SymbolLookup.service";
	this.requestCounter = 0; // Invalidate old requests.
};

// Inherit all of the base lookup driver's properties.
CIQ.inheritsFrom(CIQ.ChartEngine.Driver.Lookup.ChartIQ, CIQ.ChartEngine.Driver.Lookup);

Methods


<abstract> acceptText(text [, filter], maxResults, cb)

Accepts text entered by the user, searches financial exchanges for symbols that match the text, and returns an array of objects containing data that describes the matched symbols.

You must implement this abstract method to fetch results from the exchanges you support and return the results by calling cb(results_array). (See the example implementation below.)

Elements in the results array should be in the following format:

{
    display: ["symbol ID", "symbol description", "exchange"],
    data: {
        symbol: "symbol ID",
        name: "symbol description",
        exchDis: "exchange"
    }
}

(See the example results array below.)

Parameters:
Name Type Argument Description
text string

The text entered in the lookup component's input field.

filter string <optional>

The innerHTML of the selected cq-filter element of the cq-lookup web component connected to the lookup driver. Indicates which of the available exchanges should be searched for symbols that match the input text.

maxResults number

Maximum number of results to return from the server.

cb function

Callback function to call when the search has returned results. The results are passed to the callback function in an array (see the examples below).

Since:
  • 6.0.0

Examples

Method Implementation (See also the example in CIQ.ChartEngine.Driver.Lookup.)

CIQ.ChartEngine.Driver.Lookup.ChartIQ.prototype.acceptText = function(text, filter, maxResults, cb) {
    if (filter == "FX") filter = "FOREX";
    if (isNaN(parseInt(maxResults, 10))) maxResults = 100;
    const url = this.url + "?t=" + encodeURIComponent(text) + "&m="+maxResults+"&x=[";
    if (this.exchanges){
        url += this.exchanges.join(",");
    }
    url += "]";
    if (filter && filter.toUpperCase()! = "ALL") {
        url += "&e=" + filter;
    }

    let counter = ++this.requestCounter;
    const self = this;
    function handleResponse(status, response){
        if (counter < self.requestCounter) return;
        if (status != 200) return;
        try {
            response = JSON.parse(response);
            let symbols = response.payload.symbols;

            let results = [];
            for (let i = 0; i < symbols.length; i++) {
                let fields = symbols[i].split('|');
                let item = {
                    symbol: fields[0],
                    name: fields[1],
                    exchDisp: fields[2]
                };
                results.push({
                    display:[item.symbol, item.name, item.exchDisp],
                    data:item
                });
            }
            cb(results);
        } catch(e) {}
    }
    CIQ.postAjax({url: url, cb: handleResponse});
};

Sample Results Array

[
	{
		display: ["A", "Agilent Technologies Inc", "NYSE"],
		data: { symbol: "A", name: "Agilent Technologies Inc", exchDisp: "NYSE" },
	},
	{
		display: ["AA", "Alcoa Corp", "NYSE"],
		data: { symbol: "AA", name: "Alcoa Corp", exchDisp: "NYSE" },
	},
];