public static void Write(IWrite write,string filename,object value) { using (FileStream fs = new FileStream(filename, FileMode.Create)) { write.Write(fs, value); } }
private void CleanupAndExit(IWrite iWrite, string cmdName, object[] cmdArguments) { // chance to clean some things before exiting // flag to break out of the loop forever ExitFlag = true; }
/// <summary> /// 发送结果 /// </summary> /// <param name="result"></param> /// <returns></returns> protected virtual async Task SendResult(Result result) { if (IWrite != null) { Task <int> WSend() { IWrite.Write(2500); IWrite.Write(result.Id); if (result.IsError) { IWrite.Write(true); IWrite.Write(result.ErrorId); IWrite.Write(result.ErrorMsg); } else { IWrite.Write(false); IWrite.Write(result.Arguments.Count); foreach (var item in result.Arguments) { IWrite.Write(item); } } return(IWrite.Flush()); } await await IWrite.Sync.Ask(WSend); } else { throw new NullReferenceException("IWrite is null!"); } }
/// <summary> /// 发送结果 /// </summary> /// <param name="result"></param> /// <returns></returns> protected virtual async Task SendResult(long id, byte[][] arguments = null) { if (IWrite != null) { Task <int> WSend() { IWrite.Write(2500); IWrite.Write(id); IWrite.Write(false); if (arguments is null) { IWrite.Write(0); } else { IWrite.Write(arguments.Length); foreach (var item in arguments) { IWrite.Write(item); } } return(IWrite.Flush()); } await await IWrite.Sync.Ask(WSend); } else { throw new NullReferenceException("IWrite is null!"); } }
protected void debugLogSH161DataCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { string filename = Resources.CreateLogFileName("sh161_", LogType.CSV); iWrite.WriteLine("SH161 Log File: " + filename); GetSH161Data(iWrite, filename); }
protected void debugUserAcc(IWrite iWrite, string cmdName, object[] cmdArguments) { AccountTypeToString ac = new AccountTypeToString(","); if (IsLogged(iWrite)) { System.Array res = default(Array); string msg = ""; string strQuery = ""; int nRecords = fmrConection.userClass.GetAccounts( fmrConection.GetSessionId(), strQuery, ref res, ref msg); iWrite.WriteLine("collected " + nRecords + " records"); iWrite.WriteLine(); iWrite.WriteLine(ac.Legend); for (int i = 0; i < nRecords; i++) { ac.Init((AccountType)res.GetValue(i)); iWrite.WriteLine(ac.Values); } iWrite.WriteLine(); } }
public DetectConflict(CheckCollision checkcollision, IWrite alarm, IWrite log) { _alarm = alarm; _log = log; _checkcollision = checkcollision; _checkcollision.Attach(this); }
public static unsafe void Write <TElement>(this IWrite <TElement> collection, TElement *elements, Int32 length) where TElement : unmanaged { for (Int32 i = 0; i < length; i++) { collection.Write(elements[i]); } }
protected void debugLoggerShowCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { iWrite.WriteLine( OutputUtils.FormatField("Name", 10) + OutputUtils.FormatField("Triggered", 10) + OutputUtils.FormatField("Logged", 10) + OutputUtils.FormatField("Dropped", 10) + OutputUtils.FormatField("Log type", 10) + OutputUtils.FormatField("Latest", 24) + OutputUtils.FormatField("Oldest", 24) + OutputUtils.FormatField("Stamped", 10) ); iWrite.WriteLine("-----------------------------------------------------------------------------------------------------------------------"); bool isEmpty = true; foreach (ILogger logger in Resources.Loggers) { isEmpty = false; iWrite.WriteLine( OutputUtils.FormatField(logger.GetName(), 10) + OutputUtils.FormatField(logger.GetCountTrigger(), 10) + OutputUtils.FormatField(logger.GetCountLog(), 10) + OutputUtils.FormatField(logger.GetCountDropped(), 10) + OutputUtils.FormatField(logger.GetLogType().ToString(), 10) + OutputUtils.FormatField(logger.GetLatest().ToString(), 24) + OutputUtils.FormatField(logger.GetOldest().ToString(), 24) + OutputUtils.FormatField(logger.TimeStamped().ToString(), 10) ); } if (isEmpty) { iWrite.WriteLine("No loggers"); } }
//many methods require being logged in, this is the check protected bool IsLogged(IWrite iWrite) { bool rc = false; if (this.fmrConection == null) { iWrite.WriteLine(Environment.NewLine + "WARNING! You're not logged in. Please log in first!"); } //then check if connection is OK. TaksBar takes care of keeping it alive //in all times. If loginStatus != LoginSessionActive - there probably a big trouble else if (this.fmrConection.loginStatus != LoginStatus.LoginSessionActive) { iWrite.WriteLine(Environment.NewLine + "WARNING! Your login status is " + this.fmrConection.loginStatus.ToString() + "Please check your connection!"); } else { rc = true; } return(rc); }
protected void debugPrintResourcesNameAndStats(IWrite iWrite, System.Collections.ArrayList list) { int entry = 0; int columnSize = 8; bool isEmpty = true; iWrite.WriteLine(); foreach (INamedResource resNamed in list) { isEmpty = false; IResourceStatistics resStat = (IResourceStatistics)resNamed; System.Collections.ArrayList names; System.Collections.ArrayList values; resStat.GetEventCounters(out names, out values); if (entry == 0) { names.Insert(0, "Name"); CommandLineInterface.printTableHeader(iWrite, names, columnSize); } values.Insert(0, OutputUtils.FormatField(resNamed.Name, columnSize)); CommandLineInterface.printValues(iWrite, values, columnSize); entry++; } if (isEmpty) { System.Console.WriteLine("Table is empty - no resources registered"); } }
protected void debugThreadPoolTestCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { int maxJobs = 5; JQuant.ThreadPool threadPool = new JQuant.ThreadPool("test", 1, maxJobs, ThreadPriority.Lowest); threadpoolTestTicks = new long[maxJobs]; long tick = DateTime.Now.Ticks; for (int i = 0; i < maxJobs; i++) { threadpoolTestTicks[i] = tick; } for (int i = 0; i < maxJobs; i++) { threadPool.PlaceJob(ThreadPoolJobEnter, ThreadPoolJobDone, i); } Thread.Sleep(500); debugThreadPoolShowCallback(iWrite, cmdName, cmdArguments); threadPool.Dispose(); for (int i = 0; i < threadpoolTestTicks.Length; i++) { iWrite.WriteLine("ThreadPoolJob done idx =" + i + ", time = " + (double)threadpoolTestTicks[i] / (double)(10 * 1) + " micros"); } }
public Handler(IRead readNames, IOutput outputNames, ISort sorter, IWrite writer) { _readNames = readNames; _sorter = sorter; _writer = writer; _outputNames = outputNames; }
public SqlServerWriter( OutputContext output, IConnectionFactory cf, IBatchReader matcher, IWrite updater ) { _output = output; _cf = cf; _bulkCopyOptions = SqlBulkCopyOptions.Default; TurnOptionOn(SqlBulkCopyOptions.TableLock); TurnOptionOn(SqlBulkCopyOptions.UseInternalTransaction); TurnOptionOff(SqlBulkCopyOptions.CheckConstraints); TurnOptionOff(SqlBulkCopyOptions.FireTriggers); TurnOptionOn(SqlBulkCopyOptions.KeepNulls); _outputKeysReader = matcher; _sqlUpdater = updater; _orderHint = new ClusteredKeyOrderHint(); if (output.OutputFields.Any(f => f.Type.StartsWith("date"))) { _minDates = new MinDateTransform(output, new DateTime(1753, 1, 1)); } }
public Engine(ICollection <IServant> servants, IReader consoleReader, IWrite consoleWriter, King king) { this.servants = servants; this.consoleReader = consoleReader; this.consoleWriter = consoleWriter; this.king = king; }
protected void debugProducerShowCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { System.Collections.ArrayList names; System.Collections.ArrayList values; int entry = 0; int columnSize = 12; bool isEmpty = true; iWrite.WriteLine(); foreach (IResourceProducer producer in Resources.Producers) { producer.GetEventCounters(out names, out values); isEmpty = false; if (entry == 0) { names.Insert(0, "Name"); CommandLineInterface.printTableHeader((JQuant.IWrite) this, names, columnSize); } values.Insert(0, OutputUtils.FormatField(producer.Name, columnSize)); CommandLineInterface.printValues((JQuant.IWrite) this, values, columnSize); entry++; } if (isEmpty) { iWrite.WriteLine("No producers"); } }
/// <summary> /// Writes the <paramref name="elements"/>, one by one. /// </summary> /// <typeparam name="TElement">The type of the elements in the collection.</typeparam> /// <param name="collection">This collection.</param> /// <param name="elements">The values to write.</param> public static void Write <TElement>(this IWrite <TElement> collection, ReadOnlySpan <TElement> elements) { for (Int32 i = 0; i < elements.Length; i++) { collection.Write(elements[i]); } }
protected void debugUserPermissions(IWrite iWrite, string cmdName, object[] cmdArguments) { System.Array res = null; if (IsLogged(iWrite)) { int rc = this.fmrConection.userClass.GetUserPermissions(this.fmrConection.GetSessionId(), out res); PermTypeToString print = new PermTypeToString(" "); int len = res.Length; //int i = 0; if (res != null) { iWrite.WriteLine(print.Legend); foreach (UserPasswordType p in res) { iWrite.Write(p.SUG_RC + " " + p.USR_NAME + " " + p.USR_PW + " " + p.Branch + " " + p.Sug + " " + p.MFZL_ID + " " + p.TIK_N + " " + p.ID_N + " " + p.APPL_N + " " + p.DEVICE_N + " " + p.AUTH_LVL + " " + p.FIELD + " " + p.OPERATOR + " " + p.val + " " + p.UPD_DAT + " " + p.END_DAT + " " + p.UPD_USR_N + " " + p.FROM_USR_N + " " + p.FIL + " " + Environment.NewLine); /*if (p.FIELD != "") * { * print.Init((UserPasswordType)res.GetValue(i)); * iWrite.WriteLine(print.Values); * } * i++;*/ } //for some reason this didn't work, so i replaced it with the code above //in any case it not well understood what all those values say)) /* * for (int i = 0; i < len; i++) * { * if (res.GetValue(i) != null) * { * print.Init((UserPasswordType)res.GetValue(i)); * iWrite.WriteLine(print.Values); * } * }*/ } } }
private static void Main(string[] args) { List <string> sortPersonList = new List <string>(); IRead read = Factory.CreateReader(); IWrite write = Factory.CreateWriter(); ISorter sorter; IList <IPerson> people = read.ReadData(args[0], out var setAllGenders); Console.Write("Press 1 to sort the names in ascending order or press 2 to sort the names in descending order: "); int sorting_way = Convert.ToInt32(Console.ReadLine()); while (sorting_way != 1 && sorting_way != 2) { Console.Write("Incorrect Input, please choose again: "); sorting_way = Convert.ToInt32(Console.ReadLine()); } sorter = Factory.CreateSorter(sorting_way); people = sorter.Sort(people); Task.WhenAll(setAllGenders).Wait(); foreach (Person person in people) { Console.WriteLine(person.GetName()); sortPersonList.Add(person.GetName()); } write.WriteData(sortPersonList); Console.ReadKey(); }
protected void algoSetMode(IWrite iWrite, string cmdName, object[] cmdArguments) { if (algoMachine != null) { switch (cmdArguments.Length) { case 1: iWrite.WriteLine("Please deifne the mode - a | s"); break; case 2: switch (cmdArguments[1].ToString().ToLower()) { case "a": algoMachine.SetMode(Base.Mode.Automatic); break; case "s": algoMachine.SetMode(Base.Mode.Semiautomatic); break; default: iWrite.WriteLine("Invalid mode " + cmdArguments[1].ToString()); break; } break; default: iWrite.WriteLine("Too many arguments"); break; } } }
public AdoEntityWriter(OutputContext output, IBatchReader matcher, IWrite inserter, IWrite updater) { _output = output; _matcher = matcher; _inserter = inserter; _updater = updater; }
public BankAccount(IWrite writer, IDate date) { this.writer = writer; balance = 0; movements = new Stack <Movement>(); this.date = date; }
/// <summary> /// Loads <paramref name="amount"/> bytes into this object. /// </summary> /// <typeparam name="TElement">The type of the elements in the collection.</typeparam> /// <param name="collection">This collection.</param> /// <param name="amount">The amount of elements to load.</param> /// <param name="source">The source to load data from.</param> public static void Load <TElement>(this IWrite <TElement> collection, Int32 amount, IRead <TElement> source) { for (Int32 i = 0; i < amount; i++) { collection.Load(source); } }
/// <summary> /// This method is used to write data of the specified list to the server. It is called /// by the ClientBase after the client application has prepared and committed the data /// values. /// </summary> /// <param name="serverListId"> The server identifier of the list containing the data objects to write. </param> /// <param name="writeValueArrays"> The data values to write. </param> /// <returns> /// The list server aliases and result codes for the data objects whose write failed. Returns null if all writes /// succeeded or null if this is a keep-alive. /// </returns> public List <AliasResult>?WriteData(uint serverListId, DataValueArraysWithAlias writeValueArrays) { if (_disposed) { throw new ObjectDisposedException("Cannot access a disposed XiContext."); } if (_writeEndpoint is null) { throw new Exception("No Write Endpoint"); } if (_writeEndpoint.Disposed) { return(null); } IWrite iWrite = _writeEndpoint.Proxy; string contextId = ContextId; _writeEndpoint.LastCallUtc = DateTime.UtcNow; List <AliasResult>?listAliasResult = null; try { listAliasResult = iWrite.WriteVST(contextId, serverListId, writeValueArrays); } catch (Exception ex) { ProcessRemoteMethodCallException(ex); } return(listAliasResult); }
protected void debugMarketSimulationMaofTraceCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { if (cmdArguments.Length < 2) { iWrite.WriteLine("Security ID is required"); return; } if (marketSimulationMaof == default(MarketSimulationMaof)) { iWrite.WriteLine("Create market simulation first"); return; } int securityId = Convert.StrToInt((string)(cmdArguments[1]), 0); bool enable = false; if (cmdArguments.Length > 2) { enable = Boolean.Parse((string)(cmdArguments[2])); } else { enable = !(marketSimulationMaof.GetEnableTrace(securityId)); } marketSimulationMaof.EnableTrace(securityId, enable); }
protected void algoStop(IWrite iWrite, string cmdName, object[] cmdArguments) { if (IsLogged(iWrite)) { //stop and dispose algo if (algoMachine != default(Algo.Base)) { algoMachine.StopGracefull(); DataCollector.rezefProducer.RemoveConsumer(algoMachine); algoMachine.Dispose(); algoMachine = default(Algo.Base); } //stop and dispose OrderFSM if (rezefOrderFSM != default(FMRShell.RezefOrderFSM)) { rezefOrderFSM.Dispose(); rezefOrderFSM = default(FMRShell.RezefOrderFSM); } //TODO - test if there is no other users, before calling DataCollector.Stop if (DataCollector != default(FMRShell.Collector)) { DataCollector.Stop(FMRShell.DataType.Rezef); } } }
public AdoOutputProvider(OutputContext context, IConnectionFactory cf, IWrite writer) { _writer = writer; _context = context; _cf = cf; _cn = cf.GetConnection(); }
protected void debugMarketSimulationMaofSecsMaof(IWrite iWrite, string cmdName, object[] cmdArguments) { int[] ids = marketSimulationMaof.GetSecurities(); //get the list of securities System.Collections.ArrayList names = new System.Collections.ArrayList(); names.Add("Id"); names.Add("Name"); names.Add("Bid:PriceVolume"); names.Add("Ask:PriceVolume"); int[] columns = JQuant.ArrayUtils.CreateInitializedArray(6, names.Count); columns[0] = 10; columns[1] = 16; columns[2] = 30; columns[3] = 30; CommandLineInterface.printTableHeader(iWrite, names, columns); System.Array.Sort(ids); foreach (int id in ids) { MarketSimulationMaof.Option option = marketSimulationMaof.GetOption(id); System.Collections.ArrayList values = new System.Collections.ArrayList(); values.Add(id); values.Add(option.GetName()); values.Add(OrderBook2String(option.GetBookBid(), 9)); values.Add(OrderBook2String(option.GetBookAsk(), 9)); CommandLineInterface.printValues(iWrite, values, columns); } }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion internal virtual IWrite CreateIWrite() { // TODO: Instantiate an appropriate concrete class. IWrite target = null; return(target); }
public void SetUp() { log = Substitute.For <IWrite>(); alarm = Substitute.For <IWrite>(); checkcollision = Substitute.For <CheckCollision>(); uut = new DetectConflict(checkcollision, alarm, log); DateTime dateTime1 = new DateTime(2018, 06, 10, 10, 18, 18); DateTime dateTime2 = new DateTime(2018, 06, 10, 10, 18, 20); ITrack track1 = new Track(); track1.Tag = "KLA123"; track1.Timestamp = dateTime1; ITrack track2 = new Track(); track2.Tag = "RIH456"; track1.Timestamp = dateTime2; var li = new List <ITrack> { track1, track2 }; checkcollision.ConflictingFlights = li; uut.Update(); }
protected void algoSetMode(IWrite iWrite, string cmdName, object[] cmdArguments) { if (algoMachine != null) { switch (cmdArguments.Length) { case 1: iWrite.WriteLine("Please deifne the mode - a | s"); break; case 2: switch (cmdArguments[1].ToString().ToLower()) { case "a": algoMachine.SetMode(Base.Mode.Automatic); break; case "s": algoMachine.SetMode(Base.Mode.Semiautomatic); break; default: iWrite.WriteLine("Invalid mode " + cmdArguments[1].ToString()); break; } break; default: iWrite.WriteLine("Too many arguments"); break; } } }
public void PrintTitle(IWrite iWrite) { iWrite.WriteLine(Name + " - " + CurrentMenu.Name); iWrite.WriteLine("====================================="); iWrite.WriteLine("help, exit, one level up - .., main menu - ~"); iWrite.WriteLine(""); }
protected void debugCyclicBufferTestCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { CyclicBuffer<int> cb = new CyclicBufferSynchronized<int>("cliCbTest", 3); iWrite.WriteLine(); foreach (int i in cb) { iWrite.WriteLine("No elements " + i); } iWrite.WriteLine(); cb.Add(0); foreach (int i in cb) { iWrite.WriteLine("One element " + i); } iWrite.WriteLine(); cb.Add(1); cb.Add(2); cb.Add(3); cb.Add(4); foreach (int i in cb) { iWrite.WriteLine("Three elements " + i); } }
public static void SaveAs(Window window, string[] fileExtensions, IWrite<string> data) { var filter = FileExtensionModule.AddStar(fileExtensions); var filename = SaveFileModule.WithFilters(window, filter); if (filename == null) return; if (!FileExtensionModule.EndsWithAny(filename, fileExtensions)) filename += fileExtensions[0]; data.Save(filename); }
protected void algoReal(IWrite iWrite, string cmdName, object[] cmdArguments) { if (algoMachine != null) { algoMachine.PlaceRealTrade(); } else { if (IsLogged(iWrite)) { iWrite.WriteLine("Algo is not started."); } } }
protected void debugFileLoggerTestCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { // I can use FileLoggerTestDataSimple or FileLoggerTestData structures - both work FileLogger<FileLoggerTestData> logger = new FileLogger<FileLoggerTestData>("test", "test.csv", false, ""); logger.Start(); // add an entry to the log logger.AddEntry(new FileLoggerTestData()); // wait little bit before I tear the logger down - i want to let the logger to finish writing Thread.Sleep(200); logger.Stop(); logger.Dispose(); }
protected void feedFisherTransformCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { TA.PriceVolumeSeries series = FeedSeries; // first step is to calculate max, min, average etc. series.CalculateParams(); iWrite.WriteLine("Series: count=" + series.Data.Count + ", max=" + series.Max + ", min=" + series.Min + ", average=" + series.Average + ", sd=" + series.StdDeviation); double average, max, min; double[] data = TA.PriceVolumeSeries.GetClose(series); TA.PriceVolumeSeries.CalculateAverage(data, 0, data.Length, out average, out max, out min); iWrite.WriteLine("Data: count=" + data.Length + ",max=" + series.Max + ", min=" + series.Min + ", average=" + series.Average + ", sd=" + series.StdDeviation); int windowSize = 10; // now normalize the data data = TA.PriceVolumeSeries.Normalize(data, windowSize); TA.PriceVolumeSeries.CalculateAverage(data, 0, data.Length, out average, out max, out min); iWrite.WriteLine("Normalize(data): count=" + data.Length + ",max=" + max + ", min=" + min + ", average=" + average); TA.PriceVolumeSeries.EMA(data, 0.5); TA.PriceVolumeSeries.CalculateAverage(data, 0, data.Length, out average, out max, out min); iWrite.WriteLine("EMA(Normalize(data)): count=" + data.Length + ",max=" + max + ", min=" + min + ", average=" + average); TA.PriceVolumeSeries.Fisher(data); TA.PriceVolumeSeries.CalculateAverage(data, 0, data.Length, out average, out max, out min); iWrite.WriteLine("Fisher(EMA(Normalize(data))): count=" + data.Length + ",max=" + max + ", min=" + min + ", average=" + average); TA.PriceVolumeSeries.EMA(data, 0.5); TA.PriceVolumeSeries.CalculateAverage(data, 0, data.Length, out average, out max, out min); iWrite.WriteLine("EMA(Fisher(EMA(Normalize(data)))): count=" + data.Length + ",max=" + max + ", min=" + min + ", average=" + average); int i; for (i = 0; i < data.Length; i++) { // iWrite.WriteLine(""+data[i]); } signalPerformanceOptimization(series, data, windowSize); }
void Unsupported(IWrite iWrite, string cmdName, object[] cmdArguments) { iWrite.WriteLine("Unsupported command " + Name); }
protected void debugMarketSimulationMaofPlaceOrderCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { if (marketSimulationMaof == default(MarketSimulationMaof)) // check if there active simulation to get data from { iWrite.WriteLine("No active market simulations."); return; } int id; bool res = FindSecurity(cmdName, out id); if (!res) { iWrite.WriteLine("Unknown security in the command " + cmdName); return; } // i got security ID bool buyOrder = (cmdArguments[1].ToString().ToUpper().CompareTo("BUY") == 0); bool sellOrder = (cmdArguments[1].ToString().ToUpper().CompareTo("SELL") == 0); if (!buyOrder && !sellOrder) { iWrite.WriteLine("Use words buy or sell to specify the order type"); return; } if (buyOrder && sellOrder) { iWrite.WriteLine("Internal error: both buy and sell in " + cmdArguments[1]); return; } // are there three and only three numbers in the command line ? const string patternNumbers = ".+[0-9]+.+[0-9]+ +[0-9]+"; System.Text.RegularExpressions.Regex regexNumbers = new System.Text.RegularExpressions.Regex(patternNumbers); System.Text.RegularExpressions.MatchCollection matches = regexNumbers.Matches(cmdName); if (matches.Count != 1) { iWrite.WriteLine("Three and only three numbers - security ID, limit price and quantiy are allowed. I got '" + cmdName + "'"); return; } // last arguments are price and quantity string limitPriceStr = cmdArguments[cmdArguments.Length - 2].ToString(); string quantintyStr = cmdArguments[cmdArguments.Length - 1].ToString(); int limitPrice = Int32.Parse(limitPriceStr); int quantity = Int32.Parse(quantintyStr); if (limitPrice == 0) { iWrite.WriteLine("Failed to parse limit price " + limitPriceStr); return; } if (quantity == 0) { iWrite.WriteLine("Failed to parse quantinty " + quantintyStr); return; } TransactionType transaction; if (buyOrder) { transaction = TransactionType.BUY; } else { transaction = TransactionType.SELL; } MarketSimulation.ReturnCode errorCode; MarketSimulation.ISystemLimitOrder order = marketSimulationMaof.CreateOrder(id, limitPrice, quantity, transaction, placeOrderCallback); res = marketSimulationMaof.PlaceOrder(order, out errorCode); if (!res) { iWrite.WriteLine("Failed to place order error=" + errorCode); } }
protected void algoSkip(IWrite iWrite, string cmdName, object[] cmdArguments) { if (algoMachine != null) { algoMachine.SkipTrigger(); } else { if (IsLogged(iWrite)) { iWrite.WriteLine("Algo is not started."); } } }
protected void algoStop(IWrite iWrite, string cmdName, object[] cmdArguments) { if (IsLogged(iWrite)) { //stop and dispose algo if (algoMachine != default(Algo.Base)) { algoMachine.StopGracefull(); DataCollector.rezefProducer.RemoveConsumer(algoMachine); algoMachine.Dispose(); algoMachine = default(Algo.Base); } //stop and dispose OrderFSM if (rezefOrderFSM != default(FMRShell.RezefOrderFSM)) { rezefOrderFSM.Dispose(); rezefOrderFSM = default(FMRShell.RezefOrderFSM); } //TODO - test if there is no other users, before calling DataCollector.Stop if (DataCollector != default(FMRShell.Collector)) DataCollector.Stop(FMRShell.DataType.Rezef); } }
/// <summary> /// Create Algo object and connect it to the data feed /// Data feed can be a playback or real-time data feed /// </summary> protected void algoStart(IWrite iWrite, string cmdName, object[] cmdArguments) { if (IsLogged(iWrite)) { if (algoMachine != null) { iWrite.WriteLine("Stop the algo first"); return; } bool argsRes = true; #if USEFMRSIM string backlogfile = null; double speedup = 1.0; #endif // parse arguments switch (cmdArguments.Length) { #if USEFMRSIM case 0: case 1: iWrite.WriteLine("Usage: <backlogfile> [speedup]"); argsRes = false; break; case 2: backlogfile = cmdArguments[1].ToString(); break; case 3: backlogfile = cmdArguments[1].ToString(); speedup = JQuant.Convert.StrToDouble(cmdArguments[2].ToString(), 1.0); break; #endif default: iWrite.WriteLine("Too many arguments"); argsRes = false; break; } if (!argsRes) return; // if i run in simulation mode create playback #if USEFMRSIM // create Rezef data generator TaskBarLibSim.EventGenerator<K300RzfType> dataGenerator = new TaskBarLibSim.RezefDataGeneratorLogFile(backlogfile, speedup, 500); // setup the data generator(s) in the K300Class TaskBarLibSim.K300Class.InitStreamSimulation(dataGenerator); #endif // Create data collector if not created already. // Do not set internal time stamps, use time stamps from the recorded data log if (DataCollector == null) DataCollector = new FMRShell.Collector(this.fmrConection.GetSessionId(), false); // create Order FSM rezefOrderFSM = new RezefOrderFSM(this.fmrConection); rezefOrderFSM.Start(); // create Algo if (algoMachine == null) algoMachine = new Algo.Base(rezefOrderFSM); // connect algo to the data feed DataCollector.rezefProducer.AddConsumer(algoMachine); // start data collector, which will start the stream in K300Class DataCollector.Start(FMRShell.DataType.Rezef); // start algo - can be also done afterwards, by calling Start algoMachine.Start(); } }
protected void debugMarketSimulationMaofStatMaof(IWrite iWrite, string cmdName, object[] cmdArguments) { }
protected void debugMarketSimulationMaofStatCore(IWrite iWrite, string cmdName, object[] cmdArguments) { int columnSize = 8; System.Collections.ArrayList names; System.Collections.ArrayList values; marketSimulationMaof.GetEventCounters(out names, out values); CommandLineInterface.printTableHeader(iWrite, names, columnSize); CommandLineInterface.printValues(iWrite, values, columnSize); }
private void GotoRootMenu(IWrite iWrite, string cmdName, object[] cmdArguments) { CurrentMenu = RootMenu; PrintCommands(iWrite); }
protected void debugMarketSimulationMaofStatBook(IWrite iWrite, string cmdName, object[] cmdArguments) { int[] ids = marketSimulationMaof.GetSecurities(); //get the list of securities int[] columns = new int[0]; bool firstLoop = true; System.Collections.ArrayList names = new System.Collections.ArrayList(); names.Add("Name"); System.Array.Sort(ids); foreach (int id in ids) { MarketSimulationMaof.Option option = marketSimulationMaof.GetOption(id); System.Collections.ArrayList values = new System.Collections.ArrayList(); JQuant.IResourceStatistics bids = marketSimulationMaof.GetOrderBook(id, JQuant.TransactionType.BUY); System.Collections.ArrayList bidValues; System.Collections.ArrayList bidNames; bids.GetEventCounters(out bidNames, out bidValues); JQuant.IResourceStatistics asks = marketSimulationMaof.GetOrderBook(id, JQuant.TransactionType.SELL); System.Collections.ArrayList askValues; System.Collections.ArrayList askNames; asks.GetEventCounters(out askNames, out askValues); // print table header if this is first loop if (firstLoop) { firstLoop = false; for (int i = 0; i < bidNames.Count; i++) { names.Add(bidNames[i]); } for (int i = 0; i < askNames.Count; i++) { names.Add(askNames[i]); } columns = JQuant.ArrayUtils.CreateInitializedArray(6, names.Count); columns[0] = 16; columns[1] = 10; columns[2] = 6; columns[3] = 6; columns[4] = 6; columns[5] = 10; columns[6] = 6; columns[7] = 6; columns[8] = 6; CommandLineInterface.printTableHeader(iWrite, names, columns); } values.Add(option.GetName()); for (int i = 0; i < bidValues.Count; i++) { values.Add(bidValues[i]); } for (int i = 0; i < askValues.Count; i++) { values.Add(askValues[i]); } CommandLineInterface.printValues(iWrite, values, columns); } }
protected void debugMarketSimulationMaofSecsQueue(IWrite iWrite, string cmdName, object[] cmdArguments) { if (marketSimulationMaof == default(MarketSimulationMaof)) // check if there active simulation to get data from { iWrite.WriteLine("No active market simulations."); return; } iWrite.WriteLine("Not supported"); }
protected void debugMarketSimulationMaofSecsMaof(IWrite iWrite, string cmdName, object[] cmdArguments) { int[] ids = marketSimulationMaof.GetSecurities(); //get the list of securities System.Collections.ArrayList names = new System.Collections.ArrayList(); names.Add("Id"); names.Add("Name"); names.Add("Bid:PriceVolume"); names.Add("Ask:PriceVolume"); int[] columns = JQuant.ArrayUtils.CreateInitializedArray(6, names.Count); columns[0] = 10; columns[1] = 16; columns[2] = 30; columns[3] = 30; CommandLineInterface.printTableHeader(iWrite, names, columns); System.Array.Sort(ids); foreach (int id in ids) { MarketSimulationMaof.Option option = marketSimulationMaof.GetOption(id); System.Collections.ArrayList values = new System.Collections.ArrayList(); values.Add(id); values.Add(option.GetName()); values.Add(OrderBook2String(option.GetBookBid(), 9)); values.Add(OrderBook2String(option.GetBookAsk(), 9)); CommandLineInterface.printValues(iWrite, values, columns); } }
/// <summary> /// This method do two things /// - get list of securities from the MarketSimulationMaof /// For every security ask MarketSimulation.Core what the Core thinks about it. /// </summary> protected void debugMarketSimulationMaofSecsCore(IWrite iWrite, string cmdName, object[] cmdArguments) { int[] ids = marketSimulationMaof.GetSecurities(); //get the list of securities System.Collections.ArrayList names = new System.Collections.ArrayList(); names.Add("Id"); names.Add("Name"); names.Add("CoreId"); names.Add("Bid:PriceVolume"); names.Add("Ask:PriceVolume"); names.Add("LastTrade"); names.Add("LastTradeSize"); names.Add("DayVolume"); int[] columns = JQuant.ArrayUtils.CreateInitializedArray(6, names.Count); columns[0] = 9; columns[1] = 12; columns[2] = 9; columns[3] = 30; columns[4] = 30; CommandLineInterface.printTableHeader(iWrite, names, columns); System.Array.Sort(ids); foreach (int id in ids) { // i need MarketSimulationMaof.Option to show the name of the option // currently I take care only of options MarketSimulationMaof.Option option = marketSimulationMaof.GetOption(id); // get information kept in the MrketSimulation.Core MarketSimulation.MarketData md = marketSimulationMaof.GetSecurity(id); System.Collections.ArrayList values = new System.Collections.ArrayList(); values.Add(id); values.Add(option.GetName()); values.Add(md.id); values.Add(OrderBook2String(md.bid, 9)); values.Add(OrderBook2String(md.ask, 9)); values.Add(md.lastTrade); values.Add(md.lastTradeSize); values.Add(md.dayVolume); CommandLineInterface.printValues(iWrite, values, columns); } }
protected void DummyCommand(IWrite iWrite, string cmdName, object[] cmdArguments) { iWrite.WriteLine("Menu " + Name + ": callback is called. Probably should be command"); }
public void Register(IWrite writer) { _pipeline.Register(writer); }
protected void debugMarketSimulationMaofStatQueue(IWrite iWrite, string cmdName, object[] cmdArguments) { iWrite.WriteLine("Not supported"); }
protected void algoStat(IWrite iWrite, string cmdName, object[] cmdArguments) { if (algoMachine == null) { iWrite.WriteLine("No algo started"); return; } IResourceStatistics resStat = algoMachine; System.Collections.ArrayList names; System.Collections.ArrayList values; resStat.GetEventCounters(out names, out values); int columnSize = 8; CommandLineInterface.printTableHeader(iWrite, names, columnSize); CommandLineInterface.printValues(iWrite, values, columnSize); }
protected void debugMarketSimulationMaofTraceCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { if (cmdArguments.Length < 2) { iWrite.WriteLine("Security ID is required"); return; } if (marketSimulationMaof == default(MarketSimulationMaof)) { iWrite.WriteLine("Create market simulation first"); return; } int securityId = Convert.StrToInt((string)(cmdArguments[1]), 0); bool enable = false; if (cmdArguments.Length > 2) { enable = Boolean.Parse((string)(cmdArguments[2])); } else { enable = !(marketSimulationMaof.GetEnableTrace(securityId)); } marketSimulationMaof.EnableTrace(securityId, enable); }
protected void algoStopUrgent(IWrite iWrite, string cmdName, object[] cmdArguments) { algoMachine.StopUrgent(); }
protected void debugMarketSimulationMaofWatchCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { if (marketSimulationMaof == default(MarketSimulationMaof)) // check if there active simulation to get data from { iWrite.WriteLine("No active market simulations."); return; } if (watchlistCallback == null) // create a watchlist callback in the first call { watchlistCallback = new WatchlistCallback(iWrite); } if (cmdArguments.Length == 2) { // argument is legend or list string legendList = cmdArguments[1].ToString(); legendList = legendList.ToUpper(); if (legendList.CompareTo("LEGEND") == 0) { watchlistCallback.printLegend(); } else if (legendList.CompareTo("LIST") == 0) { watchlistCallback.printList(); } else { iWrite.WriteLine("Use commands legend or list"); } return; } if (cmdArguments.Length < 3) { iWrite.WriteLine("At least two arguments are required"); return; } int id; bool res = FindSecurity(cmdName, out id); if (!res) { iWrite.WriteLine("Unknown security in the command " + cmdName); return; } // first argument is add or rmv string addRmv = cmdArguments[1].ToString(); addRmv = addRmv.ToUpper(); if (addRmv.CompareTo("ADD") == 0) { marketSimulationMaof.AddWatch(id, watchlistCallback.callback); } else { marketSimulationMaof.RemoveWatch(id); } }
private void OneLevelUp(IWrite iWrite, string cmdName, object[] cmdArguments) { CurrentMenu = CurrentMenu.Parent; PrintCommands(iWrite); }
public WatchlistCallback(IWrite iWrite) { this.iWrite = iWrite; }
protected void debugMarketSimulationMaofStatCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { string cmd = "core"; if (dataMaofGenerator == default(MaofDataGeneratorLogFile)) // check if there active simulation to get data from { // to prevent System.NullReferenceException iWrite.WriteLine("No active market simulations."); return; } if (cmdArguments.Length > 1) { cmd = (string)cmdArguments[1]; } if (cmd == "maof") { debugMarketSimulationMaofStatMaof(iWrite, cmdName, cmdArguments); } else if (cmd == "core") { debugMarketSimulationMaofStatCore(iWrite, cmdName, cmdArguments); } else if (cmd == "book") { debugMarketSimulationMaofStatBook(iWrite, cmdName, cmdArguments); } else if (cmd == "queue") { debugMarketSimulationMaofStatQueue(iWrite, cmdName, cmdArguments); } else { iWrite.WriteLine("Only arguments maof, core, book, queue are supported"); } }
protected void debugMarketSimulationMaofCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { string cmd = "", arg1 = "", arg2 = ""; switch (cmdArguments.Length) { case 0: case 1: iWrite.WriteLine("Usage: maof create <backlogfile> [speedup] | stop | start"); break; case 2: cmd = cmdArguments[1].ToString().ToLower(); break; case 3: cmd = cmdArguments[1].ToString().ToLower(); arg1 = cmdArguments[2].ToString(); break; case 4: cmd = cmdArguments[1].ToString().ToLower(); arg1 = cmdArguments[2].ToString(); arg2 = cmdArguments[3].ToString(); break; } if (cmd == "stop") { if (dataMaofGenerator != default(MaofDataGeneratorLogFile)) { dataMaofGenerator.Stop(); // dataMaofGenerator.RemoveConsumer(marketSimulationMaof); marketSimulationMaof.Dispose(); marketSimulationMaof = default(MarketSimulationMaof); dataMaofGenerator = default(MaofDataGeneratorLogFile); iWrite.WriteLine("maof stop called"); } else { iWrite.WriteLine("No active simulation to stop."); } } else if (cmd == "start") // log file name { if (this.dataMaofGenerator != default(MaofDataGeneratorLogFile)) { // call EventGenerator.Start() - start the data stream dataMaofGenerator.Start(); } else { iWrite.WriteLine("Use 'create' first to create the market simulation"); } } else if (cmd == "create") // log file name { string logfile = arg1; double speedup = JQuant.Convert.StrToDouble(arg2, 1.0); //if K300Class instance is not already initilazed, do it now if (this.dataMaofGenerator == default(MaofDataGeneratorLogFile)) { this.dataMaofGenerator = new MaofDataGeneratorLogFile(logfile, speedup, 0); //I need a cast here, because MarketSimulationMaof expects parameter of type IProducer marketSimulationMaof = new MarketSimulationMaof(); // dataMaofGenerator.AddConsumer(marketSimulationMaof); // marketSimulationMaof.EnableTrace(80608128, true); // marketSimulationMaof.EnableTrace(80616808, true); iWrite.WriteLine("Use 'start' to start the market simulation"); } else //for the moment I don't want the mess of running multiple simulations simultaneously. { iWrite.WriteLine("Maof simulation " + dataMaofGenerator.Name + "is already running."); iWrite.WriteLine("Only a single simulation at a time is possible."); } } }