www.gusucode.com > trading工具箱matlab源码程序 > trading/trading/@fixflyer/sendMessage.m

    function status = sendMessage(f,fixStruct)
%SENDMESSAGE Send FIX message to FIX Flyer engine.
%   STATUS = SENDMESSAGE(F,FIXSTRUCT) given the FIX Flyer object sends a 
%   FIX message constructed from the structure or table FIXSTRUCT.
%
%   For example, make the connection
%
%   f = fixflyer('guest','guest','127.0.0.1',7002);
%   listener = f.addListener(@(~,e)fixExampleListener(e));
%   f.SessionID = flyer.core.session.SessionID('Alpha','Beta','FIX.4.4');
%   f.FlyerApplicationManager.registerFIXSession( flyer.apps.FixSessionSubscription(f.SessionID,true,0));
%   f.FlyerApplicationManager.connect();
%   f.FlyerApplicationManager.start();
%
%   construct the FIX structure order structure
%
%   fixStruct.BeginString = {'FIX.4.4'};
%   fixStruct.CLOrdId = {'338'};
%   fixStruct.Side = {'2'};
%   fixStruct.TransactTime = {datestr(now)};
%   fixStruct.OrdType = {'D'};
%   fixStruct.Symbol = {'ABC'};
%   fixStruct.HandlInst = {'A'};
%   fixStruct.MsgType = {'D'};
%   fixStruct.OrderQty = {'100'};
%
%   and send the message
%
%   status = f.sendMessage(fixStruct);
%
%   In this example, events are handled by the function fixExampleListener.
%   FIX messages will be returned in base workspace in the variable
%   fixResponseStruct.
%
%   See also fixflyer, addListener, close, orderInformation.

%   Copyright 2016 The MathWorks, Inc.

% imports
import flyer.apps.*;
import flyer.apps.FlyerApplicationManagerFactory.*;
import flyer.core.session.*;

% FIXFlyer application message
appMessage = ApplicationMessage;

% Convert structure to FIX message format
switch class(fixStruct)
  case 'struct'
    rawFIX = struct2fix(fixStruct);
  case 'table'
    rawFIX = table2fix(fixStruct);
end

% Preallocate output
numMessages = length(rawFIX);
status = false(numMessages,1);

% Send messages
for i = 1:numMessages
  appMessage.reset;
  appMessage.senderCompID.append(f.SessionID.getSenderCompIDAsBytes);
  appMessage.targetCompID.append(f.SessionID.getTargetCompIDAsBytes);
  appMessage.fixMsgType.append(fixStruct.OrdType{i}*1);
  appMessage.possDupFlag = false;
  appMessage.possResendFlag = false;
  appMessage.rawContent.append(java.lang.String(rawFIX{i}).getBytes);
  status(i) = f.FlyerApplicationManager.sendMessage(appMessage);
end