This SDK reference provides comprehensive details about the methods, interfaces, and message types available in the TakeProfit Widget SDK. It is designed to help developers effectively integrate and utilize the SDK to build interactive widgets within the TakeProfit platform.
connect()
disconnect()
hideLoader()
getWidgetState()
getChannelState()
subscribeWidgetChange(callback)
unsubscribeWidgetChange(callback)
subscribeChannelChange(callback)
unsubscribeChannelChange(callback)
requestChangeSecurity(securityID, callback)
addMenuItem(label, callback, disabled)
updateMenuItem(menuItemId, disabled, menuItemLabel)
removeMenuItem(menuItemId)
postMessage
API to enable communication between the embedded widget (via an iframe) and the parent platform.
ID
(string
): Unique identifier for the channel.securityID
(SecurityID | null
): Identifier for the associated security. null
if no security is selected.security
(Security | null
): Details of the current security. null
if no security is selected.widgetID
(string
): Unique identifier for the widget.channelID
(string | null
): Identifier of the associated channel. null
if not associated with any channel.active
(boolean
): Indicates whether the widget is active.fullscreen
(boolean
): Indicates whether the widget is displayed in fullscreen mode.ID
(SecurityID
): Unique identifier for the security (e.g., "AAPL;BATS"
).ticker
(string
): Ticker symbol of the security (e.g., "AAPL"
).precision
(number
): Decimal precision for pricing.name
(string
): Full name of the security (e.g., "Apple Inc."
).exchangeCode
(string | undefined
): Code of the exchange.iconURL
(string | undefined
): URL to the security’s icon.iconBase64
(string | undefined
): Base64-encoded icon data.iconBackgroundColor
(string | undefined
): Background color for the icon.className
(string | undefined
): Classification name (e.g., "Common stocks"
).classNameTopLevel
(string | undefined
): Top-level classification (e.g., "Equity"
).companyName
(string | undefined
): Name of the company.countryCode
(string | undefined
): Country code (e.g., "US"
).exchangeAlias
(string | undefined
): Alias for the exchange (e.g., "NASDAQ"
).industryName
(string | undefined
): Name of the industry (e.g., "Radio & TV communications equipment"
).type
('widgetUpdate'
): Message type identifier.payload
(WidgetStateInfo
): New state information for the widget.type
('channelUpdate'
): Message type identifier.payload
(Channel
): New channel information.type
('requestSecurityChange'
): Message type identifier.payload
:
requestId
(number
): Unique identifier for tracking the request.securityID
(SecurityID
): Identifier of the new security to be selected.type
('securityChangeResult'
): Message type identifier.payload
:
isSuccessful
(boolean
): Indicates if the security change was successful.requestId
(number
): Identifier for tracking the request.error
(string
): Error message if the request failed.type
('requestAddMenuItem'
): Message type identifier.payload
:
requestId
(number
): Unique identifier for tracking the request.menuItemLabel
(string
): Label for the new menu item.eventName
(string
): Event name triggered when the menu item is clicked.menuItemId
(number
): Identifier for the new menu item.disabled
(boolean
): Indicates if the menu item should be disabled.type
('menuEvent'
): Message type identifier.payload
:
eventName
(string
): Name of the event associated with the clicked menu item.RequestInitData
: Used to request initial data. No payload.RequestCloseConnect
: Used to request the closing of a connection. No payload.isWidgetUpdateMessage
WidgetUpdateMessage
.
isChannelUpdateMessage
ChannelUpdateMessage
.
isSecurityChangeResult
SecurityChangeResult
.
isMenuItemRequestResult
ManageMenuItemResults
type.
isMenuEventMessage
MenuEventMessage
.
Method | Description |
---|---|
connect() | Establishes a connection with the platform and initializes message handling. |
disconnect() | Removes message event listeners, effectively disconnecting the widget from the platform. |
hideLoader() | Signals the platform to hide the loading screen, indicating that the widget is ready. |
getWidgetState() | Retrieves the current state of the widget. |
getChannelState() | Retrieves the current state of the channel. |
subscribeWidgetChange(callback) | Subscribes to widget state changes. |
unsubscribeWidgetChange(callback) | Unsubscribes from widget state changes. |
subscribeChannelChange(callback) | Subscribes to channel state changes. |
unsubscribeChannelChange(callback) | Unsubscribes from channel state changes. |
requestChangeSecurity(securityID, callback) | Requests a change in the selected security. |
addMenuItem(label, callback, disabled) | Adds a new menu item to the widget header. |
updateMenuItem(menuItemId, disabled, menuItemLabel) | Updates an existing menu item in the widget header. |
removeMenuItem(menuItemId) | Removes a menu item from the widget header. |
connect()
RequestInitData
message to the parent to retrieve initial widget and channel states.disconnect()
hideLoader()
RequestHideLoader
message to the parent window.getWidgetState()
WidgetStateInfo | null
- The current widget state or null
if not available.
Usage:
getChannelState()
Channel | null
- The current channel state or null
if not available.
Usage:
subscribeWidgetChange(callback)
callback
((widgetState: WidgetStateInfo | null) => void
): Function to be called with the new widget state.unsubscribeWidgetChange(callback)
callback
((widgetState: WidgetStateInfo | null) => void
): The callback function to remove.subscribeChannelChange(callback)
callback
((channelState: Channel | null) => void
): Function to be called with the new channel state.unsubscribeChannelChange(callback)
callback
((channelState: Channel | null) => void
): The callback function to remove.requestChangeSecurity(securityID, callback)
securityID
(SecurityID
): Identifier of the new security to select (e.g., "AAPL;BATS"
).callback
((result: SecurityChangeResult) => void
): Function to handle the result of the security change request.void
Usage:
addMenuItem(label, callback, disabled)
label
(string
): The display label of the menu item.callback
(() => void
): Function to execute when the menu item is clicked.disabled
(boolean
, optional): Indicates whether the menu item should be disabled. Defaults to false
.Promise<number>
- Resolves with the ID of the added menu item if successful.
Usage:
updateMenuItem(menuItemId, disabled, menuItemLabel)
menuItemId
(number
): The ID of the menu item to update, as returned by addMenuItem
.disabled
(boolean
, optional): Indicates whether the menu item should be disabled.menuItemLabel
(string
, optional): New label for the menu item.Promise<boolean>
- Resolves to true
if the update was successful.
Usage:
removeMenuItem(menuItemId)
menuItemId
(number
): The ID of the menu item to remove, as returned by addMenuItem
.Promise<boolean>
- Resolves to true
if the removal was successful.
Usage:
postMessage
API. It listens for incoming messages from the parent window and processes them based on their type.
takeprofit.com
) are processed.isWidgetUpdateMessage
) to determine the type of incoming messages.widgetState
, channelState
) and notifies subscribed callbacks.widgetChangeSubscriptions
, channelChangeSubscriptions
) store callback functions that are invoked when the widget or channel state updates.changeSecuritySubscriptions
, menuItemSubscriptions
) track callbacks associated with specific request IDs, ensuring the correct callback is executed when a response is received.menuItemsCallbacks
) associates event names with callback functions, allowing the SDK to execute the appropriate callback when a menu item is clicked.requestId
: The SDK automatically increments messageCounter
to generate unique requestId
s. Avoid manually setting requestId
s to prevent conflicts.
SecurityID
"TICKER;EXCHANGE"
.
ManageMenuItemResults
Message
RequestUpdateMenuItem
type
('requestUpdateMenuItem'
): Message type identifier.payload
:
requestId
(number
): Unique identifier for tracking the request.menuItemId
(number
): ID of the menu item to update.disabled
(boolean
, optional): Indicates if the menu item should be disabled.menuItemLabel
(string
, optional): New label for the menu item.RequestRemoveMenuItem
type
('requestRemoveMenuItem'
): Message type identifier.payload
:
requestId
(number
): Unique identifier for tracking the request.menuItemId
(number
): ID of the menu item to remove.AddMenuItemResult
type
('addMenuItemResult'
): Message type identifier.payload
:
isSuccessful
(boolean
): Indicates if the menu item was successfully added.requestId
(number
): Identifier for tracking the request.error
(string
): Error message if the request failed.UpdateMenuItemResult
type
('updateMenuItemResult'
): Message type identifier.payload
:
isSuccessful
(boolean
): Indicates if the menu item was successfully updated.requestId
(number
): Identifier for tracking the request.error
(string
): Error message if the request failed.RemoveMenuItemResult
type
('removeMenuItemResult'
): Message type identifier.payload
:
isSuccessful
(boolean
): Indicates if the menu item was successfully removed.requestId
(number
): Identifier for tracking the request.error
(string
): Error message if the request failed.SecurityID
"TICKER;EXCHANGE"
.
ManageMenuItemResults
Message