-
Notifications
You must be signed in to change notification settings - Fork 38
JS Api
What it is ?: A set of JS methods (specific public interface).
What should I do to use it ?: You should create a JS object which will receive the data by some way and respond to Charting Library requests.
Data caching (history & symbol info) is implemented in Charting Library. When you create an object implementing described interface, just pass it to Library widget constructor through datafeed argument.
- onReady
- searchSymbolsByName
- resolveSymbol
- getBars
- subscribeBars
- unsubscribeBars
- calculateHistoryDepth
- getMarks
- getTimescaleMarks
- getServerTime
💹 Trading Platform specific:
-
callback
: function(configurationData) -
configurationData
: object (see below)
This call is intended to provide the object filled with configuration data. This data affects some of chart behavior aspects so it is called server-side customization. Charting Library expects you will call callback and pass your datafeed configurationData
as an argument. Configuration data is an object; for now, following properties are supported:
An array of exchange descriptors. Exchange descriptor is an object {value, name, desc}
. value
will be passed as exchange
argument to searchSymbolsByName (see below).
exchanges
= [] leads to exchanges filter absence in Symbol Search list. Use value
= "" if you want to create wildcard filter (all exchanges).
An array of filter descriptors. Filter descriptor is an object {name, value}
. value
will be passed as symbolType
argument to searchSymbolsByName.
symbolsTypes
= [] leads to types filter absence in Symbol Search list. Use value
= "" if you want to create wildcard filter (all types)
An array of supported resolutions. Resolution may be a number or a string. If the resolution is a number, it is treated as minutes count. Strings may be "*D", "*W", "M" ( means any number).
'resolutions'=undefined or [] leads to resolutons widget having its default content (see http://tradingview.com/e/ ). Example: [1, 15, 240, "D", "6M"]
will give you "1 minute, 15 minutes, 4 hours, 1 day, 6 months" in resolution widget.
Boolean showing whether your datafeed supports marks on bars or not.
Boolean showing whether your datafeed supports timescale marks or not.
Set this one to true
if your datafeed provides server time (unix time). It is used to adjust Countdown on the Price scale.
-
userInput
: string. It is text entered by user in symbol search field -
exchange
: string. The requested exchange (chosen by user). Empty value means no filter was specified. -
symbolType
: string. The requested symbol type: index, stock, forex e.t.c. (chosen by user). Empty value means no filter was specified. -
onResultReadyCallback
: function(result) -
result
: array (see below)
This call is intended to provide the list of symbols matching to user's search query. result
is expected to be smth like this:
[
{
"symbol": <short symbol name>,
"full_name": <full symbol name -- e.g., BTCE:BTCUSD>,
"description": <symbol description>,
"exchange": <symbol exchange name>,
"ticker": <symbol ticker name, optional>,
"type": "stock" | "futures" | "bitcoin" | "forex" | "index"
}, {
// .....
}
]
If no symbols are found, then callback should be called with an empty array. See more details about ticker
value here
-
symbolName
: string. Symbol name orticker
if provided. -
onSymbolResolvedCallback
: function(SymbolInfo) -
onResolveErrorCallback
: function(reason)
Charting Library will call this function when it need to get SymbolInfo by symbol's name.
-
symbolInfo
: SymbolInfo object -
resolution
: string -
from
: unix timestamp, leftmost required bar time -
to
: unix timestamp, rightmost required bar time -
onHistoryCallback
: function(array ofbar
s,meta
= {version = 2, noData = false}) -
bar
: object{time, close, open, high, low, volume}
-
meta
: object{version = 2, noData = true | false, nextTime}
-
onErrorCallback
: function(reason) -
firstDataRequest
: boolean to identify the first history call for this symbol/resulution. When it istrue
you can ignoreto
(which depends on browser'sDate.now()
) and return bars up to current bar (including it).
This function is called when chart needs a history fragment defined by dates range. The charting library expects onHistoryCallback
to be called just once after receiving all the requesting history. No further calls are expected.
Remark: each bar object must have time
and close
properties. Others are optional.
Remark 2: bar.time
is expected to be the amount of milliseconds since Unix epoch start in UTC timezone.
-
symbolInfo
: SymbolInfo object -
resolution
: string -
onRealtimeCallback
: function(bar) -
bar
: object{time, close, open, high, low, volume}
-
subscriberUID
: object
Charting Library calls this function when it wants to receive realtime updates for a symbol. Chart expects you will call onRealtimeCallback
every time you want to update the most recent bar or to append a new one.
Remark: When you call onRealtimeCallback
with bar having time equal to most recent bar's time, the whole last bar is replaced with the bar
object you've passed into the call. Example:
- The most recent bar is
{1419411578413, 10, 12, 9, 11}
- You call
onRealtimeCallback({1419411578413, 10, 14, 9, 14})
- Library finds out that bar with time
1419411578413
already exists and is the most recent one - Library replaces the whole bar so now the most recent bar is
{1419411578413, 10, 14, 9, 14}
Remark 2: Is it possible either to update the most recent bar or to append a new one with onRealtimeCallback
. You've get an error if you call this function trying to update a bar in history.
Remark 3: For now, there is no way to change bars in history after the chart received it.
-
subscriberUID
: object
Library calls this function when is doesn't want to receive updates for this subscriber any more. subscriberUID
will be the same object which Library passed to subscribeBars
before.
-
resolution
: requested symbol's resolution -
resolutionBack
: desired history period dimension. Supported values:D
|M
-
intervalBack
: amount orresolutionBack
periods which Library is going to request
Charting Library calls this function when it is going to request some history data to give you an ability to override required history depth. It passes some arguments so you could know how much bars is it going to get. Here are a few examples:
-
calculateHistoryDepth("D", "M", 12)
called: the Library is going to request 12 months of daily bars -
calculateHistoryDepth(60, "D", 15)
called: the Library is going to request 15 days of hourly bars
This function should return undefined
if you do not want to override anything. If you do, it should return an object {resolutionBack, intervalBack}
. Properties meaning is similar to respective arguments' one.
Example:
Assume the implementation is
Datafeed.prototype.calculateHistoryDepth = function(resolution, resolutionBack, intervalBack) {
if (period == "1D") {
return {
resolutionBack: 'M',
intervalBack: 6
};
}
}
This means when Charting Library will request the data for '1D' resolution, the history will be 6 months in depth. In all other cases the history depth will have the default value.
-
symbolInfo
: SymbolInfo object -
startDate
: unix timestamp (UTC). Leftmost visible bar's time. -
endDate
: unix timestamp (UTC). Rightmost visible bar's time. -
onDataCallback
: function(array ofmark
s) -
resolution
: string
Library calls this function to get marks for visible bars range. Chart expects you to call onDataCallback
only once per each getMarks
call. mark
is an object having following properties:
- id: unique mark id. Will be passed to a respective callback when user clicks on a mark
- time: unix time, UTC
-
color:
red
|green
|blue
|yellow
- text: mark popup text. HTML supported
- label: a letter to be printed on a mark. Single character
- labelFontColor: color of a letter on a mark
- minSize: minimal size of mark (diameter, pixels)
A few marks per bar are allowed (for now, maximum is 10). Marks out of bars are not allowed.
Remark: This function will be called only if you declared your back-end is supporting marks.
-
symbolInfo
: SymbolInfo object -
startDate
: unix timestamp (UTC). Leftmost visible bar's time. -
endDate
: unix timestamp (UTC). Rightmost visible bar's time. -
onDataCallback
: function(array ofmark
s) -
resolution
: string
Library calls this function to get timescale marks for visible bars range. Chart expects you to call onDataCallback
only once per each getTimescaleMarks
call. mark
is an object having following properties:
- id: unique mark id. Will be passed to a respective callback when user clicks on a mark
- time: unix time, UTC
-
color:
red
|green
|blue
|yellow
| ... | #000000 - label: a letter to be printed on a mark. Single character
- tooltip: array of text strings. Each element of the array is a new text line of a tooltip.
Only one mark per bar is allowed. Marks out of bars are not allowed.
Remark: This function will be called only if you declared your back-end is supporting marks.
-
callback
: function(unixTime)
This function is called if configuration flag supports_time
is set to true
when chart needs to know the server time. The charting library expects callback to be called once. The time is provided without milliseconds. Example: 1445324591
. It is used to display Countdown on the price scale.
💹 Trading Platform specific
-
symbols
: array of symbols names -
onDataCallback
: function(array ofdata
) -
data
: symbol quote data -
onErrorCallback
: function(reason)
This function is called when chart needs quotes data. The charting library expects onDataCallback to be called once when all requesting data received. No further calls are expected.
-
symbols
: array of symbols to be updated rarely (suggested frequency is once per minute). These symbols are in the watch list but they are not visible at the moment. -
fastSymbols
: array of symbols to be updated quite frequently (once in 10 seconds or more often) -
onRealtimeCallback
: function(array ofdata
) -
data
: symbol quote data -
listenerGUID
: unique identifier of the listener
Charting Library calls this function when it wants to receive realtime quotes for a symbol. Chart expects you will call onRealtimeCallback
every time you want to update quotes.
-
listenerGUID
: unique identifier of the listener
Library calls this function when is doesn't want to receive updates for this listener any more. listenerGUID
will be the same object which Library passed to subscribeQuotes
before.
#Wiki Content
- What is Charting Library
- Getting Started
- Package Content
- Running Your Charting Library
- Data Binding
- How To Connect My Data
- JS API
- UDF
- Symbology
- Trading Sessions
- Quotes
- Chart Customization
- Charts Customization 101
- Client-Side Customization 1. Widget Constructor 2. Widget Methods 3. Chart Methods 4. Featuresets
- Server-Side Customization
- Trading Platform
- Brief Intro
- Trading Controller
- Saving/Loading Charts
- Creating Custom Studies
- Best Practices
- Breaking changes in versions