3.5.10.3Selecting an order template

You can ask the user to select a saved order template using ChooseOrderTemplate(). The template can then be passed into the deal ticket or chart, as the orderDefinition, pre-populating the deal ticket. For example:

Framework.ChooseOrderTemplate(null, function(template) {

// Asynchronously receives the selected template, or null

if (template) {

// Potentially modify or add to the template

// …

// And then pass the template into the deal ticket

Framework.CreateDialog({

type: "dealticket",

settings: {

orderDefinition: template

}

});

}

});

Alternatively, you can add an instrumentId into the template and then execute the order yourself, without displaying a deal ticket:

Framework.ChooseOrderTemplate(null, function(template) {

// Asynchronously receives the selected template, or null

if (template) {

// Put the required market into the template

template.instrumentId = <some market ID>;

// And then pass the template into the deal ticket

Framework.SendOrder(template, function (MsgResult) {

// … handle asynchronous success or failure

});

}

});

The first parameter for ChooseOrderTemplate() is an optional block of settings which can contain the following properties:

Property

Description

showNone

Adds a "None" button to the selection dialog. Allows you to distinguish between the user cancelling the dialog versus saying "I don't want to use a stored template". If the button is clicked then the return value from ChooseOrderTemplate() is the string "none" (rather than a template object).

showDefault

Similar to showNone, but with different styling. Displays a "Default" button rather than a "None" button, and returns the string "default".

There is no functional difference between showNone and showDefault. Choosing to use the term "Default" is slightly clearer to the user that, if nothing is explicitly pre-populated into the deal ticket, then the deal ticket will automatically select any user-defined default template. For example:

Framework.ChooseOrderTemplate({showDefault: true}, function(template) {

if (template == "default") {

// User clicked the Default button.

// Display the deal ticket. A blank or omitted orderDefinition will mean

// that the deal ticket automatically selects any user-defined default

Framework.CreateDialog({

type: "dealticket"

});

} else if (template) {

// User selected a template

// Pre-populate the selected template into the deal ticket

Framework.CreateDialog({

type: "dealticket",

settings: {

orderDefinition: template

}

});

} else {

// (User cancelled the dialog)

}

});