Class: Lookup

CIQ.ChartEngine.Driver. Lookup


new Lookup(exchanges)

Base class that drives the lookup functionality. You should derive your own Driver.Lookup that interacts with your datafeed.

This is used with the cq-lookup web component and CIQ.UI.Context.setLookupDriver

Parameters:
Name Type Description
exchanges array

An array of exchanges that can be searched against

Since:
  • 6.0.0
Example
// sample implementation
CIQ.ChartEngine.Driver.Lookup.ChartIQ=function(exchanges){
	this.exchanges=exchanges;
	if(!this.exchanges) this.exchanges=["XNYS","XASE","XNAS","XASX","INDCBSX","INDXASE","INDXNAS","IND_DJI","ARCX","INDARCX","forex"];
	this.url="https://symbols.chartiq.com/chiq.symbolserver.SymbolLookup.service";
	this.requestCounter=0;  //used to invalidate old requests
};

//Inherits all of the base Look Driver's properties via `ciqInheritsFrom()`
	CIQ.ChartEngine.Driver.Lookup.ChartIQ.ciqInheritsFrom(CIQ.ChartEngine.Driver.Lookup);

Methods


acceptText(text [, filter], maxResults, cb)

Abstract method used to accept the selected text with optional filter and return an array of properly formatted objects.

You should implement your own instance of this method to fetch results from your symbol list and return them by calling cb(your-results-array-here);

Each element in the array should be of the following format: { display:["symbol-id","Symbol Description","exchange"], data:{ symbol:"symbol-id", name:"Symbol Description", exchDis:"exchange" } }

Parameters:
Name Type Argument Description
text string

The text entered by the user

filter string <optional>

The optional filter text selected by the user. This will be the innerHTML of the cq-filter element that is selected.

maxResults number

Max number of results to return from the server

cb function

Callback upon results

Since:
  • 6.0.0
Examples
// sample implementation
		CIQ.ChartEngine.Driver.Lookup.ChartIQ.prototype.acceptText=function(text, filter, maxResults, cb){
			if(filter=="FX") filter="FOREX";
			if(isNaN(parseInt(maxResults, 10))) maxResults=100;
			var 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;
			}

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

					var results=[];
					for(var i=0;i<symbols.length;i++){
						var fields=symbols[i].split('|');
						var 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 response 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"}}
 ];