Caplin Trader 4.8.0

Class: module:caplin/trading/statemachine/StateMachineFactory

module:caplin/trading/statemachine/StateMachineFactory

Constructor

new module:caplin/trading/statemachine/StateMachineFactory()

Constructs a caplin.trading.statemachine.StateMachineFactory. The StateMachineFactory is responsible providing module:caplin/trading/statemachine/StateMachines, which are constructed from an XML configuration file (provided with module:caplin/trading/statemachine/StateMachineFactory#loadModels. A StateMachine instance is required to construct a module:caplin/trading/trademodel/Trade instance.
The XML configuration file defines the States and Transitions within the trade model. Below is an example XML configuration file for the ESP trading protocol.
<?xml version="1.0" encoding="UTF-8" ?>
<tradeModels>
  <tradeModel name="ESP" initialState="Initial">
	 <state name="Initial">
	   <transition target="OpenSent" trigger="Open" source="client"/>
	 </state>
	 <state name="OpenSent" timeout="10" timeoutEvent="Timeout">
	   <transition target="Opened" trigger="OpenAck" source="server"/>
	 </state>
	 <state name="Opened">
	   <transition target="TradeConfirmed" trigger="TradeConfirmation"  source="server"/>
	   <transition target="TradePassed" trigger="Pass" source="server"/>
	   <transition target="TradeExpired" trigger="Expired" source="server"/>
	 </state>
	 <state name="TradeConfirmed">
	 </state>
	 <state name="TradePassed">
	 </state>
	 <state name="TradeExpired">
	 </state>
  </tradeModel>
</tradeModels>

The XML configuration file contains all possible routes a trade can traverse on its way to completion, whether or not it is successful. There are a number of states, each containing a number of transitions that cause the trade model to move to other states. A transition defines the message that will cause the change to occur, and the new state the model will move into. Transition events correlate to either server-side or client-side trade messages.

Methods

getStateMachine(modelName)

Returns a new StateMachine for the specified model name.
Parameters:
Name Type Description
modelName String The model name for the wanted StateMachine.
Throws:
If the specified model does not exist.
Type
module:caplin/core/Error
Returns:
A new state machine for the specified model name, set to the initial state.

loadModels(fileUrl)

Loads the models into the factory from the given file at the specified url.
Parameters:
Name Type Description
fileUrl String The URL of the file to load the models from.
See:
Throws:
If more than one model with the same name is defined in the XML, or if there was an error parsing the XML.
Type
module:caplin/core/Error

loadModelsFromXml(sXmlString)

Loads the models into the factory from the specified XML string.
Parameters:
Name Type Description
sXmlString String The XML to load the models from.
See:
Throws:
If more than one model with the same name is defined in the XML, or if there was an error parsing the XML.
Type
module:caplin/core/Error

loadModelsFromXmlElement(XML)

Loads the models into the factory from the specified XML DOM element.
Parameters:
Name Type Description
XML DOM element to load the models from.
See:
Throws:
If more than one model with the same name is defined in the XML, or if there was an error parsing the XML.
Type
module:caplin/core/Error