From 38f05ff89a105437bc0f71e4b5e180927e987709 Mon Sep 17 00:00:00 2001 From: Grant Birchmeier Date: Wed, 25 Sep 2024 17:02:19 -0500 Subject: [PATCH] fix deprecations, fix nullable-enables --- Examples/Executor/Examples.Executor.csproj | 1 + Examples/Executor/Executor.cs | 65 +++++++------ Examples/Executor/Program.cs | 4 - .../Examples.SimpleAcceptor.csproj | 1 + Examples/SimpleAcceptor/Program.cs | 4 - Examples/SimpleAcceptor/SimpleAcceptorApp.cs | 10 +- .../TradeClient/Examples.TradeClient.csproj | 1 + Examples/TradeClient/Program.cs | 5 +- Examples/TradeClient/TradeClientApp.cs | 93 +++++++++++-------- RELEASE_NOTES.md | 1 + 10 files changed, 90 insertions(+), 95 deletions(-) diff --git a/Examples/Executor/Examples.Executor.csproj b/Examples/Executor/Examples.Executor.csproj index 43e1aa2d5..0ece262ad 100644 --- a/Examples/Executor/Examples.Executor.csproj +++ b/Examples/Executor/Examples.Executor.csproj @@ -3,6 +3,7 @@ Exe net8.0 + enable Executor Executor Copyright © Connamara Systems, LLC 2011 diff --git a/Examples/Executor/Executor.cs b/Examples/Executor/Executor.cs index 8e0a0b739..6e4ec5c27 100644 --- a/Examples/Executor/Executor.cs +++ b/Examples/Executor/Executor.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using QuickFix; using QuickFix.Fields; @@ -48,7 +45,7 @@ public void OnMessage(QuickFix.FIX40.NewOrderSingle n, SessionID s) Price price = new Price(DEFAULT_MARKET_PRICE); ClOrdID clOrdID = n.ClOrdID; - switch (ordType.getValue()) + switch (ordType.Value) { case OrdType.LIMIT: price = n.Price; @@ -67,10 +64,10 @@ public void OnMessage(QuickFix.FIX40.NewOrderSingle n, SessionID s) symbol, side, orderQty, - new LastShares(orderQty.getValue()), - new LastPx(price.getValue()), - new CumQty(orderQty.getValue()), - new AvgPx(price.getValue())); + new LastShares(orderQty.Value), + new LastPx(price.Value), + new CumQty(orderQty.Value), + new AvgPx(price.Value)); exReport.Set(clOrdID); @@ -101,7 +98,7 @@ public void OnMessage(QuickFix.FIX41.NewOrderSingle n, SessionID s) Price price = new Price(DEFAULT_MARKET_PRICE); ClOrdID clOrdID = n.ClOrdID; - switch (ordType.getValue()) + switch (ordType.Value) { case OrdType.LIMIT: price = n.Price; @@ -121,11 +118,11 @@ public void OnMessage(QuickFix.FIX41.NewOrderSingle n, SessionID s) symbol, side, orderQty, - new LastShares(orderQty.getValue()), - new LastPx(price.getValue()), + new LastShares(orderQty.Value), + new LastPx(price.Value), new LeavesQty(0), - new CumQty(orderQty.getValue()), - new AvgPx(price.getValue())); + new CumQty(orderQty.Value), + new AvgPx(price.Value)); exReport.Set(clOrdID); @@ -156,7 +153,7 @@ public void OnMessage(QuickFix.FIX42.NewOrderSingle n, SessionID s) ClOrdID clOrdID = n.ClOrdID; Price price = new Price(DEFAULT_MARKET_PRICE); - switch (ordType.getValue()) + switch (ordType.Value) { case OrdType.LIMIT: price = n.Price; @@ -176,13 +173,13 @@ public void OnMessage(QuickFix.FIX42.NewOrderSingle n, SessionID s) symbol, side, new LeavesQty(0), - new CumQty(orderQty.getValue()), - new AvgPx(price.getValue())); + new CumQty(orderQty.Value), + new AvgPx(price.Value)); exReport.Set(clOrdID); exReport.Set(orderQty); - exReport.Set(new LastShares(orderQty.getValue())); - exReport.Set(new LastPx(price.getValue())); + exReport.Set(new LastShares(orderQty.Value)); + exReport.Set(new LastPx(price.Value)); if (n.IsSetAccount()) exReport.SetField(n.Account); @@ -211,7 +208,7 @@ public void OnMessage(QuickFix.FIX43.NewOrderSingle n, SessionID s) Price price = new Price(DEFAULT_MARKET_PRICE); ClOrdID clOrdID = n.ClOrdID; - switch (ordType.getValue()) + switch (ordType.Value) { case OrdType.LIMIT: price = n.Price; @@ -230,14 +227,14 @@ public void OnMessage(QuickFix.FIX43.NewOrderSingle n, SessionID s) symbol, // Shouldn't be here? side, new LeavesQty(0), - new CumQty(orderQty.getValue()), - new AvgPx(price.getValue())); + new CumQty(orderQty.Value), + new AvgPx(price.Value)); exReport.Set(clOrdID); exReport.Set(symbol); exReport.Set(orderQty); - exReport.Set(new LastQty(orderQty.getValue())); - exReport.Set(new LastPx(price.getValue())); + exReport.Set(new LastQty(orderQty.Value)); + exReport.Set(new LastPx(price.Value)); if (n.IsSetAccount()) exReport.SetField(n.Account); @@ -266,7 +263,7 @@ public void OnMessage(QuickFix.FIX44.NewOrderSingle n, SessionID s) Price price = new Price(DEFAULT_MARKET_PRICE); ClOrdID clOrdID = n.ClOrdID; - switch (ordType.getValue()) + switch (ordType.Value) { case OrdType.LIMIT: price = n.Price; @@ -285,14 +282,14 @@ public void OnMessage(QuickFix.FIX44.NewOrderSingle n, SessionID s) symbol, //shouldn't be here? side, new LeavesQty(0), - new CumQty(orderQty.getValue()), - new AvgPx(price.getValue())); + new CumQty(orderQty.Value), + new AvgPx(price.Value)); exReport.Set(clOrdID); exReport.Set(symbol); exReport.Set(orderQty); - exReport.Set(new LastQty(orderQty.getValue())); - exReport.Set(new LastPx(price.getValue())); + exReport.Set(new LastQty(orderQty.Value)); + exReport.Set(new LastPx(price.Value)); if (n.IsSetAccount()) exReport.SetField(n.Account); @@ -321,7 +318,7 @@ public void OnMessage(QuickFix.FIX50.NewOrderSingle n, SessionID s) Price price = new Price(DEFAULT_MARKET_PRICE); ClOrdID clOrdID = n.ClOrdID; - switch (ordType.getValue()) + switch (ordType.Value) { case OrdType.LIMIT: price = n.Price; @@ -339,14 +336,14 @@ public void OnMessage(QuickFix.FIX50.NewOrderSingle n, SessionID s) new OrdStatus(OrdStatus.FILLED), side, new LeavesQty(0), - new CumQty(orderQty.getValue())); + new CumQty(orderQty.Value)); exReport.Set(clOrdID); exReport.Set(symbol); exReport.Set(orderQty); - exReport.Set(new LastQty(orderQty.getValue())); - exReport.Set(new LastPx(price.getValue())); - exReport.Set(new AvgPx(price.getValue())); + exReport.Set(new LastQty(orderQty.Value)); + exReport.Set(new LastPx(price.Value)); + exReport.Set(new AvgPx(price.Value)); if (n.IsSetAccount()) exReport.SetField(n.Account); @@ -601,4 +598,4 @@ public void OnMessage(QuickFix.FIX50.BusinessMessageReject n, SessionID s) { } #endregion //MessageCracker overloads } -} \ No newline at end of file +} diff --git a/Examples/Executor/Program.cs b/Examples/Executor/Program.cs index 1811b10d5..ab7583496 100644 --- a/Examples/Executor/Program.cs +++ b/Examples/Executor/Program.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.ConstrainedExecution; -using System.Text; using QuickFix; using QuickFix.Logger; using QuickFix.Store; diff --git a/Examples/SimpleAcceptor/Examples.SimpleAcceptor.csproj b/Examples/SimpleAcceptor/Examples.SimpleAcceptor.csproj index 4e8e6b64e..fc954a4b0 100644 --- a/Examples/SimpleAcceptor/Examples.SimpleAcceptor.csproj +++ b/Examples/SimpleAcceptor/Examples.SimpleAcceptor.csproj @@ -3,6 +3,7 @@ Exe net8.0 + enable SimpleAcceptor SimpleAcceptor Copyright © Connamara Systems, LLC 2011 diff --git a/Examples/SimpleAcceptor/Program.cs b/Examples/SimpleAcceptor/Program.cs index e880f4bfb..136b637bb 100644 --- a/Examples/SimpleAcceptor/Program.cs +++ b/Examples/SimpleAcceptor/Program.cs @@ -1,11 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using QuickFix; using QuickFix.Logger; using QuickFix.Store; -using QuickFix.Transport; namespace SimpleAcceptor { diff --git a/Examples/SimpleAcceptor/SimpleAcceptorApp.cs b/Examples/SimpleAcceptor/SimpleAcceptorApp.cs index ab21ac0dc..a5249d98b 100644 --- a/Examples/SimpleAcceptor/SimpleAcceptorApp.cs +++ b/Examples/SimpleAcceptor/SimpleAcceptorApp.cs @@ -1,10 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - using QuickFix; -using QuickFix.Fields; namespace SimpleAcceptor { @@ -16,8 +11,6 @@ namespace SimpleAcceptor public class SimpleAcceptorApp : /*QuickFix.MessageCracker,*/ QuickFix.IApplication { - #region QuickFix.Application Methods - public void FromApp(Message message, SessionID sessionID) { Console.WriteLine("IN: " + message); @@ -42,6 +35,5 @@ public void ToAdmin(Message message, SessionID sessionID) public void OnCreate(SessionID sessionID) { } public void OnLogout(SessionID sessionID) { } public void OnLogon(SessionID sessionID) { } - #endregion } -} \ No newline at end of file +} diff --git a/Examples/TradeClient/Examples.TradeClient.csproj b/Examples/TradeClient/Examples.TradeClient.csproj index d5b28cc94..738994695 100644 --- a/Examples/TradeClient/Examples.TradeClient.csproj +++ b/Examples/TradeClient/Examples.TradeClient.csproj @@ -3,6 +3,7 @@ Exe net8.0 + enable TradeClient TradeClient Copyright © Connamara Systems, LLC 2011 diff --git a/Examples/TradeClient/Program.cs b/Examples/TradeClient/Program.cs index f991f5382..b40e1913c 100644 --- a/Examples/TradeClient/Program.cs +++ b/Examples/TradeClient/Program.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using QuickFix.Logger; using QuickFix.Store; @@ -45,7 +42,7 @@ static void Main(string[] args) application.Run(); initiator.Stop(); } - catch (System.Exception e) + catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); diff --git a/Examples/TradeClient/TradeClientApp.cs b/Examples/TradeClient/TradeClientApp.cs index 5b9ffa50c..5a41fff27 100644 --- a/Examples/TradeClient/TradeClientApp.cs +++ b/Examples/TradeClient/TradeClientApp.cs @@ -2,35 +2,39 @@ using QuickFix; using QuickFix.Fields; using System.Collections.Generic; +using ApplicationException = System.ApplicationException; +using Exception = System.Exception; namespace TradeClient { public class TradeClientApp : QuickFix.MessageCracker, QuickFix.IApplication { - Session _session = null; + private Session? _session = null; // This variable is a kludge for developer test purposes. Don't do this on a production application. - public IInitiator MyInitiator = null; + public IInitiator? MyInitiator = null; #region IApplication interface overrides - public void OnCreate(SessionID sessionID) + public void OnCreate(SessionID sessionId) { - _session = Session.LookupSession(sessionID); + _session = Session.LookupSession(sessionId); + if (_session is null) + throw new ApplicationException("Somehow session is not found"); } - public void OnLogon(SessionID sessionID) { Console.WriteLine("Logon - " + sessionID.ToString()); } - public void OnLogout(SessionID sessionID) { Console.WriteLine("Logout - " + sessionID.ToString()); } + public void OnLogon(SessionID sessionId) { Console.WriteLine("Logon - " + sessionId); } + public void OnLogout(SessionID sessionId) { Console.WriteLine("Logout - " + sessionId); } - public void FromAdmin(Message message, SessionID sessionID) { } - public void ToAdmin(Message message, SessionID sessionID) { } + public void FromAdmin(Message message, SessionID sessionId) { } + public void ToAdmin(Message message, SessionID sessionId) { } - public void FromApp(Message message, SessionID sessionID) + public void FromApp(Message message, SessionID sessionId) { Console.WriteLine("IN: " + message.ConstructString()); try { - Crack(message, sessionID); + Crack(message, sessionId); } catch (Exception ex) { @@ -40,15 +44,14 @@ public void FromApp(Message message, SessionID sessionID) } } - public void ToApp(Message message, SessionID sessionID) + public void ToApp(Message message, SessionID sessionId) { try { bool possDupFlag = false; - if (message.Header.IsSetField(QuickFix.Fields.Tags.PossDupFlag)) + if (message.Header.IsSetField(Tags.PossDupFlag)) { - possDupFlag = QuickFix.Fields.Converters.BoolConverter.Convert( - message.Header.GetString(QuickFix.Fields.Tags.PossDupFlag)); /// FIXME + possDupFlag = message.Header.GetBoolean(Tags.PossDupFlag); } if (possDupFlag) throw new DoNotSend(); @@ -77,6 +80,9 @@ public void OnMessage(QuickFix.FIX44.OrderCancelReject m, SessionID s) public void Run() { + if (this.MyInitiator is null) + throw new ApplicationException("Somehow this.MyInitiator is not set"); + while (true) { try @@ -113,7 +119,7 @@ public void Run() else if (action == 'q' || action == 'Q') break; } - catch (System.Exception e) + catch (Exception e) { Console.WriteLine("Message Not Sent: " + e.Message); Console.WriteLine("StackTrace: " + e.StackTrace); @@ -124,7 +130,7 @@ public void Run() private void SendMessage(Message m) { - if (_session != null) + if (_session is not null) _session.Send(m); else { @@ -133,6 +139,13 @@ private void SendMessage(Message m) } } + private static string ReadCommand() { + string? inp = Console.ReadLine(); + if (inp is null) + throw new ApplicationException("Input no longer available"); + return inp.Trim(); + } + private char QueryAction() { // Commands 'g' and 'x' are intentionally hidden. @@ -147,7 +160,7 @@ private char QueryAction() HashSet validActions = new HashSet("1,2,3,4,q,Q,g,x".Split(',')); - string cmd = Console.ReadLine().Trim(); + string cmd = ReadCommand(); if (cmd.Length != 1 || validActions.Contains(cmd) == false) throw new System.Exception("Invalid action"); @@ -160,7 +173,7 @@ private void QueryEnterOrder() QuickFix.FIX44.NewOrderSingle m = QueryNewOrderSingle44(); - if (m != null && QueryConfirm("Send order")) + if (m is not null && QueryConfirm("Send order")) { m.Header.GetString(Tags.BeginString); @@ -194,7 +207,7 @@ private void QueryMarketDataRequest() QuickFix.FIX44.MarketDataRequest m = QueryMarketDataRequest44(); - if (m != null && QueryConfirm("Send market data request")) + if (QueryConfirm("Send market data request")) SendMessage(m); } @@ -202,28 +215,28 @@ private bool QueryConfirm(string query) { Console.WriteLine(); Console.WriteLine(query + "?: "); - string line = Console.ReadLine().Trim(); + string line = ReadCommand(); return (line[0].Equals('y') || line[0].Equals('Y')); } #region Message creation functions private QuickFix.FIX44.NewOrderSingle QueryNewOrderSingle44() { - QuickFix.Fields.OrdType ordType = null; + OrdType ordType = QueryOrdType(); QuickFix.FIX44.NewOrderSingle newOrderSingle = new QuickFix.FIX44.NewOrderSingle( - QueryClOrdID(), + QueryClOrdId(), QuerySymbol(), QuerySide(), new TransactTime(DateTime.Now), - ordType = QueryOrdType()); + ordType); newOrderSingle.Set(new HandlInst('1')); newOrderSingle.Set(QueryOrderQty()); newOrderSingle.Set(QueryTimeInForce()); - if (ordType.getValue() == OrdType.LIMIT || ordType.getValue() == OrdType.STOP_LIMIT) + if (ordType.Value == OrdType.LIMIT || ordType.Value == OrdType.STOP_LIMIT) newOrderSingle.Set(QueryPrice()); - if (ordType.getValue() == OrdType.STOP || ordType.getValue() == OrdType.STOP_LIMIT) + if (ordType.Value == OrdType.STOP || ordType.Value == OrdType.STOP_LIMIT) newOrderSingle.Set(QueryStopPx()); return newOrderSingle; @@ -232,8 +245,8 @@ private QuickFix.FIX44.NewOrderSingle QueryNewOrderSingle44() private QuickFix.FIX44.OrderCancelRequest QueryOrderCancelRequest44() { QuickFix.FIX44.OrderCancelRequest orderCancelRequest = new QuickFix.FIX44.OrderCancelRequest( - QueryOrigClOrdID(), - QueryClOrdID(), + QueryOrigClOrdId(), + QueryClOrdId(), QuerySymbol(), QuerySide(), new TransactTime(DateTime.Now)); @@ -245,8 +258,8 @@ private QuickFix.FIX44.OrderCancelRequest QueryOrderCancelRequest44() private QuickFix.FIX44.OrderCancelReplaceRequest QueryCancelReplaceRequest44() { QuickFix.FIX44.OrderCancelReplaceRequest ocrr = new QuickFix.FIX44.OrderCancelReplaceRequest( - QueryOrigClOrdID(), - QueryClOrdID(), + QueryOrigClOrdId(), + QueryClOrdId(), QuerySymbol(), QuerySide(), new TransactTime(DateTime.Now), @@ -282,25 +295,25 @@ private QuickFix.FIX44.MarketDataRequest QueryMarketDataRequest44() #endregion #region field query private methods - private ClOrdID QueryClOrdID() + private ClOrdID QueryClOrdId() { Console.WriteLine(); Console.Write("ClOrdID? "); - return new ClOrdID(Console.ReadLine().Trim()); + return new ClOrdID(ReadCommand()); } - private OrigClOrdID QueryOrigClOrdID() + private OrigClOrdID QueryOrigClOrdId() { Console.WriteLine(); Console.Write("OrigClOrdID? "); - return new OrigClOrdID(Console.ReadLine().Trim()); + return new OrigClOrdID(ReadCommand()); } private Symbol QuerySymbol() { Console.WriteLine(); Console.Write("Symbol? "); - return new Symbol(Console.ReadLine().Trim()); + return new Symbol(ReadCommand()); } private Side QuerySide() @@ -314,7 +327,7 @@ private Side QuerySide() Console.WriteLine("6) Cross Short"); Console.WriteLine("7) Cross Short Exempt"); Console.Write("Side? "); - string s = Console.ReadLine().Trim(); + string s = ReadCommand(); char c = ' '; switch (s) @@ -339,7 +352,7 @@ private OrdType QueryOrdType() Console.WriteLine("3) Stop"); Console.WriteLine("4) Stop Limit"); Console.Write("OrdType? "); - string s = Console.ReadLine().Trim(); + string s = ReadCommand(); char c = ' '; switch (s) @@ -357,7 +370,7 @@ private OrderQty QueryOrderQty() { Console.WriteLine(); Console.Write("OrderQty? "); - return new OrderQty(Convert.ToDecimal(Console.ReadLine().Trim())); + return new OrderQty(Convert.ToDecimal(ReadCommand())); } private TimeInForce QueryTimeInForce() @@ -369,7 +382,7 @@ private TimeInForce QueryTimeInForce() Console.WriteLine("4) GTC"); Console.WriteLine("5) GTX"); Console.Write("TimeInForce? "); - string s = Console.ReadLine().Trim(); + string s = ReadCommand(); char c = ' '; switch (s) @@ -388,14 +401,14 @@ private Price QueryPrice() { Console.WriteLine(); Console.Write("Price? "); - return new Price(Convert.ToDecimal(Console.ReadLine().Trim())); + return new Price(Convert.ToDecimal(ReadCommand())); } private StopPx QueryStopPx() { Console.WriteLine(); Console.Write("StopPx? "); - return new StopPx(Convert.ToDecimal(Console.ReadLine().Trim())); + return new StopPx(Convert.ToDecimal(ReadCommand())); } #endregion diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 10b98bbb9..438749c53 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -39,6 +39,7 @@ What's New * deprecate lower-case-starting function names (renamed to upper-case-starting) * deprecate Field.Obj (renamed to Value) * deprecate Field.getValue/setValue (just use Value getter/setter) +* #889 - nullable-ize Examples and fix deprecations (gbirchmeier) ### v1.12.0