API Reference - Providers
Providers are a way to integrate data with outside world - host application
Mandatory providers
To load candles and chart service data (Quotes, Trades, ...)
ChartDataProvider
- ChartDataProvider.requestHistoryData
- Parameters
- symbol: string
- aggregation: AggregationPeriod
- options: { fromTime?: number; toTime?: number; } & ChartDataOptions
- `fromTime` and `toTime` are candles timestamps, that simply reflect the current state of the chart. Therefore, you can either use the current state of the chart to calculate the necessary query parameters, or completely ignore them. `fromTime` is an oldest candle's timestamp which should be data get from, `toTime` is the newest (usually `toTime` candle equals the oldest visible candle)
- updateCallback: (data: ChartCandleData[]) => void
- !!! WARNING !!! This function updates the whole instrument's history data
- chartId: string
- Returns
- Promise<ChartCandleData[]>
ChartDataProvider.requestHistoryData(symbol: string, aggregation: AggregationPeriod, options: { fromTime?: number; toTime?: number; } & ChartDataOptions, updateCallback: (data: ChartCandleData[]) => void, chartId: string): Promise<ChartCandleData[]>
There might be 3 possible cases: 1. Initial data request when left bound of viewport somewhere in the history data and right bound at current candle tick. In this situation `requestHistoryData` method will provide only `fromTime` parameter (that's a base case for initial viewport). In other words `fromTime` will point somewhere on the left bound of viewport. That means that in this case you should provide history data AT LEAST from `fromTime` to right now, the time when request were made. BUT you can give more history data if you want. 2. lnitial data request when left and right bound of viewport somewhere in the history data. This can happen when user for example reloads the page when their viewport somewhere in the history data. In this situation `requestHistoryData` will provide only `fromTime` parameter too. It means that even in this case you should provide all the history data from `fromTime` to right now, the time when request were made. That's pretty much the same case as №1. 3. Lazy load of candles, that are on the left to timeline, i.e older history data. On initial load you can give chart any amount of candles you like, it might be 100 or 1000, doesn't matter. Depends on you. This means that when we scroll to the left to older data, we will have as much candles as you provided. When we will reach the oldest history candle, chart will fire `requestHistoryData` to request even older data, i.e lazy load. In this situation `requestHistoryData` will only provide `toTime`. Why this way? Because again, you can give chart any amount of data you want, so there's no point in `fromTime` parameter. You may not give any data in the response - this would mean that there's no history data left.
- ChartDataProvider.subscribeCandles
- Parameters
- symbol: string
- aggregation: AggregationPeriod
- subscriptionId: string
- subscribeCallback: (data: ChartCandleData[]) => void
- options: ChartDataOptions
- chartId: string
- Returns
- void
ChartDataProvider.subscribeCandles(symbol: string, aggregation: AggregationPeriod, subscriptionId: string, subscribeCallback: (data: ChartCandleData[]) => void, options: ChartDataOptions, chartId: string): void
- ChartDataProvider.unsubscribeCandles
- Parameters
- subscriptionId: string
- Returns
- void
ChartDataProvider.unsubscribeCandles(subscriptionId: string): void
Unsubscribe is called when symbol, aggregation or options are changed
- ChartDataProvider.subscribeServiceData
- Parameters
- symbol: string
- subscribeCallback: (data: ServiceData) => void
- Returns
- void
ChartDataProvider.subscribeServiceData(symbol: string, subscribeCallback: (data: ServiceData) => void): void
- ChartDataProvider.unsubscribeServiceData
- Parameters
- symbol: string
- Returns
- void
ChartDataProvider.unsubscribeServiceData(symbol: string): void
SymbolSuggestProvider
Symbol suggest provider fetches instrument data
- SymbolSuggestProvider.findInstrument
- Parameters
- symbol: string
- Returns
- Promise<Instrument>
SymbolSuggestProvider.findInstrument(symbol: string): Promise<Instrument>
By given instrument symbol returns exactly one instrument (or throws error)
- SymbolSuggestProvider.searchInstruments
- Parameters
- search: string
- Returns
- Promise<Instrument[]>
SymbolSuggestProvider.searchInstruments(search: string): Promise<Instrument[]>
By given search string returns Promise of suggest result.
- SymbolSuggestProvider.onInstrumentChanged
- Parameters
- symbol: string
- - new instrument symbol
- chartId: string
- - chart on which instrument was changed; if all 4 charts changed - callback will be called 4 times.
- Returns
- void
SymbolSuggestProvider.onInstrumentChanged(symbol: string, chartId: string): void
Callback when instrument changed in specific chartId (multichart 0,1,2,3 supported).
Additional features providers
LayoutProvider
To remember the layout of user and store it in DB as PLAIN_TEXT
- LayoutProvider.createLayout
- Parameters
- layout: ChartLayoutNamed
- - new layout to create
- Returns
- Promise<string>
LayoutProvider.createLayout(layout: ChartLayoutNamed): Promise<string>
Creates the new layout. Returns either the ID or error.
- LayoutProvider.getLayouts
- Returns
- Promise<ChartLayoutData>
LayoutProvider.getLayouts(): Promise<ChartLayoutData>
Loads all available layouts including default one. If layout is loaded for the first time - Promise.reject() should be returned, after that updateLayouts method will be called by chart with default layout created.
- LayoutProvider.updateLayout
- Parameters
- layoutData: ChartLayoutWithId
- - layout to update
- Returns
- Promise<void>
LayoutProvider.updateLayout(layoutData: ChartLayoutWithId): Promise<void>
Update layout to persistence layer. No update expected from subscribeLayouts when this fn is called. The layout will be updated with different version if layout version does not match chart's version (migration will be performed).
- LayoutProvider.updateSelectedLayout
- Parameters
- id: string
- - layout that's need to be selected
- Returns
- Promise<void>
LayoutProvider.updateSelectedLayout(id: string): Promise<void>
Updates selected layout state.
- LayoutProvider.updateLayoutData
- Parameters
- layoutData: ChartLayoutData
- - layout data to update
- Returns
- Promise<void>
LayoutProvider.updateLayoutData(layoutData: ChartLayoutData): Promise<void>
Update layout data
- LayoutProvider.deleteLayout
- Parameters
- id: string
- - layout with that id will be deleted
- Returns
- Promise<void>
LayoutProvider.deleteLayout(id: string): Promise<void>
Delete layout by id from layout state.
UserDataProvider
To remember global user settings like custom colors and custom aggregation periods
- UserDataProvider.getUserData
- Returns
- Promise<UserData>
UserDataProvider.getUserData(): Promise<UserData>
Returns custom user data. If no data available, Promise.reject() is also valid return value
- UserDataProvider.setUserData
- Parameters
- userData: UserData
- Returns
- Promise<void>
UserDataProvider.setUserData(userData: UserData): Promise<void>
Updates custom user data
IndicatorsTemplateProvider
To save indicator templates for quick access
- IndicatorsTemplateProvider.createTemplate
- Parameters
- template: IndicatorTemplateNamed
- Returns
- Promise<string>
IndicatorsTemplateProvider.createTemplate(template: IndicatorTemplateNamed): Promise<string>
Creates new indicator template. Returns either an `id` of newly created template or error.
- IndicatorsTemplateProvider.deleteTemplate
- Parameters
- id: string
- Returns
- Promise<void>
IndicatorsTemplateProvider.deleteTemplate(id: string): Promise<void>
Deletes an indicator template by `id`.
- IndicatorsTemplateProvider.updateTemplate
- Parameters
- template: IndicatorTemplate
- - full {@link IndicatorTemplate} model with updates.
- Returns
- Promise<void>
IndicatorsTemplateProvider.updateTemplate(template: IndicatorTemplate): Promise<void>
Updates an indicator template.
- IndicatorsTemplateProvider.getTemplates
- Returns
- Promise<IndicatorTemplates>
IndicatorsTemplateProvider.getTemplates(): Promise<IndicatorTemplates>
Returns all available indicator templates for a user.
ChartSharingProvider
To share chart snapshot images
- ChartSharingProvider.uploadChartSnapshot
- Parameters
- blob: Blob
- image to share
- options: UploadOptions
- Returns
- Promise<UploadResult>
ChartSharingProvider.uploadChartSnapshot(blob: Blob, options: UploadOptions): Promise<UploadResult>
Uploads image on server and returns a link to uploaded image
DxScriptProvider
To make use of powerful dxScript language
- DxScriptProvider.getScriptList
- Returns
- TDxScriptWithoutCode[]
DxScriptProvider.getScriptList(): TDxScriptWithoutCode[]
- DxScriptProvider.fetchAllScripts
- Returns
- Promise<TDxScriptWithoutCode[]>
DxScriptProvider.fetchAllScripts(): Promise<TDxScriptWithoutCode[]>
- DxScriptProvider.getScript
- Parameters
- id: string
- Returns
- Promise<TDxScript>
DxScriptProvider.getScript(id: string): Promise<TDxScript>
- DxScriptProvider.createScript
- Parameters
- script: TDxScriptWithoutId
- Returns
- Promise<string>
DxScriptProvider.createScript(script: TDxScriptWithoutId): Promise<string>
- DxScriptProvider.updateScript
- Parameters
- script: TDxScriptWithoutCode
- Returns
- Promise<void>
DxScriptProvider.updateScript(script: TDxScriptWithoutCode): Promise<void>
- DxScriptProvider.deleteScript
- Parameters
- id: string
- Returns
- Promise<void>
DxScriptProvider.deleteScript(id: string): Promise<void>
OrderProvider
To integrate trading orders
- OrderProvider.observeOrders
- Parameters
- symbol: string
- dataCallback: (orders: OrderWithId[]) => void
- Returns
- void
OrderProvider.observeOrders(symbol: string, dataCallback: (orders: OrderWithId[]) => void): void
Observes the order lines updates. We expect to be the full list of orders - no partial updates, for now the full list will be replaced.
- OrderProvider.observeExecutedOrders
- Parameters
- symbol: string
- dataCallback: (orders: ExecutedOrder[]) => void
- Returns
- void
OrderProvider.observeExecutedOrders(symbol: string, dataCallback: (orders: ExecutedOrder[]) => void): void
Observes the executed orders. We expect to be the full list of executed orders - no partial updates, for now the full list will be replaced.
- OrderProvider.createOrder
- Parameters
- symbol: string
- order: Order
- Returns
- Promise<string>
OrderProvider.createOrder(symbol: string, order: Order): Promise<string>
Creates new order We expect creating "id" for order inside this method If you create protection order, please don't forget to link it to original order by "protectionOrderIds" field
- OrderProvider.createOcoOrders
- Parameters
- symbol: string
- - current instrument's symbol
- parentOrderId: string
- - id of the order from which OCO orders will be created
- orders: [Order, Order]
- - array of two orders, which will be created as OCO orders
- Returns
- Promise<[string, string]>
OrderProvider.createOcoOrders(symbol: string, parentOrderId: string, orders: [Order, Order]): Promise<[string, string]>
Creates new OCO orders We expect creating "ids" for the orders inside this method TODO: right now OCO orders is not fully supported by chart, so instead of orders will be passed [undefined, undefined]
- OrderProvider.updateOrder
- Parameters
- symbol: string
- order: OrderWithId
- Returns
- Promise<void>
OrderProvider.updateOrder(symbol: string, order: OrderWithId): Promise<void>
Updates single order
- OrderProvider.deleteOrder
- Parameters
- symbol: string
- order: OrderWithId
- Returns
- Promise<void>
OrderProvider.deleteOrder(symbol: string, order: OrderWithId): Promise<void>
Deletes single order Please, take a look at "protectionOrdersIds" field: if order with type "original" order was deleted, protection orders should be deleted too.
PositionProvider
To integrate trading positions
- PositionProvider.observePositions
- Parameters
- symbol: string
- dataCallback: (positions: Position[]) => void
- Returns
- void
PositionProvider.observePositions(symbol: string, dataCallback: (positions: Position[]) => void): void
- PositionProvider.closePosition
- Parameters
- symbol: string
- id: string
- Returns
- Promise<void>
PositionProvider.closePosition(symbol: string, id: string): Promise<void>
- PositionProvider.closePositionWithOcoOrders
- Parameters
- symbol: string
- - current instrument's symbol
- parentPositionId: string
- orders: [Order, Order]
- - array of two orders, which will be created as OCO orders
- Returns
- Promise<[string, string]>
PositionProvider.closePositionWithOcoOrders(symbol: string, parentPositionId: string, orders: [Order, Order]): Promise<[string, string]>
Closes position with new OCO orders We expect creating "ids" for the orders inside this method TODO: right now OCO orders is not fully supported by chart, so instead of orders will be passed [undefined, undefined]
TradingSessionsProvider
To change the way trading sessions work
- TradingSessionsProvider.generateSessions
- Parameters
- from: number
- timestamp
- to: number
- timestamp
- options: GenerateSessionOptions
- see
- Returns
- Promise<TradingSession[]>
TradingSessionsProvider.generateSessions(from: number, to: number, options: GenerateSessionOptions): Promise<TradingSession[]>
Generates trading sessions
- TradingSessionsProvider.getTimeZone
- Parameters
- options: GenerateSessionOptions
- Returns
- Promise<string>
TradingSessionsProvider.getTimeZone(options: GenerateSessionOptions): Promise<string>
Returns timezone for specified symbol and trading hours
EventsDataProvider
Fetches fundamental economic events
- EventsDataProvider.requestEventsData
- Parameters
- symbol: string
- - symbol to get {@link EventsData} for
- Returns
- Promise<EventsData>
EventsDataProvider.requestEventsData(symbol: string): Promise<EventsData>
Returns events data for a symbol
NewsDataProvider
Fetches news related to the instrument
- NewsDataProvider.requestNews
- Parameters
- symbol: string
- options: AtLeastOne<RequestNewsOptions, "fromTime">
- Returns
- Promise<NewsData>
NewsDataProvider.requestNews(symbol: string, options: AtLeastOne<RequestNewsOptions, "fromTime">): Promise<NewsData>
DxStudiesProvider
To add studies to the project
- DxStudiesProvider.getStudies
- Returns
- TStudySettings[]
DxStudiesProvider.getStudies(): TStudySettings[]
- DxStudiesProvider.observeStudies
- Returns
- Observable<TStudySettings[]>
DxStudiesProvider.observeStudies(): Observable<TStudySettings[]>
- DxStudiesProvider.setStudies
- Parameters
- studies: TStudySettings[]
- Returns
- void
DxStudiesProvider.setStudies(studies: TStudySettings[]): void
- DxStudiesProvider.updateStudy
- Parameters
- study: TStudySettings
- Returns
- void
DxStudiesProvider.updateStudy(study: TStudySettings): void
- DxStudiesProvider.getStudy
- Parameters
- id: string
- Returns
- TStudySettings
DxStudiesProvider.getStudy(id: string): TStudySettings