Caplin Trader 5.1.0

Class: module:ct-trading/testing/TradeMessageServiceStub

module:ct-trading/testing/TradeMessageServiceStub()

new module:ct-trading/testing/TradeMessageServiceStub()

Constructs an instance of TradeMessageServiceStub.

A TradeSubscribeStub stubs out a module:ct-trading/trademodel/TradeMessageService instance for the purpose of testing trades and trading components in acceptance tests and workbenches. The TradeMessageServiceStub mocks out a subscription for only one trade, as only one is typically required in a test or in a component's workbench.

Implements:

Methods

addEventLogger(fLogger)

This method registers an event logging function with this mock TradeMessageService. This function is called for all events Events being "sent" by a trade and "received" from a server mock. A component workbench or a mock server will typically register a logger in order to display or be informed of the mocked trade events. Callback functions must handle the following 3 parameters:

  • the event name (String)
  • the direction of the event (eg. send/ receive) (String)
  • the event data (Map)
Parameters:
Name Type Description
fLogger function

the callback function to log mock trade events

addTrade(oTrade)

Assigns the trade as the subscriber to mocked trade messages.

Parameters:
Name Type Description
oTrade module:ct-trading/trademodel/Trade

the trade object.

Implements:

receiveServerTradeEvent(sEventName, mData)

This method is called by a mock trade server to simulate the receipt of a trade event from Liberator via SL4B. The event is propagated to the Trade subscribed via this mock trade subscriber. This stub will print out the message to a logger if one has been defined.

Parameters:
Name Type Description
sEventName String

the event name that is being received from the server

mData Map | Object

the data being received for this event

receiveTradeChannelStatusChange(bEnabled)

This method is called by a mock trade server to simulate a channel status change of the trade subscriber. The change event is propagated to the Trade subscribed via this mock trade subscriber. The new subscriber status will be printed to a logger if one has been defined.

Parameters:
Name Type Description
bEnabled boolean

the new trading status received

removeTrade(oTrade)

Unregisters the trade subscribed to mocked trade messages.

Parameters:
Name Type Description
oTrade module:ct-trading/trademodel/Trade

the trade object.

Implements:

sendTradeEvent(sEventName, oTrade, oData)

This method is called by a module:ct-trading/trademodel/Trade to simulate the sending of a trade event to Liberator via SL4B. This stub will print out the message to a logger if one has been defined.

Parameters:
Name Type Description
sEventName String

the event name that is being sent to the server.

oTrade module:ct-trading/trademodel/Trade

the trade object.

oData module:ct-trading/trademodel/DataHolder

the data being sent with this event.

Implements: