• C#
  • Java
  • VB
  • C++
  • Python
Contact us
Display Groups

Display Groups function allows API clients to integrate with TWS Color Grouping Windows.

TWS Color Grouping Windows are identified by a colored chain in TWS and by an integer number via the API. Currently that number ranges from 1 to 7 and are mapped to specific colors, as indicated in TWS.

Query Display Groups

The IBApi.EClient.queryDisplayGroups method is used to request all available Display Groups in TWS.

  • client.queryDisplayGroups(9001);
  • client.queryDisplayGroups(9001);
  • client.queryDisplayGroups(9001)
  • m_pClient->queryDisplayGroups(9001);
  • 1  self.queryDisplayGroups(19001)

The IBApi.EWrapper.displayGroupList is a one-time response to IBApi.EClient.queryDisplayGroups.

It returns a list of integers representing visible Group ID separated by the "|" character, and sorted by most used group first. This list will not change during TWS session. In other words, user cannot add a new group, but only the sorting of the group numbers can change.

Example: "4|1|2|5|3|6|7"

  • public class EWrapperImpl : EWrapper
    {
    ...
    public virtual void displayGroupList(int reqId, string groups)
    {
    Console.WriteLine("DisplayGroupList. Request: " + reqId + ", Groups" + groups);
    }
  • public class EWrapperImpl implements EWrapper {
    ...
    @Override
    public void displayGroupList(int reqId, String groups) {
    System.out.println("Display Group List. ReqId: " + reqId + ", Groups: " + groups + "\n");
    }
  • Public Sub displayGroupList(reqId As Integer, groups As String) Implements IBApi.EWrapper.displayGroupList
    Console.WriteLine("DisplayGroupList - ReqId [" & reqId & "] Groups [" & groups & "]")
    End Sub
  • class TestCppClient : public EWrapper
    {
    ...
    void TestCppClient::displayGroupList( int reqId, const std::string& groups) {
    printf("Display Group List. ReqId: %d, Groups: %s\n", reqId, groups.c_str());
    }
  • 1 class TestWrapper(wrapper.EWrapper):
    ...
    1  def displayGroupList(self, reqId: int, groups: str):
    2  super().displayGroupList(reqId, groups)
    3  print("DisplayGroupList. ReqId:", reqId, "Groups", groups)

Subscribe To Group Events

To integrate with a specific Group, you need to first subscribe to the group number by invoking IBApi.EClient.subscribeToGroupEvents.

  • client.subscribeToGroupEvents(9002, 1);
  • client.subscribeToGroupEvents(9002, 1);
  • client.subscribeToGroupEvents(9002, 1)
  • m_pClient->subscribeToGroupEvents(9002, 1);
  • 1  self.subscribeToGroupEvents(19002, 1)

The IBApi.EWrapper.displayGroupUpdated call back is triggered once after receiving the subscription request, and will be sent again if the selected contract in the subscribed display group has changed.

  • public class EWrapperImpl : EWrapper
    {
    ...
    public virtual void displayGroupUpdated(int reqId, string contractInfo)
    {
    Console.WriteLine("displayGroupUpdated. Request: " + reqId + ", ContractInfo: " + contractInfo);
    }
  • public class EWrapperImpl implements EWrapper {
    ...
    @Override
    public void displayGroupUpdated(int reqId, String contractInfo) {
    System.out.println("Display Group Updated. ReqId: " + reqId + ", Contract info: " + contractInfo + "\n");
    }
  • Public Sub displayGroupUpdated(reqId As Integer, contractInfo As String) Implements IBApi.EWrapper.displayGroupUpdated
    Console.WriteLine("DisplayGroupUpdated - ReqId [" & reqId & "] ContractInfo [" & contractInfo & "]")
    End Sub
  • class TestCppClient : public EWrapper
    {
    ...
    void TestCppClient::displayGroupUpdated( int reqId, const std::string& contractInfo) {
    std::cout << "Display Group Updated. ReqId: " << reqId << ", Contract Info: " << contractInfo << std::endl;
    }
  • 1 class TestWrapper(wrapper.EWrapper):
    ...
    1  def displayGroupUpdated(self, reqId: int, contractInfo: str):
    2  super().displayGroupUpdated(reqId, contractInfo)
    3  print("DisplayGroupUpdated. ReqId:", reqId, "ContractInfo:", contractInfo)

Update Display Group

Once you have subscribed to a specific Group, you can then have the Group Window in TWS to display a certain contract by invoking IBApi.EClient.updateDisplayGroup.

The encoded value that uniquely represents the contract in IB. Possible values include:

  1. none = empty selection
  2. contractID@exchange - any non-combination contract. Examples: 8314@SMART for IBM SMART; 8314@ARCA for IBM @ARCA
  3. combo = if any combo is selected
  • client.updateDisplayGroup(9002, "8314@SMART");
  • client.updateDisplayGroup(9002, "8314@SMART");
  • client.updateDisplayGroup(9002, "8314@SMART")
  • m_pClient->updateDisplayGroup(9002, "8314@SMART");
  • 1  self.updateDisplayGroup(19002, "8314@SMART")

Note: This request from the API does not get a response from TWS unless an error occurs.

In the above sample we have commanded TWS Windows that chained with Group #1 to display IBM@SMART. The screenshot of TWS Mosaic below shows that both the pink chained (Group #1) windows are now displaying IBM@SMART, while the green chained (Group #4) window remains unchanged:

display_groups_sample.png

Unsubscribe From Group Events

Invoke the IBApi.EClient.unsubscribeFromGroupEvents method to cancel a group subscription.

  • client.unsubscribeFromGroupEvents(9002);
  • client.unsubscribeFromGroupEvents(9002);
  • client.unsubscribeFromGroupEvents(9002)
  • m_pClient->unsubscribeFromGroupEvents(9002);
  • 1  self.unsubscribeFromGroupEvents(19002)