datafeed-api.d.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. export declare type ResolutionString = string;
  2. export interface Exchange {
  3. value: string;
  4. name: string;
  5. desc: string;
  6. }
  7. export interface DatafeedSymbolType {
  8. name: string;
  9. value: string;
  10. }
  11. export interface DatafeedConfiguration {
  12. exchanges?: Exchange[];
  13. supported_resolutions?: ResolutionString[];
  14. supports_marks?: boolean;
  15. supports_time?: boolean;
  16. supports_timescale_marks?: boolean;
  17. symbols_types?: DatafeedSymbolType[];
  18. }
  19. export declare type OnReadyCallback = (configuration: DatafeedConfiguration) => void;
  20. export interface IExternalDatafeed {
  21. onReady(callback: OnReadyCallback): void;
  22. }
  23. export interface DatafeedQuoteValues {
  24. ch?: number;
  25. chp?: number;
  26. short_name?: string;
  27. exchange?: string;
  28. description?: string;
  29. lp?: number;
  30. ask?: number;
  31. bid?: number;
  32. spread?: number;
  33. open_price?: number;
  34. high_price?: number;
  35. low_price?: number;
  36. prev_close_price?: number;
  37. volume?: number;
  38. original_name?: string;
  39. [valueName: string]: string | number | undefined;
  40. }
  41. export interface QuoteOkData {
  42. s: 'ok';
  43. n: string;
  44. v: DatafeedQuoteValues;
  45. }
  46. export interface QuoteErrorData {
  47. s: 'error';
  48. n: string;
  49. v: object;
  50. }
  51. export declare type QuoteData = QuoteOkData | QuoteErrorData;
  52. export declare type QuotesCallback = (data: QuoteData[]) => void;
  53. export interface IDatafeedQuotesApi {
  54. getQuotes(symbols: string[], onDataCallback: QuotesCallback, onErrorCallback: (msg: string) => void): void;
  55. subscribeQuotes(symbols: string[], fastSymbols: string[], onRealtimeCallback: QuotesCallback, listenerGUID: string): void;
  56. unsubscribeQuotes(listenerGUID: string): void;
  57. }
  58. export declare type CustomTimezones = 'America/New_York' | 'America/Los_Angeles' | 'America/Chicago' | 'America/Phoenix' | 'America/Toronto' | 'America/Vancouver' | 'America/Argentina/Buenos_Aires' | 'America/El_Salvador' | 'America/Sao_Paulo' | 'America/Bogota' | 'America/Caracas' | 'Europe/Moscow' | 'Europe/Athens' | 'Europe/Berlin' | 'Europe/London' | 'Europe/Madrid' | 'Europe/Paris' | 'Europe/Rome' | 'Europe/Warsaw' | 'Europe/Istanbul' | 'Europe/Zurich' | 'Australia/Sydney' | 'Australia/Brisbane' | 'Australia/Adelaide' | 'Australia/ACT' | 'Asia/Almaty' | 'Asia/Ashkhabad' | 'Asia/Tokyo' | 'Asia/Taipei' | 'Asia/Singapore' | 'Asia/Shanghai' | 'Asia/Seoul' | 'Asia/Tehran' | 'Asia/Dubai' | 'Asia/Kolkata' | 'Asia/Hong_Kong' | 'Asia/Bangkok' | 'Pacific/Auckland' | 'Pacific/Chatham' | 'Pacific/Fakaofo' | 'Pacific/Honolulu' | 'America/Mexico_City' | 'Africa/Johannesburg' | 'Asia/Kathmandu' | 'US/Mountain';
  59. export declare type Timezone = 'UTC' | CustomTimezones;
  60. export interface LibrarySymbolInfo {
  61. /**
  62. * Symbol Name
  63. */
  64. name: string;
  65. full_name: string;
  66. base_name?: [string];
  67. /**
  68. * Unique symbol id
  69. */
  70. ticker?: string;
  71. description: string;
  72. type: string;
  73. /**
  74. * @example "1700-0200"
  75. */
  76. session: string;
  77. /**
  78. * Traded exchange
  79. * @example "NYSE"
  80. */
  81. exchange: string;
  82. listed_exchange: string;
  83. timezone: Timezone;
  84. /**
  85. * Code (Tick)
  86. * @example 8/16/.../256 (1/8/100 1/16/100 ... 1/256/100) or 1/10/.../10000000 (1 0.1 ... 0.0000001)
  87. */
  88. pricescale: number;
  89. /**
  90. * The number of units that make up one tick.
  91. * @example For example, U.S. equities are quotes in decimals, and tick in decimals, and can go up +/- .01. So the tick increment is 1. But the e-mini S&P futures contract, though quoted in decimals, goes up in .25 increments, so the tick increment is 25. (see also Tick Size)
  92. */
  93. minmov: number;
  94. fractional?: boolean;
  95. /**
  96. * @example Quarters of 1/32: pricescale=128, minmovement=1, minmovement2=4
  97. */
  98. minmove2?: number;
  99. /**
  100. * false if DWM only
  101. */
  102. has_intraday?: boolean;
  103. /**
  104. * An array of resolutions which should be enabled in resolutions picker for this symbol.
  105. */
  106. supported_resolutions: ResolutionString[];
  107. /**
  108. * @example (for ex.: "1,5,60") - only these resolutions will be requested, all others will be built using them if possible
  109. */
  110. intraday_multipliers?: string[];
  111. has_seconds?: boolean;
  112. /**
  113. * It is an array containing seconds resolutions (in seconds without a postfix) the datafeed builds by itself.
  114. */
  115. seconds_multipliers?: string[];
  116. has_daily?: boolean;
  117. has_weekly_and_monthly?: boolean;
  118. has_empty_bars?: boolean;
  119. force_session_rebuild?: boolean;
  120. has_no_volume?: boolean;
  121. /**
  122. * Integer showing typical volume value decimal places for this symbol
  123. */
  124. volume_precision?: number;
  125. data_status?: 'streaming' | 'endofday' | 'pulsed' | 'delayed_streaming';
  126. /**
  127. * Boolean showing whether this symbol is expired futures contract or not.
  128. */
  129. expired?: boolean;
  130. /**
  131. * Unix timestamp of expiration date.
  132. */
  133. expiration_date?: number;
  134. sector?: string;
  135. industry?: string;
  136. currency_code?: string;
  137. }
  138. export interface DOMLevel {
  139. price: number;
  140. volume: number;
  141. }
  142. export interface DOMData {
  143. snapshot: boolean;
  144. asks: DOMLevel[];
  145. bids: DOMLevel[];
  146. }
  147. export interface Bar {
  148. time: number;
  149. open: number;
  150. high: number;
  151. low: number;
  152. close: number;
  153. volume?: number;
  154. }
  155. export interface SearchSymbolResultItem {
  156. symbol: string;
  157. full_name: string;
  158. description: string;
  159. exchange: string;
  160. ticker: string;
  161. type: string;
  162. }
  163. export interface HistoryMetadata {
  164. noData: boolean;
  165. nextTime?: number | null;
  166. }
  167. export interface MarkCustomColor {
  168. color: string;
  169. background: string;
  170. }
  171. export declare type MarkConstColors = 'red' | 'green' | 'blue' | 'yellow';
  172. export interface Mark {
  173. id: string | number;
  174. time: number;
  175. color: MarkConstColors | MarkCustomColor;
  176. text: string;
  177. label: string;
  178. labelFontColor: string;
  179. minSize: number;
  180. }
  181. export interface TimescaleMark {
  182. id: string | number;
  183. time: number;
  184. color: MarkConstColors | string;
  185. label: string;
  186. tooltip: string[];
  187. }
  188. export declare type ResolutionBackValues = 'D' | 'M';
  189. export interface HistoryDepth {
  190. resolutionBack: ResolutionBackValues;
  191. intervalBack: number;
  192. }
  193. export declare type SearchSymbolsCallback = (items: SearchSymbolResultItem[]) => void;
  194. export declare type ResolveCallback = (symbolInfo: LibrarySymbolInfo) => void;
  195. export declare type HistoryCallback = (bars: Bar[], meta: HistoryMetadata) => void;
  196. export declare type SubscribeBarsCallback = (bar: Bar) => void;
  197. export declare type GetMarksCallback<T> = (marks: T[]) => void;
  198. export declare type ServerTimeCallback = (serverTime: number) => void;
  199. export declare type DomeCallback = (data: DOMData) => void;
  200. export declare type ErrorCallback = (reason: string) => void;
  201. export interface IDatafeedChartApi {
  202. calculateHistoryDepth?(resolution: ResolutionString, resolutionBack: ResolutionBackValues, intervalBack: number): HistoryDepth | undefined;
  203. getMarks?(symbolInfo: LibrarySymbolInfo, startDate: number, endDate: number, onDataCallback: GetMarksCallback<Mark>, resolution: ResolutionString): void;
  204. getTimescaleMarks?(symbolInfo: LibrarySymbolInfo, startDate: number, endDate: number, onDataCallback: GetMarksCallback<TimescaleMark>, resolution: ResolutionString): void;
  205. /**
  206. * This function is called if configuration flag supports_time is set to true when chart needs to know the server time.
  207. * The charting library expects callback to be called once.
  208. * The time is provided without milliseconds. Example: 1445324591. It is used to display Countdown on the price scale.
  209. */
  210. getServerTime?(callback: ServerTimeCallback): void;
  211. searchSymbols(userInput: string, exchange: string, symbolType: string, onResult: SearchSymbolsCallback): void;
  212. resolveSymbol(symbolName: string, onResolve: ResolveCallback, onError: ErrorCallback): void;
  213. getBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, rangeStartDate: number, rangeEndDate: number, onResult: HistoryCallback, onError: ErrorCallback, isFirstCall: boolean): void;
  214. subscribeBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, onTick: SubscribeBarsCallback, listenerGuid: string, onResetCacheNeededCallback: () => void): void;
  215. unsubscribeBars(listenerGuid: string): void;
  216. subscribeDepth?(symbolInfo: LibrarySymbolInfo, callback: DomeCallback): string;
  217. unsubscribeDepth?(subscriberUID: string): void;
  218. }
  219. export as namespace TradingView;