/// <summary> /// Create a NewOrderSingle message. /// </summary> /// <param name="customFields"></param> /// <param name="orderType"></param> /// <param name="side"></param> /// <param name="symbol"></param> /// <param name="orderQty"></param> /// <param name="tif"></param> /// <param name="price">ignored if orderType=Market</param> /// <returns></returns> static public QuickFix.FIX42.NewOrderSingle NewOrderSingle( Dictionary <int, string> customFields, OrderType orderType, Side side, string symbol, int orderQty, TimeInForce tif, decimal price) { // hard-coded fields QuickFix.Fields.HandlInst fHandlInst = new QuickFix.Fields.HandlInst(QuickFix.Fields.HandlInst.AUTOMATED_EXECUTION_ORDER_PRIVATE); // from params QuickFix.Fields.OrdType fOrdType = FixEnumTranslator.ToField(orderType); QuickFix.Fields.Side fSide = FixEnumTranslator.ToField(side); QuickFix.Fields.Symbol fSymbol = new QuickFix.Fields.Symbol(symbol); QuickFix.Fields.TransactTime fTransactTime = new QuickFix.Fields.TransactTime(DateTime.Now); QuickFix.Fields.ClOrdID fClOrdID = GenerateClOrdID(); QuickFix.FIX42.NewOrderSingle nos = new QuickFix.FIX42.NewOrderSingle( fClOrdID, fHandlInst, fSymbol, fSide, fTransactTime, fOrdType); nos.OrderQty = new QuickFix.Fields.OrderQty(orderQty); nos.TimeInForce = FixEnumTranslator.ToField(tif); if (orderType == OrderType.Limit) { nos.Price = new QuickFix.Fields.Price(price); } // add custom fields foreach (KeyValuePair <int, string> p in customFields) { nos.SetField(new QuickFix.Fields.StringField(p.Key, p.Value)); } return(nos); }
/// <summary> /// Create a NewOrderSingle message. /// </summary> /// <param name="customFields"></param> /// <param name="orderType"></param> /// <param name="side"></param> /// <param name="symbol"></param> /// <param name="orderQty"></param> /// <param name="tif"></param> /// <param name="price">ignored if orderType=Market</param> /// <returns></returns> static public QuickFix.FIX42.NewOrderSingle NewOrderSingle( Dictionary<int,string> customFields, OrderType orderType, Side side, string symbol, int orderQty, TimeInForce tif, decimal price) { // hard-coded fields QuickFix.Fields.HandlInst fHandlInst = new QuickFix.Fields.HandlInst(QuickFix.Fields.HandlInst.AUTOMATED_EXECUTION_ORDER_PRIVATE); // from params QuickFix.Fields.OrdType fOrdType = FixEnumTranslator.ToField(orderType); QuickFix.Fields.Side fSide = FixEnumTranslator.ToField(side); QuickFix.Fields.Symbol fSymbol = new QuickFix.Fields.Symbol(symbol); QuickFix.Fields.TransactTime fTransactTime = new QuickFix.Fields.TransactTime(DateTime.Now); QuickFix.Fields.ClOrdID fClOrdID = GenerateClOrdID(); QuickFix.FIX42.NewOrderSingle nos = new QuickFix.FIX42.NewOrderSingle( fClOrdID, fHandlInst, fSymbol, fSide, fTransactTime, fOrdType); nos.OrderQty = new QuickFix.Fields.OrderQty(orderQty); nos.TimeInForce = FixEnumTranslator.ToField(tif); if (orderType == OrderType.Limit) nos.Price = new QuickFix.Fields.Price(price); // add custom fields foreach (KeyValuePair<int,string> p in customFields) nos.SetField(new QuickFix.Fields.StringField(p.Key, p.Value)); return nos; }
/// <summary> /// Creates a FIX4.3 MarketDataRequest message. /// </summary> /// <param name="id"></param> /// <param name="security"></param> /// <param name="subscriptionType"></param> /// <param name="depth"></param> /// <returns></returns> public QuickFix.FIX43.MarketDataRequest MarketDataRequest(string id, Security security, char subscriptionType, int depth) { QuickFix.FIX43.MarketDataRequest marketDataRequest = new QuickFix.FIX43.MarketDataRequest(); QuickFix.Fields.SenderSubID senderSubId = new QuickFix.Fields.SenderSubID(this._senderSubId); marketDataRequest.SetField(senderSubId); QuickFix.Fields.DeliverToCompID deliverToCompId = new QuickFix.Fields.DeliverToCompID(this._deliverToCompId); marketDataRequest.SetField(deliverToCompId); QuickFix.Fields.NoRelatedSym noRelatedSym = new QuickFix.Fields.NoRelatedSym(1); marketDataRequest.SetField(noRelatedSym); QuickFix.Fields.MDReqID mdReqId = new QuickFix.Fields.MDReqID(id); marketDataRequest.SetField(mdReqId); QuickFix.Fields.SubscriptionRequestType subscriptionRequestType = new QuickFix.Fields.SubscriptionRequestType(subscriptionType); marketDataRequest.SetField(subscriptionRequestType); QuickFix.Fields.MarketDepth marketDepth = new QuickFix.Fields.MarketDepth(depth); marketDataRequest.SetField(marketDepth); QuickFix.Fields.MDUpdateType mdUpdateType = new QuickFix.Fields.MDUpdateType(MarketDataUpdateType.FullRefresh); marketDataRequest.SetField(mdUpdateType); // Indicates '2' requested fields i.e. OFFER/ASK and BID QuickFix.Fields.NoMDEntryTypes noMdEntryType = new QuickFix.Fields.NoMDEntryTypes(2); marketDataRequest.SetField(noMdEntryType); QuickFix.Fields.Symbol symbol = new QuickFix.Fields.Symbol(security.Symbol); QuickFix.Fields.Product product = new QuickFix.Fields.Product(Product.Currency); QuickFix.FIX43.MarketDataRequest.NoRelatedSymGroup relatedSymbols = new QuickFix.FIX43.MarketDataRequest.NoRelatedSymGroup(); relatedSymbols.SetField(symbol); relatedSymbols.SetField(product); marketDataRequest.AddGroup(relatedSymbols); QuickFix.FIX43.MarketDataRequest.NoMDEntryTypesGroup mdEntryTypes = new QuickFix.FIX43.MarketDataRequest.NoMDEntryTypesGroup(); { mdEntryTypes.SetField(new QuickFix.Fields.MDEntryType(MarketDataEntryType.Bid)); marketDataRequest.AddGroup(mdEntryTypes); mdEntryTypes.SetField(new QuickFix.Fields.MDEntryType(MarketDataEntryType.Offer)); marketDataRequest.AddGroup(mdEntryTypes); } return(marketDataRequest); }
/// <summary> /// Creates a FIX4.2 MarketDataRequest message. /// </summary> /// <param name="id"></param> /// <param name="security"></param> /// <param name="subscriptionType"></param> /// <param name="depth"></param> /// <returns></returns> public QuickFix.FIX42.MarketDataRequest MarketDataRequest(string id, Security security, char subscriptionType, int depth) { QuickFix.FIX42.MarketDataRequest marketDataRequest = new QuickFix.FIX42.MarketDataRequest(); QuickFix.Fields.SenderSubID senderSubId = new QuickFix.Fields.SenderSubID(this._senderSubId); marketDataRequest.SetField(senderSubId); QuickFix.Fields.DeliverToCompID deliverToCompId = new QuickFix.Fields.DeliverToCompID(this._deliverToCompId); marketDataRequest.SetField(deliverToCompId); QuickFix.Fields.NoRelatedSym noRelatedSym = new QuickFix.Fields.NoRelatedSym(1); marketDataRequest.SetField(noRelatedSym); QuickFix.Fields.MDReqID mdReqId = new QuickFix.Fields.MDReqID(id); marketDataRequest.SetField(mdReqId); QuickFix.Fields.SubscriptionRequestType subscriptionRequestType = new QuickFix.Fields.SubscriptionRequestType(subscriptionType); marketDataRequest.SetField(subscriptionRequestType); QuickFix.Fields.MarketDepth marketDepth = new QuickFix.Fields.MarketDepth(depth); marketDataRequest.SetField(marketDepth); QuickFix.Fields.MDUpdateType mdUpdateType = new QuickFix.Fields.MDUpdateType(MarketDataUpdateType.FullRefresh); marketDataRequest.SetField(mdUpdateType); QuickFix.Fields.NoMDEntryTypes noMdEntryType = new QuickFix.Fields.NoMDEntryTypes(2); marketDataRequest.SetField(noMdEntryType); QuickFix.Fields.AggregatedBook aggregatedBook = new QuickFix.Fields.AggregatedBook(true); marketDataRequest.SetField(aggregatedBook); QuickFix.Fields.Symbol symbol = new QuickFix.Fields.Symbol(security.Symbol); QuickFix.FIX42.MarketDataRequest.NoRelatedSymGroup relatedSymbols = new QuickFix.FIX42.MarketDataRequest.NoRelatedSymGroup(); relatedSymbols.SetField(symbol); marketDataRequest.AddGroup(relatedSymbols); QuickFix.FIX42.MarketDataRequest.NoMDEntryTypesGroup mdEntryTypes = new QuickFix.FIX42.MarketDataRequest.NoMDEntryTypesGroup(); { mdEntryTypes.SetField(new QuickFix.Fields.MDEntryType(MarketDataEntryType.Bid)); marketDataRequest.AddGroup(mdEntryTypes); mdEntryTypes.SetField(new QuickFix.Fields.MDEntryType(MarketDataEntryType.Offer)); marketDataRequest.AddGroup(mdEntryTypes); } return(marketDataRequest); }
public void Set(QuickFix.Fields.Symbol val) { this.Symbol = val; }
/// <summary> /// Helper Method to process data from message for updating positions /// </summary> /// <param name="message"></param> /// <param name="session"></param> private void posTableUpdate(QuickFix.FIX42.Message message, SessionID session) { string MGT = null; string acct = null; string SecEx = null; string symbol = null; string secID = null; string gateway = null; int tradesize = 0; char side = char.MinValue; decimal price = 0.00M; bool OK2Update = true; try { QuickFix.Fields.SenderSubID subID = new QuickFix.Fields.SenderSubID(); if (message.Header.IsSetField(subID)) { MGT = message.Header.GetField(subID).getValue(); } else { OK2Update = false; } QuickFix.Fields.Account a = new QuickFix.Fields.Account(); if (message.IsSetField(a)) { acct = message.GetField(a).getValue(); } else { OK2Update = false; } QuickFix.Fields.SecurityExchange se = new QuickFix.Fields.SecurityExchange(); if (message.IsSetField(se)) { SecEx = message.GetField(se).getValue(); } else { OK2Update = false; } QuickFix.Fields.Symbol s = new QuickFix.Fields.Symbol(); if (message.IsSetField(s)) { symbol = message.GetField(s).getValue(); } else { OK2Update = false; } QuickFix.Fields.SecurityID sid = new QuickFix.Fields.SecurityID(); if (message.IsSetField(sid)) { secID = message.GetField(sid).getValue(); } else { OK2Update = false; } QuickFix.Fields.ExchangeGateway eg = new Fields.ExchangeGateway(); if (message.IsSetField(eg)) { gateway = message.GetField(eg).getValue(); } else { OK2Update = false; } QuickFix.Fields.LastShares q = new QuickFix.Fields.LastShares(); if (message.IsSetField(q)) { tradesize = (int)message.GetField(q).getValue(); } QuickFix.Fields.Side bs = new QuickFix.Fields.Side(); if (message.IsSetField(bs)) { side = message.GetField(bs).getValue(); } else { if (tradesize < 0) { tradesize = Math.Abs(tradesize); side = QuickFix.Fields.Side.SELL; } else { side = QuickFix.Fields.Side.BUY; } } QuickFix.Fields.LastPx fill = new QuickFix.Fields.LastPx(); if (message.IsSetField(fill)) { price = message.GetField(fill).getValue(); } if (OK2Update) { //MGT, acct, SecEx, symbol, secID, tradesize, side, price, gateway updatePosition(MGT, acct, SecEx, symbol, secID, tradesize, side, price, gateway); } else { updateDisplay("Position not updated by following message"); ProcessMessage(message, session); } } catch (Exception ex) { updateDisplay("QuickFIX Error"); log.WriteLog("MGT: " + MGT); log.WriteLog("acct: " + acct); log.WriteLog("SecEx: " + SecEx); log.WriteLog("symbol: " + symbol); log.WriteLog("secID: " + secID); log.WriteLog("tradesize: " + tradesize.ToString()); log.WriteLog("side: " + side.ToString()); log.WriteLog("price: " + price.ToString()); log.WriteLog("gateway: " + gateway); log.WriteLog("Start Exception--------------------"); log.WriteLog("Source: " + ex.Source); log.WriteLog("Message: " + ex.Message); log.WriteLog("TargetSite: " + ex.TargetSite); log.WriteLog("InnerException: " + ex.InnerException); log.WriteLog("HelpLink: " + ex.HelpLink); log.WriteLog("Data: " + ex.Data); log.WriteLog("StackTrace: " + ex.StackTrace); log.WriteLog("Stop Exception details-------------"); } }
//receive contract parameters public void OnMessage(QuickFix.FIX42.SecurityDefinition message, QuickFix.SessionID session) { //parseMessage(message, session); string SecEx = null; string symbol = null; string secID = null; try { QuickFix.Fields.SecurityExchange se = new QuickFix.Fields.SecurityExchange(); if (message.IsSetField(se)) { SecEx = message.GetField(se).ToString(); } QuickFix.Fields.Symbol s = new QuickFix.Fields.Symbol(); if (message.IsSetField(s)) { symbol = message.GetField(s).ToString(); } QuickFix.Fields.SecurityID sid = new QuickFix.Fields.SecurityID(); if (message.IsSetField(sid)) { secID = message.GetField(sid).ToString(); } string cur = null; decimal exPtVal = 0.00M; QuickFix.Fields.ExchPointValue epv = new QuickFix.Fields.ExchPointValue(); if (message.IsSetField(epv)) { exPtVal = message.GetField(epv).getValue(); } QuickFix.Fields.Currency ccy = new QuickFix.Fields.Currency(); if (message.IsSetField(ccy)) { cur = message.GetField(ccy).getValue(); } updateSecurity(SecEx, symbol, secID, cur, exPtVal); } catch (Exception ex) { updateDisplay("QuickFIX Error"); log.WriteLog(ex.ToString()); } }
//Receive market data public void OnMessage(QuickFix.FIX42.MarketDataSnapshotFullRefresh message, SessionID session) { decimal _bidPrice = 0.00M; decimal _askPrice = 0.00M; try { QuickFix.Group noMDEntriesGrp = new QuickFix.FIX42.MarketDataSnapshotFullRefresh.NoMDEntriesGroup(); for (int grpIndex = 1; grpIndex <= message.GetInt(QuickFix.Fields.Tags.NoMDEntries); grpIndex += 1) { noMDEntriesGrp = message.GetGroup(grpIndex, QuickFix.Fields.Tags.NoMDEntries); if (noMDEntriesGrp.IsSetField(QuickFix.Fields.Tags.BidPx)) { _bidPrice = QuickFix.Fields.Converters.DecimalConverter.Convert(noMDEntriesGrp.GetField(QuickFix.Fields.Tags.BidPx)); } if (noMDEntriesGrp.IsSetField(QuickFix.Fields.Tags.OfferPx)) { _askPrice = QuickFix.Fields.Converters.DecimalConverter.Convert(noMDEntriesGrp.GetField(QuickFix.Fields.Tags.OfferPx)); } } string SecEx = null; string symbol = null; string secID = null; QuickFix.Fields.SecurityExchange se = new QuickFix.Fields.SecurityExchange(); if (message.IsSetField(se)) { SecEx = message.GetField(se).ToString(); } QuickFix.Fields.Symbol s = new QuickFix.Fields.Symbol(); if (message.IsSetField(s)) { symbol = message.GetField(s).ToString(); } QuickFix.Fields.SecurityID sid = new QuickFix.Fields.SecurityID(); if (message.IsSetField(sid)) { secID = message.GetField(sid).ToString(); } updatePrices(SecEx, symbol, secID, _bidPrice, _askPrice); } catch (Exception ex) { updateDisplay(string.Format("QuickFIX Error: {0}", System.Reflection.MethodBase.GetCurrentMethod().Name)); log.WriteLog(string.Format("{0} : {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString())); } }