private static bool TryParseTaggedStringParam(string tag, string paramTagString, string paramString, InputParam <string> param) { if (!paramTagString.Equals(tag)) { return(false); } param.Value = paramString; return(true); }
private static bool TryParseDateTimeParam(string stringParam, InputParam <DateTime?> param) { DateTime dateTimeValue; if (!DateTime.TryParse(stringParam, out dateTimeValue)) { return(false); } param.Value = dateTimeValue; return(true); }
private static bool TryParseRecordsPrintLimitParam(string paramTagString, string paramString, InputParam <int> param) { if (!paramTagString.Equals("-l")) { return(false); } int newRecordsPrintLimit; if (!int.TryParse(paramString, out newRecordsPrintLimit)) { return(false); } param.Value = newRecordsPrintLimit; return(true); }
private static void Main(string[] args) { if (args.Length < 3 || args.Length > 9) { ShowUsage(); return; } var address = args[HostIndex]; var symbol = args[SymbolIndex]; var source = new InputParam <string>(OrderSource.NTV.Name); var dateTime = new InputParam <DateTime?>(null); var recordsPrintLimit = new InputParam <int>(DefaultRecordsPrintLimit); var token = new InputParam <string>(null); var logDataTransferFlag = false; for (var i = SymbolIndex + 1; i < args.Length; i++) { if (!dateTime.IsSet && TryParseDateTimeParam(args[i], dateTime)) { continue; } if (!recordsPrintLimit.IsSet && i < args.Length - 1 && TryParseRecordsPrintLimitParam(args[i], args[i + 1], recordsPrintLimit)) { i++; continue; } if (!token.IsSet && i < args.Length - 1 && TryParseTaggedStringParam("-T", args[i], args[i + 1], token)) { i++; continue; } if (logDataTransferFlag == false && args[i].Equals("-p")) { logDataTransferFlag = true; i++; continue; } if (!source.IsSet) { source.Value = args[i]; } } Console.WriteLine( $"Connecting to {address} for [Order#{source.Value} (book)] on [{symbol}] ..."); using (var con = token.IsSet ? new NativeConnection(address, token.Value, DisconnectHandler, ConnectionStatusChangeHandler) : new NativeConnection(address, DisconnectHandler, ConnectionStatusChangeHandler)) { IDxSubscription s = null; try { NativeTools.InitializeLogging("dxf_simple_order_book_sample.log", true, true, logDataTransferFlag); s = con.CreateSnapshotSubscription(EventType.Order, dateTime.Value, new OrderListener(recordsPrintLimit.Value)); s.SetSource(source.Value); s.AddSymbols(symbol); Console.WriteLine("Press enter to stop"); Console.ReadLine(); } catch (DxException dxException) { Console.WriteLine($"Native exception occured: {dxException.Message}"); } catch (Exception exc) { Console.WriteLine($"Exception occured: {exc.Message}"); } finally { s?.Dispose(); } } }