How To Get Market Price From Fix Server Using Quick Fix

5,038 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,038
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
109
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

How To Get Market Price From Fix Server Using Quick Fix

  1. 1. How to get MarketPrice from FixServerusing QuickFix?PurposeThis in continuation with previous post on QuickFix which explain how to connect to FIXServer and send order to Fix Server.I dont have any environment to test now. I just want to give idea about how can we getmarket price from FIX server if broker/exchange is sending market price in FIX messages.I am assuming session has been setup with Fix Server. You can go thorough previous post tounderstand about steps to set up session.MarketDataRequestOnce session has setup, Fix Initiator application needs to send MarketDataRequest messageto FIX server.Response can be different messages: MarketDataRequestReject This is reject response of MarketDataRequest message. Market Data - Incremental Refresh (MarketDataIncrementalRefresh) This message contain incremental update of market price. Its real time message for MarketDataRequest. Market Data - Snapshot / Full Refresh (MarketDataSnapshotFullRefresh) This message will be one per MarketDataRequest message. It contains snapshot of market prices.Fix InitiatorSource CodevarmarketDataRequest = new MarketDataRequest();marketDataRequest.set(new QuickFix.MDReqID(Utility.GetNewUniqueId()));marketDataRequest.set(new QuickFix.SubscriptionRequestType(1)); //if market depth requiremarketDataRequest.set(new QuickFix.MarketDepth(1));marketDataRequest.set(new QuickFix.MDUpdateType(1));marketDataRequest.set(new QuickFix.AggregatedBook(true));varnoMDEntryTypes = new MarketDataRequest.NoMDEntryTypes();varmdEntryType_bid = new QuickFix.MDEntryType(0);noMDEntryTypes.set(mdEntryType_bid);marketDataRequest.addGroup(noMDEntryTypes);varmdEntryType_offer = new QuickFix.MDEntryType(1);
  2. 2. noMDEntryTypes.set(mdEntryType_offer);marketDataRequest.addGroup(noMDEntryTypes);varrelatedSymbol = new MarketDataRequest.NoRelatedSym();relatedSymbol.set(new QuickFix.Symbol(instrument));marketDataRequest.addGroup(relatedSymbol);//Send messageSession.sendToTarget(marketDataRequest, _admin.TradeSessionId);MarketDataRequest Message Fields NoRelatedSym: this is list of instrument for which you want to receive market prices. MarketDepth: if you want market depth in price then set it 1. MDEntryType: type of Market Data prices like Bid, Offer, Trade Price, Open price etc.You can read more about each field here.http://btobits.com/fixopaedia/fixdic50/message_Market_Data_Request_V_.htmlCapture MarketData ResponseOnce Marketdatarequest message sent to FixServer, fix initiator expect marketdata responsein MarketDataIncrementalRefresh MarketDataSnapshotFullRefresh MarketDataRequestRejectMarketDataIncrementalRefreshYou can read more about this message:http://btobits.com/fixopaedia/fixdic50/message_Market_Data_Incremental_Refresh_X_.htmlSource CodepublicoverridevoidonMessage(MarketDataIncrementalRefresh message, SessionID session) {try {MDReqIDmdreqid = newMDReqID();NoMDEntriesnomdentries = newNoMDEntries(); QuickFix42.MarketDataIncrementalRefresh.NoMDEntries group = newQuickFix42.MarketDataIncrementalRefresh.NoMDEntries();MDUpdateActionmdupdateaction = newMDUpdateAction();DeleteReasondeletereason = newDeleteReason();MDEntryTypemdentrytype = newMDEntryType();MDEntryIDmdentryid = newMDEntryID();Symbolsymbol = newSymbol();MDEntryOriginatormdentryoriginator = newMDEntryOriginator();MDEntryPxmdentrypx = newMDEntryPx();Currencycurrency = newCurrency();
  3. 3. MDEntrySizemdentrysize = newMDEntrySize();ExpireDateexpiredate = newExpireDate();ExpireTimeexpiretime = newExpireTime();NumberOfOrdersnumberoforders = newNumberOfOrders();MDEntryPositionNomdentrypositionno = newMDEntryPositionNo();message.get(nomdentries);message.getGroup(1, group);int list = nomdentries.getValue();for (uinti = 0; i< list; i++) {message.getGroup(i + 1, group);group.get(mdupdateaction);if (mdupdateaction.getValue() == 2)Console.WriteLine("Enter");group.get(deletereason);group.get(mdentrytype);group.get(mdentryid);group.get(symbol);group.get(mdentryoriginator);if (mdupdateaction.getValue() == 0)group.get(mdentrypx);group.get(currency);if (mdupdateaction.getValue() == 0)group.get(mdentrysize); }Console.WriteLine("Got Symbol {0} Price {1}", symbol.getValue(),mdentrypx.getValue()); }catch (Exception ex) {Console.WriteLine(ex.Message); } }MarketDataSnapshotFullRefreshThis message will be one per MarketDataRequest message. It contains snapshot of marketprices.http://btobits.com/fixopaedia/fixdic50/message_Market_Data_Snapshot_Full_Refresh_W_.htmlSource CodepublicoverridevoidonMessage(MarketDataSnapshotFullRefresh message, SessionID session) {string Symbol = message.get(newSymbol()).getValue();NoMDEntriesnoMDEntries = newNoMDEntries();message.get(noMDEntries);
  4. 4. var group =new QuickFix42.MarketDataSnapshotFullRefresh.NoMDEntries();MDEntryTypeMDEntryType = newMDEntryType();MDEntryPxMDEntryPx = newMDEntryPx();MDEntrySizeMDEntrySize = newMDEntrySize();message.getGroup(1, group);group.get(MDEntryType);group.get(MDEntryPx);group.get(MDEntrySize);message.getGroup(2, group);group.get(MDEntryType);group.get(MDEntryPx);group.get(MDEntrySize);Console.WriteLine("Symbol {0} Price {1}", Symbol, MDEntryPx); }Market Data Request RejectIt is used when the broker cannot honor the Market Data Request, due to business or technicalreasons.FieldsMDReqRejReason : Reject reason codeText: Reject reason text.I hope this post gives overview of how to capture Market Price from FIX server.

×