Create an Order UsingFIX 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, seeFIX Trading Community.

To access the example code, enteredit FixFlyerExample.mat the command line.

Connect toFIX Flyer

Import the FIX Flyer Java®libraries.

importflyer.apps.*;importflyer.apps.FlyerApplicationManagerFactory.*;importflyer.core.session.*;

Create the FIX Flyer Engine connectioncusing these arguments:

  • User nameusername

  • Passwordpassword

  • IP addressipaddress

  • Port numberport

  • Order information port numberorderport

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 listenerfixExampleListener.

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

Process the FIX Flyer Engine eventseusing the sample event handling listenerfixExampleListener. Specifyeas any letter.fixExampleListenerreturns a handle to the listenerlh.

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 arrayorder. 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 theMsgTypeto'D'to denote a new order.

秩序。BeginString{1,1} ='FIX.4.4';秩序。CLOrdId{1,1} ='338';秩序。Side{1,1} ='2';秩序。TransactTime{1,1} = datestr(now); order.OrdType{1,1} ='D';秩序。Symbol{1,1} ='IBM';秩序。HandlInst{1,1} ='1';秩序。MsgType{1,1} ='D';秩序。OrderQty{1,1} ='1000';秩序。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';秩序。CLOrdId{2,1} ='339';秩序。Side{2,1} ='2';秩序。TransactTime{2,1} = datestr(now); order.OrdType{2,1} ='D';秩序。Symbol{2,1} ='IBM';秩序。HandlInst {2,} ='1';秩序。MsgType{2,1} ='D';秩序。OrderQty{2,1} ='1000';秩序。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.statuscontains a logical zero for a successful message delivery.

status = sendMessage(c,order);

Return Order Information

Return and display the order informationofor all orders. The Variables editor displays the contents ofo.

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

Replace an order. Create a FIX messagereplacewith an updated quantity of 3378 shares. Set the fieldMsgTypeto'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 ofo.

status = sendMessage(c,replace); o = orderInfo(c); openvar('o')

Now, cancel the order. Create a FIX message取消with order number338. Set the fieldMsgTypeto'F'to specify a cancel order.

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

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

status = sendMessage(c,cancel); o = orderInfo(c); openvar('o')

Receive FIX Message

Use the sample event handling listenerfixExampleListener听修复信息修复飞行注意事项ne. The listenerfixExampleListenerreturns the raw FIX message in the tablefixResponse. Display the first three columns of the table. The column names offixResponsecontain 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'

CloseFIX FlyerConnection

close(c)

See Also

||||

External Websites