public static MarketDataRequest MakeMarketDataRequest() { //let ms = System.DateTimeOffset.Now.ToUnixTimeMilliseconds() //let mdr = MkMarketDataRequest( // MDReqID(sprintf "MDRQ-%d" ms), // SubscriptionRequestType.SnapshotPlusUpdates, // MarketDepth 1, // [MDEntryType.Bid; MDEntryType.Offer] |> List.map MkNoMDEntryTypesGrp, // [MkInstrument(Fix44.Fields.Symbol "EUR/USD")] |> List.map MkMarketDataRequestNoRelatedSymGrp // ) var msg = new MarketDataRequest(); //var ms = System.DateTimeOffset.Now.ToUnixTimeMilliseconds(); var ms = 1489416392996; msg.MDReqID = new MDReqID($"MDRQ-{ms}"); msg.SubscriptionRequestType = new SubscriptionRequestType(SubscriptionRequestType.SNAPSHOT_PLUS_UPDATES); msg.MarketDepth = new MarketDepth(1); var entryTypesGroup = new MarketDataRequest.NoMDEntryTypesGroup(); entryTypesGroup.MDEntryType = new MDEntryType(MDEntryType.BID); msg.AddGroup(entryTypesGroup); entryTypesGroup.MDEntryType = new MDEntryType(MDEntryType.OFFER); msg.AddGroup(entryTypesGroup); var symGroup = new MarketDataRequest.NoRelatedSymGroup(); symGroup.Symbol = new Symbol("EUR/USD"); msg.AddGroup(symGroup); return(msg); }
public MarketDataRequest unsubscribeIncrementalRequest(string symbol) { MarketDataRequest tickerRequest = new MarketDataRequest(); MarketDataRequest.NoRelatedSymGroup symbolGroup = new MarketDataRequest.NoRelatedSymGroup(); symbolGroup.SetField(new Symbol(symbol)); tickerRequest.AddGroup(symbolGroup); tickerRequest.Set(new MDReqID("123")); tickerRequest.Set(new SubscriptionRequestType('2')); tickerRequest.Set(new MarketDepth(0)); addMDType(tickerRequest, '0'); addMDType(tickerRequest, '1'); addMDType(tickerRequest, '2'); addMDType(tickerRequest, '3'); addMDType(tickerRequest, '4'); addMDType(tickerRequest, '5'); addMDType(tickerRequest, '6'); addMDType(tickerRequest, '7'); addMDType(tickerRequest, '8'); addMDType(tickerRequest, '9'); addMDType(tickerRequest, 'A'); addMDType(tickerRequest, 'B'); addMDType(tickerRequest, 'C'); return(tickerRequest); }
private async Task Subscribe() { var request = new MarketDataRequest { MDReqID = new MDReqID(DateTime.UtcNow.Ticks.ToString()), SubscriptionRequestType = new SubscriptionRequestType(SubscriptionRequestType.SNAPSHOT_PLUS_UPDATES), MarketDepth = new MarketDepth(50), MDUpdateType = new MDUpdateType(MDUpdateType.FULL_REFRESH), NoMDEntryTypes = new NoMDEntryTypes(2), NoRelatedSym = new NoRelatedSym(_configuration.SupportedCurrencySymbols.Count) }; var bidGroup = new MarketDataRequest.NoMDEntryTypesGroup { MDEntryType = new MDEntryType(MDEntryType.BID) }; var askGroup = new MarketDataRequest.NoMDEntryTypesGroup { MDEntryType = new MDEntryType(MDEntryType.OFFER) }; foreach (var mapping in _configuration.SupportedCurrencySymbols) { var noRelatedSymGroup = new MarketDataRequest.NoRelatedSymGroup { Symbol = _modelConverter.ConvertLykkeSymbol(mapping.LykkeSymbol) }; request.AddGroup(noRelatedSymGroup); } request.AddGroup(bidGroup); request.AddGroup(askGroup); await Messenger.SendRequestAsync(request, CancellationToken); }
/// <summary> /// Creates and returns a new <see cref="MarketDataRequest"/> FIX message. /// </summary> /// <param name="symbol">The symbol.</param> /// <param name="marketDepth">The market depth.</param> /// <param name="timeNow">The time now.</param> /// <returns>The FIX message.</returns> public static MarketDataRequest Create(string symbol, int marketDepth, ZonedDateTime timeNow) { Debug.NotEmptyOrWhiteSpace(symbol, nameof(symbol)); Debug.NotNegativeInt32(marketDepth, nameof(marketDepth)); Debug.NotDefault(timeNow, nameof(timeNow)); var marketDataEntryGroup1 = new MarketDataRequest.NoMDEntryTypesGroup(); marketDataEntryGroup1.Set(new MDEntryType(MDEntryType.BID)); var marketDataEntryGroup2 = new MarketDataRequest.NoMDEntryTypesGroup(); marketDataEntryGroup2.Set(new MDEntryType(MDEntryType.OFFER)); var symbolGroup = new MarketDataRequest.NoRelatedSymGroup(); symbolGroup.SetField(new Symbol(symbol)); var message = new MarketDataRequest( new MDReqID($"MD_{timeNow.TickOfDay.ToString()}"), new SubscriptionRequestType(SubscriptionRequestType.SNAPSHOT_PLUS_UPDATES), new MarketDepth(marketDepth)); message.Set(new MDUpdateType(0)); // val:1 to receive shortened message message.AddGroup(marketDataEntryGroup1); message.AddGroup(marketDataEntryGroup2); message.Set(new NoRelatedSym(1)); message.AddGroup(symbolGroup); return(message); }
public string EnviarAssinaturaMarketDataConflated(string instrumento, string securityType, string product, string cfiCode) { string mdReqID = "MDREQ"; try { logger.InfoFormat("Requisitando snapshot MD Instrumento[{0}] Produto [{1}] Type [{2}] CFI[{3}]", instrumento, product, securityType, cfiCode); QuickFix.FIX44.MarketDataRequest mktDataReq = new MarketDataRequest(); if (!String.IsNullOrEmpty(instrumento)) { QuickFix.FIX44.MarketDataRequest.NoRelatedSymGroup noRelatedSym = new MarketDataRequest.NoRelatedSymGroup(); noRelatedSym.SecurityExchange = new QuickFix.Fields.SecurityExchange("BVMF"); noRelatedSym.SecurityIDSource = new QuickFix.Fields.SecurityIDSource("8"); noRelatedSym.SecurityID = new QuickFix.Fields.SecurityID(instrumento); mktDataReq.AddGroup(noRelatedSym); mdReqID += "-" + instrumento; } if (!String.IsNullOrEmpty(product) && !product.Equals("0")) { mktDataReq.Product = new QuickFix.Fields.Product(Convert.ToInt32(product)); mdReqID += "-" + product; } if (!String.IsNullOrEmpty(securityType)) { mktDataReq.SecurityType = new QuickFix.Fields.SecurityType(securityType); } if (!String.IsNullOrEmpty(cfiCode)) { mktDataReq.CFICode = new QuickFix.Fields.CFICode(cfiCode); } mdReqID += "-" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); mktDataReq.MDReqID = new QuickFix.Fields.MDReqID(mdReqID); mktDataReq.SubscriptionRequestType = new QuickFix.Fields.SubscriptionRequestType(QuickFix.Fields.SubscriptionRequestType.SNAPSHOT_PLUS_UPDATES); // Subscribe + update mktDataReq.MDBookType = new QuickFix.Fields.MDBookType(QuickFix.Fields.MDBookType.ORDER_DEPTH); //MBO Session.SendToTarget(mktDataReq, _session); } catch (Exception ex) { logger.Error("RequestMarketData: " + ex.Message, ex); } return(mdReqID); }
public async Task ShouldReceiveOrderBooks() { await _connector.ConnectAsync(CancellationToken.None); WaitForState(FixConnectorState.Connected, 30); var symbols = new[] { "USDCHF", "EURUSD" }; var request = new MarketDataRequest() { MDReqID = new MDReqID(DateTime.UtcNow.Ticks.ToString()), SubscriptionRequestType = new SubscriptionRequestType(SubscriptionRequestType.SNAPSHOT_PLUS_UPDATES), MarketDepth = new MarketDepth(50), MDUpdateType = new MDUpdateType(MDUpdateType.FULL_REFRESH), NoMDEntryTypes = new NoMDEntryTypes(2), NoRelatedSym = new NoRelatedSym(symbols.Length) }; var bidGroup = new MarketDataRequest.NoMDEntryTypesGroup { MDEntryType = new MDEntryType(MDEntryType.BID) }; var askGroup = new MarketDataRequest.NoMDEntryTypesGroup { MDEntryType = new MDEntryType(MDEntryType.OFFER) }; foreach (var symb in symbols) { var noRelatedSymGroup = new MarketDataRequest.NoRelatedSymGroup { Symbol = new Symbol(symb) }; request.AddGroup(noRelatedSymGroup); } request.AddGroup(bidGroup); request.AddGroup(askGroup); await _connector.SendRequestAsync(request, CancellationToken.None); for (int i = 0; i < symbols.Length; i++) { var resp = await _connector.GetResponseAsync(CancellationToken.None); if (resp is MarketDataSnapshotFullRefresh snapshot) { var symbol = snapshot.Symbol.Obj; for (int j = 1; j <= snapshot.NoMDEntries.Obj; j++) { var ob = resp.GetGroup(j, new MarketDataSnapshotFullRefresh.NoMDEntriesGroup()); var dir = ob.GetField(new MDEntryType()).Obj; var price = ob.GetField(new MDEntryPx()).Obj; var size = ob.GetField(new MDEntrySize()).Obj; await _output.WriteInfoAsync("", "", $"Sym:{symbol} side:{dir} price:{price} size:{size}"); } } } }
public void CancelarAssinaturaMarketDataConflated(string instrumento, string securityType, string product, string cfiCode, string mdReqID) { try { logger.InfoFormat("CancelandoAssinatura MD Instrumento[{0}] Produto [{1}] Type [{2}] CFI[{3}] ReqID[{4}]", instrumento, product, securityType, cfiCode, mdReqID); QuickFix.FIX44.MarketDataRequest mktDataReq = new MarketDataRequest(); if (!String.IsNullOrEmpty(instrumento)) { QuickFix.FIX44.MarketDataRequest.NoRelatedSymGroup noRelatedSym = new MarketDataRequest.NoRelatedSymGroup(); noRelatedSym.SecurityExchange = new QuickFix.Fields.SecurityExchange("BVMF"); noRelatedSym.SecurityIDSource = new QuickFix.Fields.SecurityIDSource("8"); noRelatedSym.SecurityID = new QuickFix.Fields.SecurityID(instrumento); mktDataReq.AddGroup(noRelatedSym); } if (!String.IsNullOrEmpty(product) && !product.Equals("0")) { mktDataReq.Product = new QuickFix.Fields.Product(Convert.ToInt32(product)); } if (!String.IsNullOrEmpty(securityType)) { mktDataReq.SecurityType = new QuickFix.Fields.SecurityType(securityType); } if (!String.IsNullOrEmpty(cfiCode)) { mktDataReq.CFICode = new QuickFix.Fields.CFICode(cfiCode); } mktDataReq.MDReqID = new QuickFix.Fields.MDReqID(mdReqID); mktDataReq.SubscriptionRequestType = new QuickFix.Fields.SubscriptionRequestType(QuickFix.Fields.SubscriptionRequestType.DISABLE_PREVIOUS); // Subscribe + update mktDataReq.MDBookType = new QuickFix.Fields.MDBookType(QuickFix.Fields.MDBookType.ORDER_DEPTH); //MBO Session.SendToTarget(mktDataReq, _session); } catch (Exception ex) { logger.Error("CancelarAssinaturaMarketDataConflated: " + ex.Message, ex); } }
public void Subscribe(string symbol, SessionID sessionId) { var marketDataRequest = new MarketDataRequest { MDReqID = new MDReqID(symbol), SubscriptionRequestType = new SubscriptionRequestType('1'), //incremental refresh MarketDepth = new MarketDepth(1), //yes market depth need MDUpdateType = new MDUpdateType(1) // }; var relatedSymbol = new MarketDataRequest.NoRelatedSymGroup { Symbol = new Symbol(symbol) }; marketDataRequest.AddGroup(relatedSymbol); var noMdEntryTypes = new MarketDataRequest.NoMDEntryTypesGroup(); var mdEntryTypeBid = new MDEntryType('0'); noMdEntryTypes.MDEntryType = mdEntryTypeBid; marketDataRequest.AddGroup(noMdEntryTypes); noMdEntryTypes = new MarketDataRequest.NoMDEntryTypesGroup(); var mdEntryTypeOffer = new MDEntryType('1'); noMdEntryTypes.MDEntryType = mdEntryTypeOffer; marketDataRequest.AddGroup(noMdEntryTypes); //Send message Session.SendToTarget(marketDataRequest, sessionId); }
public MarketDataRequest unsubscribeIncrementalRequest(string symbol) { MarketDataRequest tickerRequest = new MarketDataRequest(); MarketDataRequest.NoRelatedSymGroup symbolGroup = new MarketDataRequest.NoRelatedSymGroup(); symbolGroup.SetField(new Symbol(symbol)); tickerRequest.AddGroup(symbolGroup); tickerRequest.Set(new MDReqID("123")); tickerRequest.Set(new SubscriptionRequestType('2')); tickerRequest.Set(new MarketDepth(0)); addMDType(tickerRequest, '0'); addMDType(tickerRequest, '1'); addMDType(tickerRequest, '2'); addMDType(tickerRequest, '3'); addMDType(tickerRequest, '4'); addMDType(tickerRequest, '5'); addMDType(tickerRequest, '6'); addMDType(tickerRequest, '7'); addMDType(tickerRequest, '8'); addMDType(tickerRequest, '9'); addMDType(tickerRequest, 'A'); addMDType(tickerRequest, 'B'); addMDType(tickerRequest, 'C'); return tickerRequest; }
internal void Run() { Initiator.Start(); var settings = this.settings; bool isExiting = false; while (!isExiting) { Console.Write("> "); var key = Console.ReadKey(false); Console.WriteLine(); try { bool unhandled = false; switch (key.Key) { case ConsoleKey.Q: Console.WriteLine("Exiting"); isExiting = true; break; case ConsoleKey.H: Console.WriteLine("Help: "); break; case ConsoleKey.L: var logon = new Logon(); logon.Username = new Username(settings.Account); logon.Password = new Password(settings.Password); Session.SendToTarget(logon); //SendMessage(logon); break; case ConsoleKey.F1: Console.WriteLine("Initiator.IsLoggedOn: " + Initiator.IsLoggedOn); Console.WriteLine("Initiator.IsStopped: " + Initiator.IsStopped); //Console.WriteLine("Session: " + (_session != null)); Console.WriteLine("Logged on: " + _session?.IsLoggedOn); break; //case ConsoleKey.H: // break; default: unhandled = true; break; } if (unhandled) { switch (key.KeyChar) { case '=': { Console.Write(" Subscribe to: "); string symbol = Console.ReadLine(); Console.WriteLine("Subscribing to " + symbol); var mdr = new MarketDataRequest(new MDReqID(symbol), new SubscriptionRequestType(SubscriptionRequestType.SNAPSHOT_PLUS_UPDATES), new MarketDepth(0)); mdr.MDUpdateType = new MDUpdateType(MDUpdateType.INCREMENTAL_REFRESH); var sym = new MarketDataRequest.NoRelatedSymGroup(); sym.Symbol = new Symbol("1"); mdr.AddGroup(sym); mdr.NoMDEntryTypes = new NoMDEntryTypes(2); mdr.AddGroup(new MarketDataRequest.NoMDEntryTypesGroup() { MDEntryType = new MDEntryType(MDEntryType.BID) }); mdr.AddGroup(new MarketDataRequest.NoMDEntryTypesGroup() { MDEntryType = new MDEntryType(MDEntryType.OFFER) }); //message.SetField(new MDEntryType(MDEntryType.BID), false); // 269 //message.SetField(new MDEntryType(MDEntryType.OFFER), false); // 269 //message.SetField(new NoMDEntryTypes(1)); // 267 Should be 2 TODO //message.SetField(new Symbol("EUR/USD")); // 55 //message.SetField(new NoRelatedSym(1)); // 146 SendMessage(mdr); break; } case '-': { Console.Write(" Unubscribe to: "); string symbol = Console.ReadLine(); Console.WriteLine("Unubscribing to " + symbol); break; } default: break; } } } catch (Exception ex) { Console.WriteLine(); Console.WriteLine(ex.ToString()); Console.WriteLine(); } } Initiator.Stop(); }
static void Main(string[] args) { TestFixApp testFixApp = new TestFixApp(args.FirstOrDefault()); testFixApp.Start(); Account account = new Account("54b97c9e-202b-11b2-be90-529049f1f1bb"); ClOrdID clOrdId = new ClOrdID(Guid.NewGuid().ToString()); Symbol symbol = new Symbol("BTC/USD"); Side side = new Side(Side.BUY); #region SecurityListRequest SecurityListRequest securityListRequest = new SecurityListRequest( new SecurityReqID(Guid.NewGuid().ToString()), new SecurityListRequestType(SecurityListRequestType.SYMBOL) ) { Symbol = symbol }; Console.WriteLine("Press enter to next comand"); Console.ReadLine(); testFixApp.Send(securityListRequest); testFixApp.WaitResponces(1); #endregion SecurityListRequest #region MarketDataRequest MarketDataRequest marketDataRequest = new MarketDataRequest( new MDReqID(Guid.NewGuid().ToString()), new SubscriptionRequestType(SubscriptionRequestType.SNAPSHOT), new MarketDepth(5)) { MDUpdateType = new MDUpdateType(MDUpdateType.FULL_REFRESH), }; var bid = new MarketDataRequest.NoMDEntryTypesGroup() { MDEntryType = new MDEntryType(MDEntryType.BID) }; var ask = new MarketDataRequest.NoMDEntryTypesGroup() { MDEntryType = new MDEntryType(MDEntryType.OFFER) }; var symGroup = new MarketDataRequest.NoRelatedSymGroup { Symbol = symbol }; marketDataRequest.AddGroup(bid); marketDataRequest.AddGroup(ask); marketDataRequest.AddGroup(symGroup); Console.WriteLine("Press enter to next comand"); Console.ReadLine(); testFixApp.Send(marketDataRequest); testFixApp.WaitResponces(1); #endregion MarketDataRequest #region NewOrderSingle NewOrderSingle newOrderSingle = new NewOrderSingle( clOrdId, symbol, side, new TransactTime(DateTime.Now), new OrdType(OrdType.LIMIT)) { OrderQty = new OrderQty(0.1m), Price = new Price(1m), Account = account, AcctIDSource = new AcctIDSource(AcctIDSource.OTHER) }; Console.WriteLine("Press enter to next comand"); Console.ReadLine(); testFixApp.Send(newOrderSingle); testFixApp.WaitResponces(2); #endregion NewOrderSingle #region OrderCancelReplaceRequest OrderCancelReplaceRequest orderCancelReplaceRequest = new OrderCancelReplaceRequest( new OrigClOrdID(clOrdId.ToString()), clOrdId = new ClOrdID(Guid.NewGuid().ToString()), symbol, side, new TransactTime(DateTime.Now), new OrdType(OrdType.LIMIT)) { Price = new Price(2m), OrderQty = new OrderQty(0.2m) }; Console.WriteLine("Press enter to next comand"); Console.ReadLine(); testFixApp.Send(orderCancelReplaceRequest); testFixApp.WaitResponces(2); #endregion OrderCancelReplaceRequest #region OrderStatusRequest OrderStatusRequest orderStatusRequest = new OrderStatusRequest( clOrdId, symbol, side ); Console.WriteLine("Press enter to next comand"); Console.ReadLine(); testFixApp.Send(orderStatusRequest); testFixApp.WaitResponces(1); #endregion OrderStatusRequest #region OrderCancelRequest OrderCancelRequest orderCancelRequest = new OrderCancelRequest( new OrigClOrdID(clOrdId.ToString()), new ClOrdID(Guid.NewGuid().ToString()), symbol, side, new TransactTime(DateTime.Now) ) { OrderQty = new OrderQty(0.1m) }; Console.WriteLine("Press enter to next comand"); Console.ReadLine(); testFixApp.Send(orderCancelRequest); testFixApp.WaitResponces(3); #endregion region OrderCancelRequest #region OrderMassStatusRequest OrderMassStatusRequest orderMassStatusRequest = new OrderMassStatusRequest( new MassStatusReqID(Guid.NewGuid().ToString()), new MassStatusReqType(MassStatusReqType.STATUS_FOR_ALL_ORDERS)) { Side = side, Symbol = symbol }; Console.WriteLine("Press enter to next comand"); Console.ReadLine(); testFixApp.Send(orderMassStatusRequest); #endregion OrderMassStatusRequest Console.WriteLine("Press enter to exit"); Console.ReadLine(); testFixApp.Stop(); }