Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Create an Order Using FIX Flyer

This example shows how to create a FIX Flyer™ connection, process event data for sending FIX messages, and submit various orders using FIX messages.

FIX is a financial industry protocol that facilitates low latency trading. For details about the FIX protocol, see FIX Trading Community.

To access the example code, enter edit FixFlyerExample.m at the command line.

Connect to FIX Flyer

Import the FIX Flyer Java® libraries.

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

Create the FIX Flyer Engine connection c using these arguments:

  • User name username

  • Password password

  • IP address ipaddress

  • Port number port

  • Order information port number orderport

username = 'guest';
password = 'guest';
ipaddress = 'example.fixcomputeserver.com';
port = 12001;
orderport = 13001;

c = fixflyer(username,password,ipaddress,port,orderport);

Add Listener and Subscribe to FIX Sessions

Add the FIX Flyer event listener to the FIX Flyer Engine connection. Listen for and display the FIX Flyer Engine event data in the Workspace browser by using the sample event handling listener fixExampleListener.

To access the code for the listener, enter edit fixExampleListener.m. Or, to process the event data in another way, you can write a custom event handling listener function. For details, see Create Functions in Files (MATLAB).

Process the FIX Flyer Engine events e using the sample event handling listener fixExampleListener. Specify e as any letter. fixExampleListener returns a handle to the listener lh.

lh = addListener(c,@(~,e)fixExampleListener(e,c));

Subscribe to FIX sessions and set up the FIX Flyer Application Manager. Register with the FIX Flyer session. Connect the FIX Flyer Application Manager to the FIX Flyer Engine and start the internal receiving thread.

c.SessionID = flyer.core.session.SessionID('Alpha',...
                                           'Beta','FIX.4.4');
c.FlyerApplicationManager.setLoadDefaultDataDictionary(false);
c.FlyerApplicationManager.registerFIXSession(...
                                            flyer.apps.FixSessionSubscription(...
                                            c.SessionID,true,0));
c.FlyerApplicationManager.connect;
c.FlyerApplicationManager.start;

Create FIX Messages

Create two FIX messages using a structure array order. Each structure in the array represents one FIX message. Both messages denote a sell side transaction for 1000 IBM® shares. The order type is a previously quoted order. The order handling instruction is a private automated execution. The order transaction time is the current moment. The FIX protocol version is 4.4.

Set the MsgType to 'D' to denote a new order.

order.BeginString{1,1} = 'FIX.4.4';
order.CLOrdId{1,1} = '338';
order.Side{1,1} = '2';
order.TransactTime{1,1} = datestr(now);
order.OrdType{1,1} = 'D';
order.Symbol{1,1} = 'IBM';
order.HandlInst{1,1} = '1';
order.MsgType{1,1} = 'D';
order.OrderQty{1,1} = '1000';
order.HeaderFields{1,1} = {'OnBehalfOfCompID','TRADER'};
order.BodyFields{1,1} = {'NoPartyIDs','3'; ...
                         'PartyID','1'; ...
                         'PartyRole','BBVA'; ...
                         'PartyID','1'; ...
                         'PartyRole','CVGX'; ...
                         'PartyID','1'; ...
                         'PartyRole','GSAM'};
order.BeginString{2,1} = 'FIX.4.4';
order.CLOrdId{2,1} = '339';
order.Side{2,1} = '2';
order.TransactTime{2,1} = datestr(now);
order.OrdType{2,1} = 'D';
order.Symbol{2,1} = 'IBM';
order.HandlInst{2,1} = '1';
order.MsgType{2,1} = 'D';
order.OrderQty{2,1} = '1000';
order.HeaderFields{2,1} = {'OnBehalfOfCompID','TRADER'};
order.BodyFields{2,1} = {'NoPartyIDs','3'; ...
                         'PartyID','1'; ...
                         'PartyRole','BBVA'; ...
                         'PartyID','1'; ...
                         'PartyRole','CVGX'; ...
                         'PartyID','1'; ...
                         'PartyRole','GSAM'};

Send FIX Messages

Use the FIX Flyer Engine connection to send the FIX messages. status contains a logical zero for a successful message delivery.

status = sendMessage(c,order);

Return Order Information

Return and display the order information o for all orders. The Variables editor displays the contents of o.

o = orderInfo(c);
openvar('o')

Replace an order. Create a FIX message replace with an updated quantity of 3378 shares. Set the field MsgType to 'G' to specify a replace order.

replace.BeginString{1,1} = 'FIX.4.4';
replace.CLOrdId{1,1} = '338_REPLACE';
replace.origClOrdId{1,1} = '338';
replace.Symbol{1,1} = 'IBM';
replace.OnBehalfOfCompID{1,1} = 'TRADER';
replace.OrdType{1,1} = 'D';
replace.OrderQty{1,1} = '3378';
replace.MsgType{1,1} = 'G';
replace.Text{1,1} = 'REST API REPLACE';

Send the FIX message. To see the replaced order, retrieve and display the order information. The Variables editor displays the contents of o.

status = sendMessage(c,replace);

o = orderInfo(c);
openvar('o')

Now, cancel the order. Create a FIX message cancel with order number 338. Set the field MsgType to 'F' to specify a cancel order.

cancel.BeginString{1,1} = 'FIX.4.4';
cancel.CLOrdId{1,1} = '338_CANCEL';
cancel.origClOrdId{1,1} = '338_REPLACE';
cancel.Symbol{1,1} = 'IBM';
cancel.OnBehalfOfCompID{1,1} = 'TRADER';
cancel.OrdType{1,1} = 'D';
cancel.MsgType{1,1} = 'F';
cancel.Text{1,1} = 'REST API CANCEL';

Send the FIX message. Then retrieve and display the canceled order information. The Variables editor displays the contents of o.

status = sendMessage(c,cancel);

o = orderInfo(c);
openvar('o')

Receive FIX Message

Use the sample event handling listener fixExampleListener to listen for FIX messages from the FIX Flyer Engine. The listener fixExampleListener returns the raw FIX message in the table fixResponse. Display the first three columns of the table. The column names of fixResponse contain FIX tag names from the returned raw FIX message. The data in the columns contain the values of the returned raw FIX message.

fixResponse(:,1:3)
ans = 

    BeginString    BodyLength    MsgType
    ___________    __________    _______

    'FIX.4.4'      '219'         '8'    

Close FIX Flyer Connection

close(c)

See Also

| | | |

External Websites

Was this topic helpful?