From 33030b121218274eb623e155e1b36fb0876d96df Mon Sep 17 00:00:00 2001 From: Taha Date: Mon, 16 Oct 2023 00:01:29 -0400 Subject: [PATCH] Market data streams work now --- docker/linux | 1 + docker/windows | 1 + .../DataStream/DataStream.csproj | 2 +- .../FileStreams/CaptureSnapshotStream.cs | 40 - .../Primitives/FileStreams/PersistorStream.cs | 130 +++ .../Primitives/FileStreams/PlaybackStream.cs | 245 ++++-- .../Primitives/FileStreams/SnapshotStream.cs | 115 +++ .../FileStreams/StreamPersistorUtils.cs | 145 ++++ .../DataStream/Primitives/Misc/DebugStream.cs | 46 + .../Primitives/Misc/TimeSeriesStream.cs | 45 + .../Time/DateStandardizationStream.cs | 143 ++++ .../BlueData/BlueDataUtility.cs | 12 + .../DynamicLoading/PrimitiveManager.cs | 7 +- .../DataStreamPublisher.csproj | 1 + .../DataStreamPublisher/Program.cs | 26 +- .../DataStreamQueryAnalyzer/HScrollGrid.resx | 120 +++ .../MainForm.Designer.cs | 798 ++++++++++-------- .../DataStreamQueryAnalyzer/MainForm.cs | 39 +- .../DataStreamQueryAnalyzer/MainForm.resx | 60 -- src/DataStreamSuite/PubSub/StreamOpCode.cs | 6 +- .../MarketData/{MDStream.cs => BBOStream.cs} | 52 +- .../Business/MarketData/BookStream.cs | 146 ++++ .../Business/MarketData/InstrumentsStream.cs | 120 +++ .../Business/MarketData/PriceStatsStream.cs | 125 +++ .../TimeSeriesGroupByStream.cs | 117 +++ .../Business/MarketData/TimeSalesStream.cs | 93 ++ .../SharedStreams/SharedStreams.csproj | 4 + .../AW2/Bus/VolSurfaceBlackboardManager.cs | 152 ++-- src/client/spark/AW2/Misc/Pair.cs | 124 +-- src/client/spark/Daemons/MergedMDDaemon.cs | 56 +- .../BlackboardStructure/MNSheetTheoRequest.cs | 14 +- .../NMSheetSingleOptionData.cs | 2 +- .../NMSheetSingleOptionDataTaskEye.cs | 14 +- .../NMSheetSingleOptionDataTaskQuoter.cs | 14 +- .../DataProviders/NMSheetMainDataSource.cs | 2 +- .../spark/NMSheets/Outside/ColorRetriever.cs | 4 +- .../NMSheets/Outside/ExchangeSecurityMap.cs | 53 +- .../Outside/OptionContractKeyedData.cs | 65 +- .../tc2/Calculator2/MainForm/ATM/ATMData.cs | 2 +- .../MainForm/ATM/OptionATMDataSource.cs | 2 +- .../NMSheetDriverControlStrip.cs | 2 +- .../UIComponents/MainSheet/NMSheetTheoGrid.cs | 2 +- .../MainSheet/NMSheetTheoGridMouseHandling.cs | 2 +- src/client/spark/Spark.csproj | 1 + .../Calculators/StatelessSpreadCalculator.cs | 2 +- .../spark_api/MarketData/MarketDataClient.cs | 2 +- 46 files changed, 2367 insertions(+), 787 deletions(-) create mode 160000 docker/linux create mode 160000 docker/windows delete mode 100644 src/DataStreamSuite/DataStream/Primitives/FileStreams/CaptureSnapshotStream.cs create mode 100644 src/DataStreamSuite/DataStream/Primitives/FileStreams/PersistorStream.cs create mode 100644 src/DataStreamSuite/DataStream/Primitives/FileStreams/SnapshotStream.cs create mode 100644 src/DataStreamSuite/DataStream/Primitives/FileStreams/StreamPersistorUtils.cs create mode 100644 src/DataStreamSuite/DataStream/Primitives/Misc/DebugStream.cs create mode 100644 src/DataStreamSuite/DataStream/Primitives/Misc/TimeSeriesStream.cs create mode 100644 src/DataStreamSuite/DataStream/Primitives/Time/DateStandardizationStream.cs create mode 100644 src/DataStreamSuite/DataStreamQueryAnalyzer/HScrollGrid.resx rename src/DataStreamSuite/SharedStreams/Business/MarketData/{MDStream.cs => BBOStream.cs} (58%) create mode 100644 src/DataStreamSuite/SharedStreams/Business/MarketData/BookStream.cs create mode 100644 src/DataStreamSuite/SharedStreams/Business/MarketData/InstrumentsStream.cs create mode 100644 src/DataStreamSuite/SharedStreams/Business/MarketData/PriceStatsStream.cs create mode 100644 src/DataStreamSuite/SharedStreams/Business/MarketData/TimSeriesOperations/TimeSeriesGroupByStream.cs create mode 100644 src/DataStreamSuite/SharedStreams/Business/MarketData/TimeSalesStream.cs diff --git a/docker/linux b/docker/linux new file mode 160000 index 000000000..653781226 --- /dev/null +++ b/docker/linux @@ -0,0 +1 @@ +Subproject commit 65378122620c7a26561641cb49b477c822b315f2 diff --git a/docker/windows b/docker/windows new file mode 160000 index 000000000..de7d40c09 --- /dev/null +++ b/docker/windows @@ -0,0 +1 @@ +Subproject commit de7d40c09de473e1b2802c4b27e03dc7f0c360d6 diff --git a/src/DataStreamSuite/DataStream/DataStream.csproj b/src/DataStreamSuite/DataStream/DataStream.csproj index 507294e20..22319c84a 100644 --- a/src/DataStreamSuite/DataStream/DataStream.csproj +++ b/src/DataStreamSuite/DataStream/DataStream.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/DataStreamSuite/DataStream/Primitives/FileStreams/CaptureSnapshotStream.cs b/src/DataStreamSuite/DataStream/Primitives/FileStreams/CaptureSnapshotStream.cs deleted file mode 100644 index 63e923291..000000000 --- a/src/DataStreamSuite/DataStream/Primitives/FileStreams/CaptureSnapshotStream.cs +++ /dev/null @@ -1,40 +0,0 @@ -// using System; -// using System.Collections.Generic; -// using System.Linq; -// using System.Text; -// using System.IO; - -// namespace BCG -// { -// public class CaptureSnapshotStream : ViewStream -// { -// public CaptureSnapshotStream(string basePath,ViewStream sourceStream) -// { -// myBasePath = basePath; -// mySource = sourceStream; -// Directory.CreateDirectory(myBasePath); -// } - -// protected override void myOnFirstSubscriber() -// { -// mySource.onChange += new ChangeDelegate(mySource_onChange); -// } - -// protected override void myOnLastSubscriber() -// { -// mySource.onChange -= mySource_onChange; -// } - -// void mySource_onChange(object newValue) -// { -// DateTime now = DateTime.Now; -// new ViewStreamWaiter(new SaverStream(new BlueRowCollectionStaticStream(((DataPacket)newValue).newRows), -// Path.Combine(myBasePath, String.Format("{0}_{1}.ds", now.ToString("yyyyMMdd_HHmmss"), -// now.Millisecond)))).waitUntilArrived(); -// myFireEvent(newValue); -// } - -// private string myBasePath; -// private ViewStream mySource; -// } -// } diff --git a/src/DataStreamSuite/DataStream/Primitives/FileStreams/PersistorStream.cs b/src/DataStreamSuite/DataStream/Primitives/FileStreams/PersistorStream.cs new file mode 100644 index 000000000..d991f0854 --- /dev/null +++ b/src/DataStreamSuite/DataStream/Primitives/FileStreams/PersistorStream.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using Google.Protobuf; +using System.Globalization; + +namespace BCG { + // Writes all the udpates to a stream in a file. + // File naming: + // token_epoch_yyyyMMdd_HHmmss + // File location: directory(passed)\token\ + // directory passed on, it creates a folder with the token passed + // data: + // epochtime, size, serialized data + [DataStreamUserRespresentation("pers")] + public class PersistorStream : ViewStream { + private ViewStream _source_stream; + private string _token; + private FileStream _out_fs; + private IBlueDataSerializer _serializer; + private string _file_name = String.Empty; + private long _rollover_size; + private readonly string _directory_path; + private int _n_updates_in_current_file = 0; + + public PersistorStream(ViewStream src, string token, string directory, int rollover_size) { + _source_stream = src; + _token = token; + _directory_path = directory + $@"\{token}\"; + _open_new_file(); + _rollover_size = rollover_size; + } + + protected override void myOnFirstSubscriber() { + _source_stream.onChange += _on_change; + } + + protected override void myOnLastSubscriber() { + _source_stream.onChange -= _on_change; + _out_fs.Close(); + } + + + public static DateTime parse_datetime_from_filename(string s) { + // allbooks_1697054438_2023-10-11_16-00-38 + string[] toks = s.Split("_"); + bts.Log.assert(toks.Length == 4); + string dt = $"{toks[2]}_{toks[3]}"; + return parse_datetime(dt); + } + + // this is used to parse the string passed the datetime texts passed to cons of the stream + public static DateTime parse_datetime(string s) { + // for whatever reason "yyyy-MM-dd_HH-mm-ss" is not parsable using DateTime.ParseExact (it only gets + // the Date not the time), "yyyy-MM-dd_HH:mm:ss" is parsable + // however a file name can not have : in its name, therefore we need to parse "yyyy-MM-dd_HH-mm-ss" + DateTime rv = DateTime.ParseExact(s, PersistorStream.DateTime_format, CultureInfo.InvariantCulture); + string[] toks = s.Split("_"); + string time_str = toks[1]; + string[] time_toks = time_str.Split("-"); + bts.Log.assert(time_toks.Length == 3); + int hh = Int32.Parse(time_toks[0]); + int mm = Int32.Parse(time_toks[1]); + int ss = Int32.Parse(time_toks[2]); + rv = rv.Date; + rv = rv.AddHours(hh); + rv = rv.AddMinutes(mm); + rv = rv.AddSeconds(ss); + return rv; + } + + public static string DateTime_format { + get { + return "yyyy-MM-dd_HH-mm-ss"; + } + } + + public static long dt_to_epoch(DateTime dt) { + DateTimeOffset dtos = new DateTimeOffset(dt, TimeSpan.Zero); + return dtos.ToUnixTimeSeconds(); + } + public static long epoch_now() { + return DateTimeOffset.UtcNow.ToUnixTimeSeconds(); + } + + void _on_change(object new_value) { + DataPacket dp = new_value as DataPacket; + byte[] serialized_update = null; + bool _write_create = _serializer == null || _n_updates_in_current_file == 0; + _serializer = _serializer ?? new UniversalSerializer(dp.schema); + if (_write_create) { + // new files always starts with create + _serializer.serialize(StreamOpCode.create, new IBlueRowCollection[] { dp.newRows }, out serialized_update); + } else + _serializer.serialize(StreamOpCode.multipleRemoveAdd, new IBlueRowCollection[] { dp.deletedRows, dp.addedRows }, out serialized_update); + + BinaryWriter bw = new BinaryWriter(_out_fs); + long utc_epoch = epoch_now(); + + //time, length of data, data + bw.Write(utc_epoch); + bw.Write(serialized_update.Length); + bw.Write(serialized_update); + _out_fs.Flush(); + myFireEvent(dp); + _n_updates_in_current_file++; + if (_out_fs.Length > _rollover_size) { + _close_current_and_open_new(); + } + } + + void _close_current_and_open_new() { + _out_fs.Close(); + _open_new_file(); + } + + void _open_new_file() { + var epoch = epoch_now(); + _n_updates_in_current_file = 0; + // Check if the directory was successfully created + if (!Directory.Exists(_directory_path)) { + Directory.CreateDirectory(_directory_path); + } + _file_name = $"{_directory_path}{_token}_{epoch}_{DateTime.Now.ToString(DateTime_format)}"; + _out_fs = new FileStream(_file_name, FileMode.OpenOrCreate); + } + } +} diff --git a/src/DataStreamSuite/DataStream/Primitives/FileStreams/PlaybackStream.cs b/src/DataStreamSuite/DataStream/Primitives/FileStreams/PlaybackStream.cs index 629fc149f..5a85a49e8 100644 --- a/src/DataStreamSuite/DataStream/Primitives/FileStreams/PlaybackStream.cs +++ b/src/DataStreamSuite/DataStream/Primitives/FileStreams/PlaybackStream.cs @@ -5,111 +5,184 @@ using System.Text; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using BCG.Utilities.General; -using BCG.Utilities; +using bts.collections; +using System.Reflection.Metadata; -namespace BCG -{ - public delegate void PlaybackStreamProgress(long readFar, long totalBytesRead); - public class PlaybackStream : ViewStream, IWorker - { - public PlaybackStream(string fileName) : this(fileName, 1.0) { } +namespace BCG { - private string myFileName; - private FileStream myFileReader; - private double myPlaybackSpeed; - private DateTime myPlaybackStart; - private DateTime myNextPacketTime; - private IClientDeserializer myDeserializer; - private ITableAccumulator myAccumulator; + public class PlaybackStream : ViewStream, IWorker { + private readonly PlaybackType _type; + private BlueTable _current_table; + private IClientDeserializer _deserilializer = new ClientUniversalDeserializer(); + // these are the packets already downloaded from the current file + private List _packets = new List(); + //private IEnumerable _file_streams = new List(); + private IEnumerable _file_names; + private Tuple _current_fs = new Tuple(-1, null); + private DateTime _playback_t0, _playback_t1; + private bool _all_files_read = false; + SnapshotData _snapshot_data = null; // only initialized when in snapshot mode - private BlueTable myLastTableVersion; - - public PlaybackStream(string fileName, double playbackSpeed) - { - myFileName = fileName; - myPlaybackSpeed = playbackSpeed; + public PlaybackStream(string datetime_start, string datetime_end, string directory_name, string token) { + _type = PlaybackType.Streaming; + _playback_t0 = PersistorStream.parse_datetime(datetime_start); + _playback_t1 = PersistorStream.parse_datetime(datetime_end); + string token_directory_name = $"{directory_name}\\{token}"; + bts.Log.Gen.info($"PlaybackStream t0: {_playback_t0} t1: {_playback_t1} dir: {token_directory_name}"); + List files_in_range = new List(); + if (Directory.Exists(token_directory_name)) { + _file_names = + Directory.GetFiles(token_directory_name).Where(f => { + DateTime file_time = PersistorStream.parse_datetime_from_filename(f); + return file_time > _playback_t0 && file_time < _playback_t1; + }); + } } - protected override void myOnFirstSubscriber() - { myPlaybackStart = DateTime.Now; - myNextPacketTime = DateTime.MinValue; - myFileReader = new FileStream(myFileName, FileMode.Open, FileAccess.Read, FileShare.Read); - myReadNextPacketTime(); - ViewStreamDatabase.instance.addWorker(this); + protected override void myOnFirstSubscriber() { + FileStream fs = new FileStream(_snapshot_data.snapshot_file, FileMode.Open, FileAccess.Read); + _snapshot_data.packets = StreamPersistorUtils.load_packets_from_file(fs); + PlaybackPacket snapshot_packet = StreamPersistorUtils.find_packet_at_time(_snapshot_data.packets, _snapshot_data.snapshot_time); + if (snapshot_packet != null) { + foreach (PlaybackPacket p in _snapshot_data.packets) { + byte[] ops; + Array row_array; + _deserilializer.deserialize(new Stream[] { new MemoryStream(p.data) }, out ops, out row_array); + for (int i = 0; i < ops.Length; i++) { + IBlueRowCollection[] rows_args = row_array.GetValue(i) as IBlueRowCollection[]; + byte op = ops[i]; + if (op == StreamOpCode.create) { + IBlueRowCollection full_table = rows_args[0]; + _current_table = new BlueTable(full_table); + } else if (op == StreamOpCode.multipleRemoveAdd) { + //IBlueRowCollection[] del_added = rows_args.GetValue(0) as IBlueRowCollection[]; + IBlueRowCollection dels = rows_args.GetValue(0) as IBlueRowCollection; + IBlueRowCollection adds = rows_args.GetValue(1) as IBlueRowCollection; + BlueDataUtility.absorbChanges(_current_table, dels, adds); + } else { + bts.Log.assert(false, $"Oprator: {op} is not expected"); + } + if (p.idx == snapshot_packet.idx) { + myFireEvent(new DataPacket(_current_table, _current_table, new BlueTable(_current_table.schema))); + break; + } + } + } + } } - protected override void myOnLastSubscriber() - { - if (myFileReader != null) - myFileReader.Close(); + + private void _load_packets_from_current_file() { + int curr_idx = _current_fs.Item1; + FileStream curr_fs = _current_fs.Item2; + _packets = new List(); + _packets.AddRange(StreamPersistorUtils.load_packets_from_file(curr_fs)); + } + + private bool current_file_all_replayed { + get { + bool rv = true; + _packets.ForEach(p => rv = rv && p.replayed); + return rv; + } + } + + protected override void myOnLastSubscriber() { + var fs = _current_fs.Item2; + if (fs != null) { + fs.Close(); + } ViewStreamDatabase.instance.removeWorker(this); } - protected void myReadNextPacketTime() - { - if (myFileReader.Position == myFileReader.Length) - { - myNextPacketTime = DateTime.MaxValue; - myFileReader.Dispose(); - if (onFileExhausted != null) - onFileExhausted(); - } - else - { - double secondsElapsed = new BinaryReader(myFileReader).ReadDouble(); - myNextPacketTime = myPlaybackStart + new TimeSpan(0, 0, 0, 0, (int)(1000 * secondsElapsed / myPlaybackSpeed)); - if (onProgress != null) - onProgress(myFileReader.Position, myFileReader.Length); + // public event PlaybackStreamProgress onProgress; + // public event Action onFileExhausted; + private PlaybackPacket _locate_packet_to_replay() { + foreach (var p in _packets) { + // returns the first non replayed packet + if (!p.replayed) + return p; } + return null; } - public event PlaybackStreamProgress onProgress; - public event Action onFileExhausted; - + private PlaybackPacket _get_previous_packet(PlaybackPacket p) { + if (p.idx == 0) + return null; + return _packets[p.idx - 1]; + } #region IWorker Members - public void doWork() - { - if (myNextPacketTime <= DateTime.Now) - { - if (myDeserializer == null) - { - myDeserializer = new ClientUniversalDeserializer(); - myAccumulator = new TableAccumulator(myFileName, null); - } - - BinaryReader reader = new BinaryReader(myFileReader); - int numBytes = reader.ReadInt32(); - byte[] thisData = reader.ReadBytes(numBytes); - byte[] ops; - Array resultRowCollections; - myDeserializer.deserialize(new Stream[] { new MemoryStream(thisData) }, out ops, out resultRowCollections); - - //there should only be one op in there becuae we just read a single update. - // BlueEventLog.logAssert(ops.Length == 1,"Playback stream got " +ops.Length.ToString() + " op codes in one update, from stream file "+myFileName); - //there shoudl only be one set of collections becaue there was just a single op code - //(those two arrays are parallel) - // BlueEventLog.logAssert(resultRowCollections.Length == 1, "StreamOpCode was create, serializer should return exactly 1 set of rows"); - - if (ops[0] == (byte)StreamOpCode.create) - { - myLastTableVersion = new BlueTable((resultRowCollections.GetValue(0) as IBlueRowCollection[])[0]); - myFireEvent(new DataPacket(myLastTableVersion, new BlueTable(myLastTableVersion.schema), new BlueTable(myLastTableVersion.schema))); - } - else - { - // BlueEventLog.logAssert(ops[0] == (byte)StreamOpCode.multipleRemoveAdd, "Playback stream got unexpected open code " + ops[0].ToString() + " from file " + myFileName); - // BlueEventLog.logAssert(myLastTableVersion != null, "Playback stream for file "+myFileName + "got a non-create before a create"); - IBlueRowCollection[] deletedAndAdded = resultRowCollections.GetValue(0) as IBlueRowCollection[]; - BlueDataUtility.absorbChanges(myLastTableVersion, deletedAndAdded[0], deletedAndAdded[1]); - myFireEvent(new DataPacket(myLastTableVersion, deletedAndAdded[1], deletedAndAdded[0])); - } - - myReadNextPacketTime(); + public void doWork() { + if (_all_files_read) + return; + if (current_file_all_replayed) { + _load_next_file(); } + PlaybackPacket curr_packet = _locate_packet_to_replay(); + if (curr_packet.idx == 0) { // first packet in the file, fire it rightaway + byte[] ops; + Array row_array; + // what a stupid interface! + _deserilializer.deserialize(new Stream[] { new MemoryStream(curr_packet.data) }, out ops, out row_array); + _fire_packet(ops, row_array); + curr_packet.replay_timestamp = PersistorStream.epoch_now(); + } else { + PlaybackPacket prev_packet = _get_previous_packet(curr_packet); + // this is the time we need to fire (replay) this packet + long time_to_fire = prev_packet.replay_timestamp + curr_packet.offset_from_previous; + long now_epoch = PersistorStream.epoch_now(); + // fire when we are past the + if (now_epoch >= time_to_fire) { + byte[] ops; + Array row_array; + _deserilializer.deserialize(new Stream[] { new MemoryStream(curr_packet.data) }, out ops, out row_array); + _fire_packet(ops, row_array); + curr_packet.replay_timestamp = PersistorStream.epoch_now(); + } + } + } + private void _fire_packet(byte[] ops, Array row_array) { + for (int i = 0; i < ops.Length; i++) { + IBlueRowCollection[] rows_args = row_array.GetValue(i) as IBlueRowCollection[]; + byte op = ops[i]; + if (op == StreamOpCode.create) { + IBlueRowCollection full_table = rows_args[0]; + _current_table = new BlueTable(full_table); + //_current_table.addRows(full_table); + myFireEvent(new DataPacket(full_table, full_table, myLastValue == null ? new BlueTable(full_table.schema) : + (myLastValue as DataPacket).newRows)); + } else if (op == StreamOpCode.multipleRemoveAdd) { + //IBlueRowCollection[] del_added = rows_args.GetValue(0) as IBlueRowCollection[]; + IBlueRowCollection dels = rows_args.GetValue(0) as IBlueRowCollection; + IBlueRowCollection adds = rows_args.GetValue(1) as IBlueRowCollection; + BlueDataUtility.absorbChanges(_current_table, dels, adds); + myFireEvent(new DataPacket(_current_table, adds, dels)); + } else { + bts.Log.assert(false, $"Oprator: {op} is not expected"); + } + + } + } + + private void _load_next_file() { + var new_idx = _current_fs.Item1 + 1; + if (new_idx >= _file_names.Count()) { + _all_files_read = true; + bts.Log.Gen.info("All files read"); + return; + } + var prev_fs = _current_fs.Item2; + if (prev_fs != null) + prev_fs.Close(); + var new_filename = _file_names.ElementAt(new_idx); + bts.Log.Gen.info("PlaybackStream_load_next_file new_filename=: {new_filename}"); + var new_fs = new FileStream(new_filename, FileMode.Open, FileAccess.Read); + _current_fs = new Tuple(new_idx, new_fs); + _load_packets_from_current_file(); } #endregion diff --git a/src/DataStreamSuite/DataStream/Primitives/FileStreams/SnapshotStream.cs b/src/DataStreamSuite/DataStream/Primitives/FileStreams/SnapshotStream.cs new file mode 100644 index 000000000..a549c13e8 --- /dev/null +++ b/src/DataStreamSuite/DataStream/Primitives/FileStreams/SnapshotStream.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using BCG.Utilities.General; +using bts.collections; +using System.Reflection.Metadata; + + +namespace BCG { + public class SnapshotStream : ViewStream { + + private BlueTable _current_table; + private IClientDeserializer _deserilializer = new ClientUniversalDeserializer(); + public DateTime _snapshot_time; + public string _snapshot_file; + public IEnumerable _packets; + + + public SnapshotStream(string snapshot_dt, string directory_name, string token) { + _snapshot_time = PersistorStream.parse_datetime(snapshot_dt); + string token_directory_name = $"{directory_name}\\{token}"; + _snapshot_file = StreamPersistorUtils.find_snapshot_file(token_directory_name, _snapshot_time); + } + + protected override void myOnFirstSubscriber() { + FileStream fs = new FileStream(_snapshot_file, FileMode.Open, FileAccess.Read); + _packets = StreamPersistorUtils.load_packets_from_file(fs); + PlaybackPacket snapshot_packet = StreamPersistorUtils.find_packet_at_time(_packets, _snapshot_time); + if (snapshot_packet != null) { + foreach (PlaybackPacket p in _packets) { + byte[] ops; + Array row_array; + _deserilializer.deserialize(new Stream[] { new MemoryStream(p.data) }, out ops, out row_array); + for (int i = 0; i < ops.Length; i++) { + IBlueRowCollection[] rows_args = row_array.GetValue(i) as IBlueRowCollection[]; + byte op = ops[i]; + if (op == StreamOpCode.create) { + IBlueRowCollection full_table = rows_args[0]; + _current_table = new BlueTable(full_table); + } else if (op == StreamOpCode.multipleRemoveAdd) { + //IBlueRowCollection[] del_added = rows_args.GetValue(0) as IBlueRowCollection[]; + IBlueRowCollection dels = rows_args.GetValue(0) as IBlueRowCollection; + IBlueRowCollection adds = rows_args.GetValue(1) as IBlueRowCollection; + BlueDataUtility.absorbChanges(_current_table, dels, adds); + } else { + bts.Log.assert(false, $"Oprator: {op} is not expected"); + } + if (p.idx == snapshot_packet.idx) { + myFireEvent(new DataPacket(_current_table, _current_table, new BlueTable(_current_table.schema))); + break; + } + } + } + } + } + + private void _absorb_packet(byte[] ops, Array row_array) { + for (int i = 0; i < ops.Length; i++) { + IBlueRowCollection[] rows_args = row_array.GetValue(i) as IBlueRowCollection[]; + byte op = ops[i]; + if (op == StreamOpCode.create) { + IBlueRowCollection full_table = rows_args[0]; + _current_table = new BlueTable(full_table); + } else if (op == StreamOpCode.multipleRemoveAdd) { + //IBlueRowCollection[] del_added = rows_args.GetValue(0) as IBlueRowCollection[]; + IBlueRowCollection dels = rows_args.GetValue(0) as IBlueRowCollection; + IBlueRowCollection adds = rows_args.GetValue(1) as IBlueRowCollection; + BlueDataUtility.absorbChanges(_current_table, dels, adds); + } else { + bts.Log.assert(false, $"Operator: {op} is not expected"); + } + } + } + + protected override void myOnLastSubscriber() { + } + + // public event SnapshotStream.Progress onProgress; + // public event Action onFileExhausted; + private PlaybackPacket _locate_packet_to_replay() { + foreach (var p in _packets) { + // returns the first non replayed packet + if (!p.replayed) + return p; + } + return null; + } + + private void _fire_packet(byte[] ops, Array row_array) { + for (int i = 0; i < ops.Length; i++) { + IBlueRowCollection[] rows_args = row_array.GetValue(i) as IBlueRowCollection[]; + byte op = ops[i]; + if (op == StreamOpCode.create) { + IBlueRowCollection full_table = rows_args[0]; + _current_table = new BlueTable(full_table); + //_current_table.addRows(full_table); + myFireEvent(new DataPacket(full_table, full_table, myLastValue == null ? new BlueTable(full_table.schema) : + (myLastValue as DataPacket).newRows)); + } else if (op == StreamOpCode.multipleRemoveAdd) { + //IBlueRowCollection[] del_added = rows_args.GetValue(0) as IBlueRowCollection[]; + IBlueRowCollection dels = rows_args.GetValue(0) as IBlueRowCollection; + IBlueRowCollection adds = rows_args.GetValue(1) as IBlueRowCollection; + BlueDataUtility.absorbChanges(_current_table, dels, adds); + myFireEvent(new DataPacket(_current_table, adds, dels)); + } else { + bts.Log.assert(false, $"Oprator: {op} is not expected"); + } + + } + } + } +} \ No newline at end of file diff --git a/src/DataStreamSuite/DataStream/Primitives/FileStreams/StreamPersistorUtils.cs b/src/DataStreamSuite/DataStream/Primitives/FileStreams/StreamPersistorUtils.cs new file mode 100644 index 000000000..8ef7267b0 --- /dev/null +++ b/src/DataStreamSuite/DataStream/Primitives/FileStreams/StreamPersistorUtils.cs @@ -0,0 +1,145 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Globalization; +using System.IO; + + +namespace BCG { + // each stream op in the replay file is reprsented by a packet here + public class PlaybackPacket { + public readonly int idx; + public readonly long timestamp; + public readonly byte[] data; + public long replay_timestamp = 0; // non zero it has been replayed + public long offset_from_previous = 0; + public PlaybackPacket(int the_idx, long the_timestamp, byte[] the_data) { + this.idx = the_idx; + this.timestamp = the_timestamp; + this.data = the_data; + } + public bool replayed { + get { return replay_timestamp != 0; } + } + } + + public enum PlaybackType { + Streaming = 0, + Snapshot + } + public class SnapshotData { + public DateTime snapshot_time; + public string snapshot_file; + public SnapshotData(DateTime snapshot_time_arg, string snapshot_file_arg) { + snapshot_time = snapshot_time_arg; + snapshot_file = snapshot_file_arg; + } + public IEnumerable packets = new List(); + } + public static class StreamPersistorUtils { + public static string find_snapshot_file(string directory_name, DateTime snapshot_time) { + string[] file_names = Directory.GetFiles(directory_name); + for (int i = 0; i < file_names.Count() - 1; i++) { + string fn = file_names[i]; + string next_fn = file_names[i + 1]; + DateTime f_dt = PersistorStream.parse_datetime_from_filename(fn); + DateTime next_f_dt = PersistorStream.parse_datetime_from_filename(next_fn); + if (snapshot_time >= f_dt && snapshot_time <= next_f_dt) { + return fn; + } + } + return String.Empty; + } + public static DateTime parse_datetime_from_filename(string s) { + // allbooks_1697054438_2023-10-11_16-00-38 + string[] toks = s.Split("_"); + bts.Log.assert(toks.Length == 4); + string dt = $"{toks[2]}_{toks[3]}"; + return parse_datetime(dt); + } + + // this is used to parse the string passed the datetime texts passed to cons of the stream + public static DateTime parse_datetime(string s) { + // for whatever reason "yyyy-MM-dd_HH-mm-ss" is not parsable using DateTime.ParseExact (it only gets + // the Date not the time), "yyyy-MM-dd_HH:mm:ss" is parsable + // however a file name can not have : in its name, therefore we need to parse "yyyy-MM-dd_HH-mm-ss" + DateTime rv = DateTime.ParseExact(s, PersistorStream.DateTime_format, CultureInfo.InvariantCulture); + string[] toks = s.Split("_"); + string time_str = toks[1]; + string[] time_toks = time_str.Split("-"); + bts.Log.assert(time_toks.Length == 3); + int hh = Int32.Parse(time_toks[0]); + int mm = Int32.Parse(time_toks[1]); + int ss = Int32.Parse(time_toks[2]); + rv = rv.Date; + rv = rv.AddHours(hh); + rv = rv.AddMinutes(mm); + rv = rv.AddSeconds(ss); + return rv; + } + + public static string DateTime_format { + get { + return "yyyy-MM-dd_HH-mm-ss"; + } + } + + public static long dt_to_epoch(DateTime dt) { + DateTimeOffset dtos = new DateTimeOffset(dt, TimeSpan.Zero); + return dtos.ToUnixTimeSeconds(); + } + public static long epoch_now() { + return DateTimeOffset.UtcNow.ToUnixTimeSeconds(); + } + public static DateTime epoch_to_dt(long epoch_seconds) { + return DateTimeOffset.FromUnixTimeSeconds(epoch_seconds).DateTime; + } + + public static PlaybackPacket find_packet_at_time(IEnumerable packets, DateTime snapshot_time) { + log_file_ts(packets, snapshot_time); + long snapshot_time_epoch = PersistorStream.dt_to_epoch(snapshot_time); + for (int i = 0; i < packets.Count() - 1; i++) { + PlaybackPacket curr_p = packets.ElementAt(i); + PlaybackPacket next_p = packets.ElementAt(i + 1); + if (curr_p.timestamp <= snapshot_time_epoch && next_p.timestamp >= snapshot_time_epoch) { + return curr_p; + } + } + // if for some reason it cant find it, send the last packet + return packets.Last(); + } + + private static void log_file_ts(IEnumerable packets, DateTime snapshot_time) { + string big_log_msg = String.Empty; + foreach (var p in packets) { + big_log_msg += $"packet idx: {p.idx} epoch_ts: {p.timestamp} ts: {epoch_to_dt(p.timestamp)} snapshot_time: {snapshot_time}"; + big_log_msg += "\n"; + } + bts.Log.Gen.info($"Packets: {big_log_msg}"); + } + + public static IEnumerable load_packets_from_file(FileStream fs) { + BinaryReader br = new BinaryReader(fs); + List rv = new List(); + while (fs.Position < fs.Length) { + try { + long ts = br.ReadInt64(); + int sz = br.ReadInt32(); + byte[] data = br.ReadBytes(sz); + var pb = new PlaybackPacket(rv.Count, ts, data); + rv.Add(pb); + } catch (Exception ex) { + bts.Log.Gen.error($"ex: {ex}"); + break; + } + } + // setting offset field + for (int i = 0; i < rv.Count; i++) { + if (i == 0) + continue; + rv[i].offset_from_previous = rv[i].timestamp - rv[i - 1].timestamp; + } + return rv; + } + } +} \ No newline at end of file diff --git a/src/DataStreamSuite/DataStream/Primitives/Misc/DebugStream.cs b/src/DataStreamSuite/DataStream/Primitives/Misc/DebugStream.cs new file mode 100644 index 000000000..3543fac6a --- /dev/null +++ b/src/DataStreamSuite/DataStream/Primitives/Misc/DebugStream.cs @@ -0,0 +1,46 @@ + + +using System; + +namespace BCG { + // Keeps adding changing rows to the stream, hence preserving the history + // and creating a time series, for example this can be used to make bbo updates + // into a time series of prices/qty + public class DebugStream : ViewStream { + + private ViewStream _stream; + private IBlueRowCollection _last_recv_rows = null; + + public DebugStream(ViewStream stream) { + _stream = stream; + } + + protected override void myOnFirstSubscriber() { + _stream.onChange += new ChangeDelegate(_onstream_change); + } + protected override void myOnLastSubscriber() { + _stream.onChange -= new ChangeDelegate(_onstream_change); + } + + private void _onstream_change(object o) { + DataPacket dp = o as DataPacket; + if (_last_recv_rows == null) { + _last_recv_rows = dp.newRows; + } else { + //schema + bts.Log.assert(BlueDataUtility.compareSchemas(_last_recv_rows.schema, dp.newRows.schema)); + bts.Log.assert(BlueDataUtility.compareSchemas(_last_recv_rows.schema, dp.addedRows.schema)); + bts.Log.assert(BlueDataUtility.compareSchemas(_last_recv_rows.schema, dp.deletedRows.schema)); + foreach (IBlueRow r in dp.deletedRows) { + bts.Log.assert(_last_recv_rows.containsID(r.get("id"))); + } + foreach (IBlueRow r in dp.addedRows) { + bts.Log.assert(dp.newRows.containsID(r.get("id"))); + } + _last_recv_rows = dp.newRows; + } + myFireEvent(o); + + } + } +} \ No newline at end of file diff --git a/src/DataStreamSuite/DataStream/Primitives/Misc/TimeSeriesStream.cs b/src/DataStreamSuite/DataStream/Primitives/Misc/TimeSeriesStream.cs new file mode 100644 index 000000000..5ea4537ff --- /dev/null +++ b/src/DataStreamSuite/DataStream/Primitives/Misc/TimeSeriesStream.cs @@ -0,0 +1,45 @@ +using Google.Protobuf.WellKnownTypes; + +using System; + +namespace BCG { + // Keeps adding changing rows to the stream, hence preserving the history + // and creating a time series, for example this can be used to make bbo updates + // into a time series of prices/qty + public class TimeSeriesStream : ViewStream { + private BlueTable _table; + private ViewStream _stream; + private int _id = 0; + + public TimeSeriesStream(ViewStream stream) { + _stream = stream; + } + + protected override void myOnFirstSubscriber() { + _stream.onChange += new ChangeDelegate(_onstream_change); + } + protected override void myOnLastSubscriber() { + _stream.onChange -= new ChangeDelegate(_onstream_change); + } + + private void _onstream_change(object o) { + DataPacket dp = o as DataPacket; + DateTime now = DateTime.Now; + if (_table == null) { + IBlueTableSchema schema = new BlueTableSchema(dp.newRows.schema.columnInfo, dp.newRows.schema.tableName); + schema = schema.add_columns(Tuple.Create(typeof(DateTime), "timestamp")); + _table = new BlueTable(schema); + } + BlueTable added_rows = new BlueTable(_table.schema); + foreach (IBlueRow r in dp.addedRows) { + MutableBlueRow ar = new MutableBlueRow(_table.schema, r); + ar.setValue("timestamp", now); + ar.setValue("id", _id++); + added_rows.addRow(ar); + } + _table.addRows(added_rows); + myFireEvent(new DataPacket(_table, added_rows, new BlueTable(_table.schema))); + + } + } +} \ No newline at end of file diff --git a/src/DataStreamSuite/DataStream/Primitives/Time/DateStandardizationStream.cs b/src/DataStreamSuite/DataStream/Primitives/Time/DateStandardizationStream.cs new file mode 100644 index 000000000..7fe43313c --- /dev/null +++ b/src/DataStreamSuite/DataStream/Primitives/Time/DateStandardizationStream.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections.Generic; +using System.Text; + + +namespace BCG +{ + /// + /// If one adds annother value to this enum, be sure to update _date_conversion_to_type_map below as well + /// + public enum DateConversion + { + ConvertDoubleToDateTime = 0, + ChopTime, + UTCToCurrent, + ConvertStringToDateTime, + ConvertDateTimeToMilliseconds, + SecondsOfDay + } + + [DataStreamUserRespresentation("dateStandardize")] + public class DateStandardizationStream : ViewStream, IStreamMapper + { + private IBlueTableSchema mySchema; + private DateConversion myConversion; + private string myConversionColName; + private readonly Dictionary _date_conversion_to_type_map = new Dictionary() + { + {DateConversion.ConvertDoubleToDateTime , typeof(DateTime)}, + {DateConversion.ChopTime , typeof(DateTime)}, + {DateConversion.UTCToCurrent , typeof(DateTime)}, + {DateConversion.ConvertStringToDateTime , typeof(DateTime)}, + {DateConversion.ConvertDateTimeToMilliseconds, typeof(Double)}, + {DateConversion.SecondsOfDay , typeof(Double)} + }; + + + private static DateConversion _parse(string s) + { + DateConversion rv = DateConversion.ChopTime; + Enum.TryParse(s, false, out rv); + return rv; + } + /// + /// for DSQA + /// + public DateStandardizationStream(ViewStream vs, string colName, string conversion) + : this(vs, colName, _parse(conversion)) + { } + + public DateStandardizationStream(ViewStream vs, string colName, DateConversion conversion) + { + myConversionColName = colName; + myConversion = conversion; + mySetRealSource(new MapStream(vs, this)); + } + + #region IStreamMapper Members + + public IBlueTableSchema getOutputSchema(IBlueTableSchema inputSchema) + { + if (mySchema == null) + { + List cis = new List(); + foreach (ColumnInfo c in inputSchema.columnInfo) + { + if (c.colName == myConversionColName) + { + Type convType; + if (!_date_conversion_to_type_map.TryGetValue(myConversion, out convType)) + { + //BCG.Utilities.BlueEventLog.logEvent("Please update the _date_conversion_to_type_map in DateStandardizationStream.cs.", BCG.Utilities.BlueEventLevel.Error); + convType = typeof(DateTime); + } + cis.Add(new ColumnInfo(c.colName, c.colNo, convType)); + } + else + cis.Add(new ColumnInfo(c.colName, c.colNo, c.colType)); + } + mySchema = new BlueTableSchema(inputSchema.tableName, cis.ToArray()); + } + return mySchema; + } + + #endregion + + #region IDynamicStreamMapper Members + + public IBlueRow map(IBlueRow row) + { + return BlueDataUtility.getNewReplacedRow(row, mapDateTime(row[myConversionColName], myConversion), myConversionColName); + } + + #endregion + + public static object mapDateTime(object objIn, DateConversion conv) + { + if (objIn == DBNull.Value || objIn == null) + { + return DBNull.Value; + } + else + { + if (conv == DateConversion.ChopTime) + { + DateTime dtIn = (DateTime)objIn; + return dtIn.Date; + } + else if (conv == DateConversion.ConvertDoubleToDateTime) + { + double dtIn = (double)objIn; + return DateTime.FromOADate(dtIn); + } + else if (conv == DateConversion.UTCToCurrent) + { + DateTime dtIn = (DateTime)objIn; + return dtIn.ToLocalTime(); + } + else if (conv == DateConversion.ConvertStringToDateTime) + { + return DateTime.Parse((string)objIn); + } + else if (conv == DateConversion.ConvertDateTimeToMilliseconds) + { + DateTime dtIn = (DateTime)objIn; + return dtIn.TimeOfDay.TotalMilliseconds; + } + else if (conv == DateConversion.SecondsOfDay) + { + DateTime dtIn = (DateTime)objIn; + DateTime start_of_day = dtIn.Date; + TimeSpan day_period = dtIn - start_of_day; + return day_period.TotalSeconds; + } + else + { + bts.Log.Gen.info("incorrect type"); + return null; + } + } + } + } +} \ No newline at end of file diff --git a/src/DataStreamSuite/DataStreamCore/BlueData/BlueDataUtility.cs b/src/DataStreamSuite/DataStreamCore/BlueData/BlueDataUtility.cs index 1a90eb793..87db76f18 100644 --- a/src/DataStreamSuite/DataStreamCore/BlueData/BlueDataUtility.cs +++ b/src/DataStreamSuite/DataStreamCore/BlueData/BlueDataUtility.cs @@ -34,6 +34,18 @@ namespace BCG { public static T get(this IBlueRow r, int col_no, T err_value = default(T)) { return get_row_value(r, col_no, err_value); } + public static IEnumerable get_covalues(this IBlueRowCollection rows, string col) { + List rv = new List(); + foreach (IBlueRow r in rows) + rv.Add(r.get(col)); + return rv; + } + public static IEnumerable get_covalues(IEnumerable rows, string col) { + List rv = new List(); + foreach (IBlueRow r in rows) + rv.Add(r.get(col)); + return rv; + } public static IBlueRowCollection where(this IBlueRowCollection rows, Func where_func) { if (rows == null) diff --git a/src/DataStreamSuite/DataStreamCore/DynamicLoading/PrimitiveManager.cs b/src/DataStreamSuite/DataStreamCore/DynamicLoading/PrimitiveManager.cs index 047dd79b8..14a74816a 100644 --- a/src/DataStreamSuite/DataStreamCore/DynamicLoading/PrimitiveManager.cs +++ b/src/DataStreamSuite/DataStreamCore/DynamicLoading/PrimitiveManager.cs @@ -22,8 +22,11 @@ namespace BCG { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += new ResolveEventHandler(myAssemblyResolver); loadAssembly(this.GetType().Assembly.FullName); - var assemblies = new string[] { "datastream.dll", "datastreamcore.dll" }; - foreach (string assemblyName in Configuration.get().Assemblies) { + var assemblies = new string[] { "datastream.dll", "sharedstreams.dll" }; + var config_assemblies = Configuration.get().Assemblies; + bts.Log.Gen.info($"PrimitiveManager.myLoadAllTypes config_assemblies: {config_assemblies}"); + foreach (string assemblyName in assemblies/*config_assemblies*/) { + bts.Log.Gen.info($"PrimitiveManager.myLoadAllTypes assemblyName: {assemblyName}"); string resolvedAssemblyPath = assemblyName; if (!System.IO.Path.IsPathRooted(assemblyName)) { string appPath = Path.GetDirectoryName( diff --git a/src/DataStreamSuite/DataStreamPublisher/DataStreamPublisher.csproj b/src/DataStreamSuite/DataStreamPublisher/DataStreamPublisher.csproj index de755eb51..c28c33ec4 100644 --- a/src/DataStreamSuite/DataStreamPublisher/DataStreamPublisher.csproj +++ b/src/DataStreamSuite/DataStreamPublisher/DataStreamPublisher.csproj @@ -5,6 +5,7 @@ + diff --git a/src/DataStreamSuite/DataStreamPublisher/Program.cs b/src/DataStreamSuite/DataStreamPublisher/Program.cs index 1b2536cee..1775b0fa2 100644 --- a/src/DataStreamSuite/DataStreamPublisher/Program.cs +++ b/src/DataStreamSuite/DataStreamPublisher/Program.cs @@ -1,29 +1,33 @@ using System; +using System.Threading.Tasks; using BCG; -bts.utils.BTSNativeMethods.provide_command_line(new string[] { }, 0); +bts.utils.BTSNativeMethods.provide_command_line(args, args.Length); mbts.config.Configuration.initialize(); bts.Log.Gen.info($"Starting DSPublisher"); Console.WriteLine("Starting DSPublisher..."); -// SimpleTCPClient.start("127.0.0.1", 12345); -// Task.Delay(1000000000).Wait(); - -//TestPubliser.publish(); -//TestPubliser.subscribe(); -// TestPublisher ts = new TestPublisher(false); -// ts.keep_publishing(TimeSpan.FromSeconds(10)); - +// static async Task _run() { +// var login = "bts"; +// var passwd = String.Empty; +// Console.WriteLine("Starting DSQA... "); +// // Log.notnull(login); +// // Log.notnull(passwd); +// // var service_ctx = bts.api.core.ServiceContext.create(); +// await service_ctx.login(login, passwd); +// } +//Task.Run(async () => await _run()); _publish_stream(); void _publish_stream() { - BCG.ViewStream vs = new LiteralStream("x", "420.0"); + + BCG.ViewStream vs = new LiteralStream("x", "420.0");// new BBOStream(); + //new BCG.MDStream(); ViewPublisher vpub = new ViewPublisher(String.Empty, new PubTableBroker(), vs); vs.onChange += on_change; } - while (true) { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); ViewStreamDatabase.instance.doWork(); diff --git a/src/DataStreamSuite/DataStreamQueryAnalyzer/HScrollGrid.resx b/src/DataStreamSuite/DataStreamQueryAnalyzer/HScrollGrid.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/src/DataStreamSuite/DataStreamQueryAnalyzer/HScrollGrid.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.Designer.cs b/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.Designer.cs index e26fa6ce6..c5c89cf52 100644 --- a/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.Designer.cs +++ b/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.Designer.cs @@ -1,11 +1,16 @@ -namespace BCG { - public partial class MainForm { +namespace BCG +{ + public partial class MainForm + { /// /// Clean up any resources being used. /// - protected override void Dispose(bool disposing) { - if (disposing) { - if (components != null) { + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (components != null) + { components.Dispose(); } } @@ -17,499 +22,549 @@ /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// - private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); - this.myQueryTextBox = new System.Windows.Forms.RichTextBox(); - this.myTabControl = new System.Windows.Forms.TabControl(); - this.myViewTabPage = new System.Windows.Forms.TabPage(); - this.myDataGrid = new BCG.HScrollGrid(); - this.myCSharpTabPage = new System.Windows.Forms.TabPage(); - this.myCSharpText = new System.Windows.Forms.RichTextBox(); - this.myErrorTabPage = new System.Windows.Forms.TabPage(); - this.myErrorTextBox = new System.Windows.Forms.RichTextBox(); - this.myTableListTabPage = new System.Windows.Forms.TabPage(); - this.myTableListBox = new BCG.Utilities.XPControls.ListBoxXP(); - this.myTableListTopPanel = new System.Windows.Forms.Panel(); - this.myTableFilterBox = new System.Windows.Forms.TextBox(); - this.myTableFilterLabel = new System.Windows.Forms.Label(); - this.myPrimitivesPage = new System.Windows.Forms.TabPage(); - this.myTreeView = new System.Windows.Forms.TreeView(); - this.myConsoleTabPage = new System.Windows.Forms.TabPage(); - this.myConsoleRichTextBox = new System.Windows.Forms.RichTextBox(); - this.myTimer = new System.Windows.Forms.Timer(this.components); - this.mySplitter = new System.Windows.Forms.Splitter(); - this.myStatusStrip = new System.Windows.Forms.StatusStrip(); - this.myToolStripStatusLabelTime = new System.Windows.Forms.ToolStripStatusLabel(); - this.myToolStripStatusLabelRows = new System.Windows.Forms.ToolStripStatusLabel(); - this.myMenuStrip = new System.Windows.Forms.MenuStrip(); - this.myToolStripMenuItemFile = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemOpen = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemSave = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemSaveAs = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemExit = new System.Windows.Forms.ToolStripMenuItem(); - this.testGridToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemQuery = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemExecute = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemExecSel = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemFreeze = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemStep = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemTools = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemLoadAss = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemTest = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemToolsSep = new System.Windows.Forms.ToolStripSeparator(); - this.myToolStripMenuItemClearConsole = new System.Windows.Forms.ToolStripMenuItem(); - this.myToolStripMenuItemSite = new System.Windows.Forms.ToolStripMenuItem(); - this.libraryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.myTabControl.SuspendLayout(); - this.myViewTabPage.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.myDataGrid)).BeginInit(); - this.myCSharpTabPage.SuspendLayout(); - this.myErrorTabPage.SuspendLayout(); - this.myTableListTabPage.SuspendLayout(); - this.myTableListTopPanel.SuspendLayout(); - this.myPrimitivesPage.SuspendLayout(); - this.myConsoleTabPage.SuspendLayout(); - this.myStatusStrip.SuspendLayout(); - this.myMenuStrip.SuspendLayout(); - this.SuspendLayout(); + myQueryTextBox = new System.Windows.Forms.RichTextBox(); + myTabControl = new System.Windows.Forms.TabControl(); + myViewTabPage = new System.Windows.Forms.TabPage(); + myDataGrid = new HScrollGrid(); + myCSharpTabPage = new System.Windows.Forms.TabPage(); + myCSharpText = new System.Windows.Forms.RichTextBox(); + myErrorTabPage = new System.Windows.Forms.TabPage(); + myErrorTextBox = new System.Windows.Forms.RichTextBox(); + myTableListTabPage = new System.Windows.Forms.TabPage(); + myTableListBox = new Utilities.XPControls.ListBoxXP(); + myTableListTopPanel = new System.Windows.Forms.Panel(); + myTableFilterBox = new System.Windows.Forms.TextBox(); + myTableFilterLabel = new System.Windows.Forms.Label(); + myPrimitivesPage = new System.Windows.Forms.TabPage(); + myTreeView = new System.Windows.Forms.TreeView(); + myConsoleTabPage = new System.Windows.Forms.TabPage(); + myConsoleRichTextBox = new System.Windows.Forms.RichTextBox(); + myTimer = new System.Windows.Forms.Timer(components); + mySplitter = new System.Windows.Forms.Splitter(); + myStatusStrip = new System.Windows.Forms.StatusStrip(); + myToolStripStatusLabelTime = new System.Windows.Forms.ToolStripStatusLabel(); + myToolStripStatusLabelRows = new System.Windows.Forms.ToolStripStatusLabel(); + toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); + myMenuStrip = new System.Windows.Forms.MenuStrip(); + myToolStripMenuItemFile = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemOpen = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemSave = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemSaveAs = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemExit = new System.Windows.Forms.ToolStripMenuItem(); + testGridToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemQuery = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemExecute = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemExecSel = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemFreeze = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemStep = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemTools = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemLoadAss = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemTest = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemToolsSep = new System.Windows.Forms.ToolStripSeparator(); + myToolStripMenuItemClearConsole = new System.Windows.Forms.ToolStripMenuItem(); + myToolStripMenuItemSite = new System.Windows.Forms.ToolStripMenuItem(); + libraryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + myTabControl.SuspendLayout(); + myViewTabPage.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)myDataGrid).BeginInit(); + myCSharpTabPage.SuspendLayout(); + myErrorTabPage.SuspendLayout(); + myTableListTabPage.SuspendLayout(); + myTableListTopPanel.SuspendLayout(); + myPrimitivesPage.SuspendLayout(); + myConsoleTabPage.SuspendLayout(); + myStatusStrip.SuspendLayout(); + myMenuStrip.SuspendLayout(); + SuspendLayout(); // // myQueryTextBox // - this.myQueryTextBox.AutoWordSelection = true; - this.myQueryTextBox.BackColor = System.Drawing.Color.White; - this.myQueryTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.myQueryTextBox.Dock = System.Windows.Forms.DockStyle.Top; - this.myQueryTextBox.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.myQueryTextBox.ForeColor = System.Drawing.Color.Black; - this.myQueryTextBox.Location = new System.Drawing.Point(0, 24); - this.myQueryTextBox.Name = "myQueryTextBox"; - this.myQueryTextBox.Size = new System.Drawing.Size(904, 208); - this.myQueryTextBox.TabIndex = 0; - this.myQueryTextBox.Text = ""; + myQueryTextBox.AutoWordSelection = true; + myQueryTextBox.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myQueryTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None; + myQueryTextBox.Dock = System.Windows.Forms.DockStyle.Top; + myQueryTextBox.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + myQueryTextBox.ForeColor = System.Drawing.Color.White; + myQueryTextBox.Location = new System.Drawing.Point(0, 24); + myQueryTextBox.Name = "myQueryTextBox"; + myQueryTextBox.Size = new System.Drawing.Size(904, 208); + myQueryTextBox.TabIndex = 0; + myQueryTextBox.Text = ""; // // myTabControl // - this.myTabControl.Appearance = System.Windows.Forms.TabAppearance.FlatButtons; - this.myTabControl.Controls.Add(this.myViewTabPage); - this.myTabControl.Controls.Add(this.myCSharpTabPage); - this.myTabControl.Controls.Add(this.myErrorTabPage); - this.myTabControl.Controls.Add(this.myTableListTabPage); - this.myTabControl.Controls.Add(this.myPrimitivesPage); - this.myTabControl.Controls.Add(this.myConsoleTabPage); - this.myTabControl.Dock = System.Windows.Forms.DockStyle.Fill; - this.myTabControl.Location = new System.Drawing.Point(0, 232); - this.myTabControl.Multiline = true; - this.myTabControl.Name = "myTabControl"; - this.myTabControl.SelectedIndex = 0; - this.myTabControl.Size = new System.Drawing.Size(904, 335); - this.myTabControl.TabIndex = 1; + myTabControl.Appearance = System.Windows.Forms.TabAppearance.FlatButtons; + myTabControl.Controls.Add(myViewTabPage); + myTabControl.Controls.Add(myCSharpTabPage); + myTabControl.Controls.Add(myErrorTabPage); + myTabControl.Controls.Add(myTableListTabPage); + myTabControl.Controls.Add(myPrimitivesPage); + myTabControl.Controls.Add(myConsoleTabPage); + myTabControl.Dock = System.Windows.Forms.DockStyle.Fill; + myTabControl.Location = new System.Drawing.Point(0, 232); + myTabControl.Multiline = true; + myTabControl.Name = "myTabControl"; + myTabControl.SelectedIndex = 0; + myTabControl.Size = new System.Drawing.Size(904, 335); + myTabControl.TabIndex = 1; // // myViewTabPage // - this.myViewTabPage.Controls.Add(this.myDataGrid); - this.myViewTabPage.Location = new System.Drawing.Point(4, 26); - this.myViewTabPage.Name = "myViewTabPage"; - this.myViewTabPage.Size = new System.Drawing.Size(896, 305); - this.myViewTabPage.TabIndex = 0; - this.myViewTabPage.Text = "View"; + myViewTabPage.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myViewTabPage.Controls.Add(myDataGrid); + myViewTabPage.ForeColor = System.Drawing.Color.White; + myViewTabPage.Location = new System.Drawing.Point(4, 26); + myViewTabPage.Name = "myViewTabPage"; + myViewTabPage.Size = new System.Drawing.Size(896, 305); + myViewTabPage.TabIndex = 0; + myViewTabPage.Text = "View"; // // myDataGrid // - this.myDataGrid.BackgroundColor = System.Drawing.Color.Gainsboro; - this.myDataGrid.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - // this.myDataGrid.CaptionBackColor = System.Drawing.Color.Wheat; - // this.myDataGrid.CaptionFont = new System.Drawing.Font("Comic Sans MS", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - // this.myDataGrid.CaptionForeColor = System.Drawing.Color.Black; - this.myDataGrid.DataMember = ""; - this.myDataGrid.Dock = System.Windows.Forms.DockStyle.Fill; - // this.myDataGrid.FlatMode = true; - // this.myDataGrid.GridLineColor = System.Drawing.Color.Gainsboro; - // this.myDataGrid.HeaderBackColor = System.Drawing.Color.Gainsboro; - // this.myDataGrid.HeaderFont = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - // this.myDataGrid.HeaderForeColor = System.Drawing.Color.Black; - this.myDataGrid.HorizScrollBarValue = 0; - this.myDataGrid.Location = new System.Drawing.Point(0, 0); - this.myDataGrid.Name = "myDataGrid"; - // this.myDataGrid.PreferredRowHeight = 20; - this.myDataGrid.ReadOnly = true; - this.myDataGrid.RowHeadersVisible = false; - // this.myDataGrid.RowHeaderWidth = 0; - this.myDataGrid.Size = new System.Drawing.Size(896, 305); - this.myDataGrid.TabIndex = 0; - this.myDataGrid.MouseEnter += new System.EventHandler(this.myDataGrid_MouseEnter); - this.myDataGrid.MouseLeave += new System.EventHandler(this.myDataGrid_MouseLeave); + myDataGrid.BackgroundColor = System.Drawing.Color.FromArgb(36, 36, 49); + myDataGrid.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; + myDataGrid.ColumnHeadersHeight = 32; + dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + dataGridViewCellStyle1.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle1.ForeColor = System.Drawing.Color.White; + dataGridViewCellStyle1.SelectionBackColor = System.Drawing.Color.Green; + dataGridViewCellStyle1.SelectionForeColor = System.Drawing.Color.Yellow; + dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + myDataGrid.DefaultCellStyle = dataGridViewCellStyle1; + myDataGrid.Dock = System.Windows.Forms.DockStyle.Fill; + myDataGrid.GridColor = System.Drawing.Color.DarkGray; + myDataGrid.HorizScrollBarValue = 0; + myDataGrid.Location = new System.Drawing.Point(0, 0); + myDataGrid.Name = "myDataGrid"; + myDataGrid.ReadOnly = true; + myDataGrid.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; + dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle2.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White; + dataGridViewCellStyle2.SelectionBackColor = System.Drawing.Color.Yellow; + dataGridViewCellStyle2.SelectionForeColor = System.Drawing.Color.DimGray; + dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + myDataGrid.RowHeadersDefaultCellStyle = dataGridViewCellStyle2; + myDataGrid.RowHeadersVisible = false; + myDataGrid.RowHeadersWidth = 82; + myDataGrid.Size = new System.Drawing.Size(896, 305); + myDataGrid.TabIndex = 0; + myDataGrid.MouseEnter += myDataGrid_MouseEnter; + myDataGrid.MouseLeave += myDataGrid_MouseLeave; // // myCSharpTabPage // - this.myCSharpTabPage.Controls.Add(this.myCSharpText); - this.myCSharpTabPage.Location = new System.Drawing.Point(4, 25); - this.myCSharpTabPage.Name = "myCSharpTabPage"; - this.myCSharpTabPage.Size = new System.Drawing.Size(896, 306); - this.myCSharpTabPage.TabIndex = 2; - this.myCSharpTabPage.Text = "C# Class"; + myCSharpTabPage.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myCSharpTabPage.Controls.Add(myCSharpText); + myCSharpTabPage.ForeColor = System.Drawing.Color.White; + myCSharpTabPage.Location = new System.Drawing.Point(4, 27); + myCSharpTabPage.Name = "myCSharpTabPage"; + myCSharpTabPage.Size = new System.Drawing.Size(896, 304); + myCSharpTabPage.TabIndex = 2; + myCSharpTabPage.Text = "C# Class"; // // myCSharpText // - this.myCSharpText.BackColor = System.Drawing.Color.White; - this.myCSharpText.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.myCSharpText.Dock = System.Windows.Forms.DockStyle.Fill; - this.myCSharpText.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.myCSharpText.Location = new System.Drawing.Point(0, 0); - this.myCSharpText.Name = "myCSharpText"; - this.myCSharpText.ReadOnly = true; - this.myCSharpText.Size = new System.Drawing.Size(896, 306); - this.myCSharpText.TabIndex = 0; - this.myCSharpText.Text = ""; - this.myCSharpText.MouseEnter += new System.EventHandler(this.myCSharpText_MouseEnter); - this.myCSharpText.MouseLeave += new System.EventHandler(this.myCSharpText_MouseLeave); + myCSharpText.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myCSharpText.BorderStyle = System.Windows.Forms.BorderStyle.None; + myCSharpText.Dock = System.Windows.Forms.DockStyle.Fill; + myCSharpText.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + myCSharpText.ForeColor = System.Drawing.Color.White; + myCSharpText.Location = new System.Drawing.Point(0, 0); + myCSharpText.Name = "myCSharpText"; + myCSharpText.ReadOnly = true; + myCSharpText.Size = new System.Drawing.Size(896, 304); + myCSharpText.TabIndex = 0; + myCSharpText.Text = ""; + myCSharpText.MouseEnter += myCSharpText_MouseEnter; + myCSharpText.MouseLeave += myCSharpText_MouseLeave; // // myErrorTabPage // - this.myErrorTabPage.Controls.Add(this.myErrorTextBox); - this.myErrorTabPage.Location = new System.Drawing.Point(4, 25); - this.myErrorTabPage.Name = "myErrorTabPage"; - this.myErrorTabPage.Size = new System.Drawing.Size(896, 306); - this.myErrorTabPage.TabIndex = 1; - this.myErrorTabPage.Text = "Error"; + myErrorTabPage.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myErrorTabPage.Controls.Add(myErrorTextBox); + myErrorTabPage.ForeColor = System.Drawing.Color.White; + myErrorTabPage.Location = new System.Drawing.Point(4, 27); + myErrorTabPage.Name = "myErrorTabPage"; + myErrorTabPage.Size = new System.Drawing.Size(896, 304); + myErrorTabPage.TabIndex = 1; + myErrorTabPage.Text = "Error"; // // myErrorTextBox // - this.myErrorTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.myErrorTextBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.myErrorTextBox.ForeColor = System.Drawing.Color.Red; - this.myErrorTextBox.Location = new System.Drawing.Point(0, 0); - this.myErrorTextBox.Name = "myErrorTextBox"; - this.myErrorTextBox.ReadOnly = true; - this.myErrorTextBox.Size = new System.Drawing.Size(896, 306); - this.myErrorTextBox.TabIndex = 1; - this.myErrorTextBox.Text = ""; + myErrorTextBox.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myErrorTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None; + myErrorTextBox.Dock = System.Windows.Forms.DockStyle.Fill; + myErrorTextBox.ForeColor = System.Drawing.Color.Red; + myErrorTextBox.Location = new System.Drawing.Point(0, 0); + myErrorTextBox.Name = "myErrorTextBox"; + myErrorTextBox.ReadOnly = true; + myErrorTextBox.Size = new System.Drawing.Size(896, 304); + myErrorTextBox.TabIndex = 1; + myErrorTextBox.Text = ""; // // myTableListTabPage // - this.myTableListTabPage.Controls.Add(this.myTableListBox); - this.myTableListTabPage.Controls.Add(this.myTableListTopPanel); - this.myTableListTabPage.Location = new System.Drawing.Point(4, 25); - this.myTableListTabPage.Name = "myTableListTabPage"; - this.myTableListTabPage.Size = new System.Drawing.Size(896, 306); - this.myTableListTabPage.TabIndex = 3; - this.myTableListTabPage.Text = "Table list"; + myTableListTabPage.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myTableListTabPage.Controls.Add(myTableListBox); + myTableListTabPage.Controls.Add(myTableListTopPanel); + myTableListTabPage.ForeColor = System.Drawing.Color.White; + myTableListTabPage.Location = new System.Drawing.Point(4, 27); + myTableListTabPage.Name = "myTableListTabPage"; + myTableListTabPage.Size = new System.Drawing.Size(896, 304); + myTableListTabPage.TabIndex = 3; + myTableListTabPage.Text = "Table list"; // // myTableListBox // - this.myTableListBox.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.myTableListBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.myTableListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; - this.myTableListBox.ItemHeight = 14; - this.myTableListBox.Location = new System.Drawing.Point(0, 31); - this.myTableListBox.Name = "myTableListBox"; - this.myTableListBox.Size = new System.Drawing.Size(896, 275); - this.myTableListBox.TabIndex = 1; - this.myTableListBox.DoubleClick += new System.EventHandler(this.myTableListBox_DoubleClick); - this.myTableListBox.MouseEnter += new System.EventHandler(this.myTableListBox_MouseEnter); - this.myTableListBox.MouseLeave += new System.EventHandler(this.myTableListBox_MouseLeave); + myTableListBox.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myTableListBox.BorderStyle = System.Windows.Forms.BorderStyle.None; + myTableListBox.Dock = System.Windows.Forms.DockStyle.Fill; + myTableListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; + myTableListBox.ForeColor = System.Drawing.Color.White; + myTableListBox.ItemHeight = 14; + myTableListBox.Location = new System.Drawing.Point(0, 31); + myTableListBox.Name = "myTableListBox"; + myTableListBox.Size = new System.Drawing.Size(896, 273); + myTableListBox.TabIndex = 1; + myTableListBox.DoubleClick += myTableListBox_DoubleClick; + myTableListBox.MouseEnter += myTableListBox_MouseEnter; + myTableListBox.MouseLeave += myTableListBox_MouseLeave; // // myTableListTopPanel // - this.myTableListTopPanel.Controls.Add(this.myTableFilterBox); - this.myTableListTopPanel.Controls.Add(this.myTableFilterLabel); - this.myTableListTopPanel.Dock = System.Windows.Forms.DockStyle.Top; - this.myTableListTopPanel.Location = new System.Drawing.Point(0, 0); - this.myTableListTopPanel.Name = "myTableListTopPanel"; - this.myTableListTopPanel.Size = new System.Drawing.Size(896, 31); - this.myTableListTopPanel.TabIndex = 4; + myTableListTopPanel.Controls.Add(myTableFilterBox); + myTableListTopPanel.Controls.Add(myTableFilterLabel); + myTableListTopPanel.Dock = System.Windows.Forms.DockStyle.Top; + myTableListTopPanel.Location = new System.Drawing.Point(0, 0); + myTableListTopPanel.Name = "myTableListTopPanel"; + myTableListTopPanel.Size = new System.Drawing.Size(896, 31); + myTableListTopPanel.TabIndex = 4; // // myTableFilterBox // - this.myTableFilterBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.myTableFilterBox.Location = new System.Drawing.Point(58, 3); - this.myTableFilterBox.Name = "myTableFilterBox"; - this.myTableFilterBox.Size = new System.Drawing.Size(835, 20); - this.myTableFilterBox.TabIndex = 2; - this.myTableFilterBox.TextChanged += new System.EventHandler(this.myTableFilterBox_TextChanged); + myTableFilterBox.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + myTableFilterBox.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myTableFilterBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + myTableFilterBox.ForeColor = System.Drawing.Color.White; + myTableFilterBox.Location = new System.Drawing.Point(58, 3); + myTableFilterBox.Name = "myTableFilterBox"; + myTableFilterBox.Size = new System.Drawing.Size(835, 20); + myTableFilterBox.TabIndex = 2; + myTableFilterBox.TextChanged += myTableFilterBox_TextChanged; // // myTableFilterLabel // - this.myTableFilterLabel.AutoSize = true; - this.myTableFilterLabel.Location = new System.Drawing.Point(3, 3); - this.myTableFilterLabel.Name = "myTableFilterLabel"; - this.myTableFilterLabel.Size = new System.Drawing.Size(49, 14); - this.myTableFilterLabel.TabIndex = 3; - this.myTableFilterLabel.Text = "Filter"; + myTableFilterLabel.AutoSize = true; + myTableFilterLabel.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myTableFilterLabel.ForeColor = System.Drawing.Color.White; + myTableFilterLabel.Location = new System.Drawing.Point(3, 3); + myTableFilterLabel.Name = "myTableFilterLabel"; + myTableFilterLabel.Size = new System.Drawing.Size(49, 14); + myTableFilterLabel.TabIndex = 3; + myTableFilterLabel.Text = "Filter"; + myTableFilterLabel.Click += myTableFilterLabel_Click; // // myPrimitivesPage // - this.myPrimitivesPage.Controls.Add(this.myTreeView); - this.myPrimitivesPage.Location = new System.Drawing.Point(4, 25); - this.myPrimitivesPage.Name = "myPrimitivesPage"; - this.myPrimitivesPage.Size = new System.Drawing.Size(896, 306); - this.myPrimitivesPage.TabIndex = 4; - this.myPrimitivesPage.Text = "Language primitives"; + myPrimitivesPage.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myPrimitivesPage.Controls.Add(myTreeView); + myPrimitivesPage.ForeColor = System.Drawing.Color.White; + myPrimitivesPage.Location = new System.Drawing.Point(4, 27); + myPrimitivesPage.Name = "myPrimitivesPage"; + myPrimitivesPage.Size = new System.Drawing.Size(896, 304); + myPrimitivesPage.TabIndex = 4; + myPrimitivesPage.Text = "Language primitives"; // // myTreeView // - this.myTreeView.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.myTreeView.Dock = System.Windows.Forms.DockStyle.Fill; - this.myTreeView.Location = new System.Drawing.Point(0, 0); - this.myTreeView.Name = "myTreeView"; - this.myTreeView.Size = new System.Drawing.Size(896, 306); - this.myTreeView.TabIndex = 0; + myTreeView.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myTreeView.BorderStyle = System.Windows.Forms.BorderStyle.None; + myTreeView.Dock = System.Windows.Forms.DockStyle.Fill; + myTreeView.ForeColor = System.Drawing.Color.White; + myTreeView.Location = new System.Drawing.Point(0, 0); + myTreeView.Name = "myTreeView"; + myTreeView.Size = new System.Drawing.Size(896, 304); + myTreeView.TabIndex = 0; // // myConsoleTabPage // - this.myConsoleTabPage.Controls.Add(this.myConsoleRichTextBox); - this.myConsoleTabPage.Location = new System.Drawing.Point(4, 25); - this.myConsoleTabPage.Name = "myConsoleTabPage"; - this.myConsoleTabPage.Padding = new System.Windows.Forms.Padding(3); - this.myConsoleTabPage.Size = new System.Drawing.Size(896, 306); - this.myConsoleTabPage.TabIndex = 5; - this.myConsoleTabPage.Text = "Console"; - this.myConsoleTabPage.UseVisualStyleBackColor = true; + myConsoleTabPage.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myConsoleTabPage.Controls.Add(myConsoleRichTextBox); + myConsoleTabPage.ForeColor = System.Drawing.Color.White; + myConsoleTabPage.Location = new System.Drawing.Point(4, 27); + myConsoleTabPage.Name = "myConsoleTabPage"; + myConsoleTabPage.Padding = new System.Windows.Forms.Padding(3); + myConsoleTabPage.Size = new System.Drawing.Size(896, 304); + myConsoleTabPage.TabIndex = 5; + myConsoleTabPage.Text = "Console"; // // myConsoleRichTextBox // - this.myConsoleRichTextBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.myConsoleRichTextBox.Location = new System.Drawing.Point(3, 3); - this.myConsoleRichTextBox.Name = "myConsoleRichTextBox"; - this.myConsoleRichTextBox.Size = new System.Drawing.Size(890, 300); - this.myConsoleRichTextBox.TabIndex = 0; - this.myConsoleRichTextBox.Text = ""; + myConsoleRichTextBox.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myConsoleRichTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + myConsoleRichTextBox.Dock = System.Windows.Forms.DockStyle.Fill; + myConsoleRichTextBox.ForeColor = System.Drawing.Color.White; + myConsoleRichTextBox.Location = new System.Drawing.Point(3, 3); + myConsoleRichTextBox.Name = "myConsoleRichTextBox"; + myConsoleRichTextBox.Size = new System.Drawing.Size(890, 298); + myConsoleRichTextBox.TabIndex = 0; + myConsoleRichTextBox.Text = ""; // // myTimer // - this.myTimer.Enabled = true; - this.myTimer.Interval = 150; - this.myTimer.Tick += new System.EventHandler(this.myTimer_Tick); + myTimer.Enabled = true; + myTimer.Interval = 150; + myTimer.Tick += myTimer_Tick; // // mySplitter // - this.mySplitter.Dock = System.Windows.Forms.DockStyle.Top; - this.mySplitter.Location = new System.Drawing.Point(0, 232); - this.mySplitter.Name = "mySplitter"; - this.mySplitter.Size = new System.Drawing.Size(904, 3); - this.mySplitter.TabIndex = 3; - this.mySplitter.TabStop = false; + mySplitter.Dock = System.Windows.Forms.DockStyle.Top; + mySplitter.Location = new System.Drawing.Point(0, 232); + mySplitter.Name = "mySplitter"; + mySplitter.Size = new System.Drawing.Size(904, 4); + mySplitter.TabIndex = 3; + mySplitter.TabStop = false; // // myStatusStrip // - this.myStatusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.myToolStripStatusLabelTime, - this.myToolStripStatusLabelRows}); - this.myStatusStrip.Location = new System.Drawing.Point(0, 567); - this.myStatusStrip.Name = "myStatusStrip"; - this.myStatusStrip.Size = new System.Drawing.Size(904, 22); - this.myStatusStrip.TabIndex = 4; + myStatusStrip.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myStatusStrip.ImageScalingSize = new System.Drawing.Size(32, 32); + myStatusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { myToolStripStatusLabelTime, myToolStripStatusLabelRows, toolStripStatusLabel1 }); + myStatusStrip.Location = new System.Drawing.Point(0, 567); + myStatusStrip.Name = "myStatusStrip"; + myStatusStrip.Size = new System.Drawing.Size(904, 22); + myStatusStrip.TabIndex = 4; // // myToolStripStatusLabelTime // - this.myToolStripStatusLabelTime.Name = "myToolStripStatusLabelTime"; - this.myToolStripStatusLabelTime.Padding = new System.Windows.Forms.Padding(0, 0, 8, 0); - this.myToolStripStatusLabelTime.Size = new System.Drawing.Size(8, 17); + myToolStripStatusLabelTime.Name = "myToolStripStatusLabelTime"; + myToolStripStatusLabelTime.Padding = new System.Windows.Forms.Padding(0, 0, 8, 0); + myToolStripStatusLabelTime.Size = new System.Drawing.Size(8, 17); // // myToolStripStatusLabelRows // - this.myToolStripStatusLabelRows.Name = "myToolStripStatusLabelRows"; - this.myToolStripStatusLabelRows.Size = new System.Drawing.Size(0, 17); + myToolStripStatusLabelRows.Name = "myToolStripStatusLabelRows"; + myToolStripStatusLabelRows.Size = new System.Drawing.Size(0, 17); + // + // toolStripStatusLabel1 + // + toolStripStatusLabel1.ForeColor = System.Drawing.Color.White; + toolStripStatusLabel1.Name = "toolStripStatusLabel1"; + toolStripStatusLabel1.Size = new System.Drawing.Size(0, 17); // // myMenuStrip // - this.myMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.myToolStripMenuItemFile, - this.myToolStripMenuItemQuery, - this.myToolStripMenuItemTools, - this.myToolStripMenuItemSite, - this.libraryToolStripMenuItem}); - this.myMenuStrip.Location = new System.Drawing.Point(0, 0); - this.myMenuStrip.Name = "myMenuStrip"; - this.myMenuStrip.Size = new System.Drawing.Size(904, 24); - this.myMenuStrip.TabIndex = 5; - this.myMenuStrip.Text = "menuStrip1"; + myMenuStrip.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myMenuStrip.ImageScalingSize = new System.Drawing.Size(32, 32); + myMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { myToolStripMenuItemFile, myToolStripMenuItemQuery, myToolStripMenuItemTools, myToolStripMenuItemSite, libraryToolStripMenuItem }); + myMenuStrip.Location = new System.Drawing.Point(0, 0); + myMenuStrip.Name = "myMenuStrip"; + myMenuStrip.Size = new System.Drawing.Size(904, 24); + myMenuStrip.TabIndex = 5; + myMenuStrip.Text = "menuStrip1"; // // myToolStripMenuItemFile // - this.myToolStripMenuItemFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.myToolStripMenuItemOpen, - this.myToolStripMenuItemSave, - this.myToolStripMenuItemSaveAs, - this.myToolStripMenuItemExit, - this.testGridToolStripMenuItem}); - this.myToolStripMenuItemFile.Name = "myToolStripMenuItemFile"; - this.myToolStripMenuItemFile.Size = new System.Drawing.Size(37, 20); - this.myToolStripMenuItemFile.Text = "&File"; + myToolStripMenuItemFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { myToolStripMenuItemOpen, myToolStripMenuItemSave, myToolStripMenuItemSaveAs, myToolStripMenuItemExit, testGridToolStripMenuItem }); + myToolStripMenuItemFile.ForeColor = System.Drawing.Color.White; + myToolStripMenuItemFile.Name = "myToolStripMenuItemFile"; + myToolStripMenuItemFile.Size = new System.Drawing.Size(37, 20); + myToolStripMenuItemFile.Text = "&File"; // // myToolStripMenuItemOpen // - this.myToolStripMenuItemOpen.Image = global::DataStreamQueryAnalyzer.Properties.Resources.File_Open_icon16; - this.myToolStripMenuItemOpen.Name = "myToolStripMenuItemOpen"; - this.myToolStripMenuItemOpen.Size = new System.Drawing.Size(123, 22); - this.myToolStripMenuItemOpen.Text = "&Open..."; - this.myToolStripMenuItemOpen.Click += new System.EventHandler(this.myMenuItemOpenClick); + myToolStripMenuItemOpen.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myToolStripMenuItemOpen.ForeColor = System.Drawing.Color.White; + myToolStripMenuItemOpen.Image = DataStreamQueryAnalyzer.Properties.Resources.File_Open_icon16; + myToolStripMenuItemOpen.Name = "myToolStripMenuItemOpen"; + myToolStripMenuItemOpen.Size = new System.Drawing.Size(139, 38); + myToolStripMenuItemOpen.Text = "&Open..."; + myToolStripMenuItemOpen.Click += myMenuItemOpenClick; // // myToolStripMenuItemSave // - this.myToolStripMenuItemSave.Image = global::DataStreamQueryAnalyzer.Properties.Resources.Save_icon16; - this.myToolStripMenuItemSave.Name = "myToolStripMenuItemSave"; - this.myToolStripMenuItemSave.Size = new System.Drawing.Size(123, 22); - this.myToolStripMenuItemSave.Text = "Save..."; - this.myToolStripMenuItemSave.Click += new System.EventHandler(this.myMenuItemSaveClick); + myToolStripMenuItemSave.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myToolStripMenuItemSave.ForeColor = System.Drawing.Color.White; + myToolStripMenuItemSave.Image = DataStreamQueryAnalyzer.Properties.Resources.Save_icon16; + myToolStripMenuItemSave.Name = "myToolStripMenuItemSave"; + myToolStripMenuItemSave.Size = new System.Drawing.Size(139, 38); + myToolStripMenuItemSave.Text = "Save..."; + myToolStripMenuItemSave.Click += myMenuItemSaveClick; // // myToolStripMenuItemSaveAs // - this.myToolStripMenuItemSaveAs.Name = "myToolStripMenuItemSaveAs"; - this.myToolStripMenuItemSaveAs.Size = new System.Drawing.Size(123, 22); - this.myToolStripMenuItemSaveAs.Text = "Save As..."; - this.myToolStripMenuItemSaveAs.Click += new System.EventHandler(this.myMenuItemSaveAsClick); + myToolStripMenuItemSaveAs.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myToolStripMenuItemSaveAs.ForeColor = System.Drawing.Color.White; + myToolStripMenuItemSaveAs.Name = "myToolStripMenuItemSaveAs"; + myToolStripMenuItemSaveAs.Size = new System.Drawing.Size(139, 38); + myToolStripMenuItemSaveAs.Text = "Save As..."; + myToolStripMenuItemSaveAs.Click += myMenuItemSaveAsClick; // // myToolStripMenuItemExit // - this.myToolStripMenuItemExit.Image = global::DataStreamQueryAnalyzer.Properties.Resources.Button_Turn_Off_icon16; - this.myToolStripMenuItemExit.Name = "myToolStripMenuItemExit"; - this.myToolStripMenuItemExit.Size = new System.Drawing.Size(123, 22); - this.myToolStripMenuItemExit.Text = "Exit"; - this.myToolStripMenuItemExit.Click += new System.EventHandler(this.myToolStripMenuItemExit_Click); + myToolStripMenuItemExit.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myToolStripMenuItemExit.ForeColor = System.Drawing.Color.White; + myToolStripMenuItemExit.Image = DataStreamQueryAnalyzer.Properties.Resources.Button_Turn_Off_icon16; + myToolStripMenuItemExit.Name = "myToolStripMenuItemExit"; + myToolStripMenuItemExit.Size = new System.Drawing.Size(139, 38); + myToolStripMenuItemExit.Text = "Exit"; + myToolStripMenuItemExit.Click += myToolStripMenuItemExit_Click; // // testGridToolStripMenuItem // - this.testGridToolStripMenuItem.Name = "testGridToolStripMenuItem"; - this.testGridToolStripMenuItem.Size = new System.Drawing.Size(123, 22); - this.testGridToolStripMenuItem.Text = "Test Grid"; - this.testGridToolStripMenuItem.Click += new System.EventHandler(this.testGridToolStripMenuItem_Click); + testGridToolStripMenuItem.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + testGridToolStripMenuItem.ForeColor = System.Drawing.Color.White; + testGridToolStripMenuItem.Name = "testGridToolStripMenuItem"; + testGridToolStripMenuItem.Size = new System.Drawing.Size(139, 38); + testGridToolStripMenuItem.Text = "Test Grid"; + testGridToolStripMenuItem.Click += testGridToolStripMenuItem_Click; // // myToolStripMenuItemQuery // - this.myToolStripMenuItemQuery.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.myToolStripMenuItemExecute, - this.myToolStripMenuItemExecSel, - this.myToolStripMenuItemFreeze, - this.myToolStripMenuItemStep}); - this.myToolStripMenuItemQuery.Name = "myToolStripMenuItemQuery"; - this.myToolStripMenuItemQuery.Size = new System.Drawing.Size(51, 20); - this.myToolStripMenuItemQuery.Text = "&Query"; + myToolStripMenuItemQuery.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { myToolStripMenuItemExecute, myToolStripMenuItemExecSel, myToolStripMenuItemFreeze, myToolStripMenuItemStep }); + myToolStripMenuItemQuery.ForeColor = System.Drawing.Color.White; + myToolStripMenuItemQuery.Name = "myToolStripMenuItemQuery"; + myToolStripMenuItemQuery.Size = new System.Drawing.Size(51, 20); + myToolStripMenuItemQuery.Text = "&Query"; // // myToolStripMenuItemExecute // - this.myToolStripMenuItemExecute.Image = global::DataStreamQueryAnalyzer.Properties.Resources.Button_Play_icon16; - this.myToolStripMenuItemExecute.Name = "myToolStripMenuItemExecute"; - this.myToolStripMenuItemExecute.ShortcutKeys = System.Windows.Forms.Keys.F11; - this.myToolStripMenuItemExecute.Size = new System.Drawing.Size(190, 22); - this.myToolStripMenuItemExecute.Text = "Execute"; - this.myToolStripMenuItemExecute.Click += new System.EventHandler(this.myMenuItemExecuteQueryClick); + myToolStripMenuItemExecute.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myToolStripMenuItemExecute.ForeColor = System.Drawing.Color.White; + myToolStripMenuItemExecute.Image = DataStreamQueryAnalyzer.Properties.Resources.Button_Play_icon16; + myToolStripMenuItemExecute.Name = "myToolStripMenuItemExecute"; + myToolStripMenuItemExecute.ShortcutKeys = System.Windows.Forms.Keys.F11; + myToolStripMenuItemExecute.Size = new System.Drawing.Size(207, 38); + myToolStripMenuItemExecute.Text = "Execute"; + myToolStripMenuItemExecute.Click += myMenuItemExecuteQueryClick; // // myToolStripMenuItemExecSel // - this.myToolStripMenuItemExecSel.Image = global::DataStreamQueryAnalyzer.Properties.Resources.Button_Blank_Blue_icon16; - this.myToolStripMenuItemExecSel.Name = "myToolStripMenuItemExecSel"; - this.myToolStripMenuItemExecSel.ShortcutKeys = System.Windows.Forms.Keys.F12; - this.myToolStripMenuItemExecSel.Size = new System.Drawing.Size(190, 22); - this.myToolStripMenuItemExecSel.Text = "Execute Selection"; - this.myToolStripMenuItemExecSel.Click += new System.EventHandler(this.myToolStripMenuItemExecSel_Click); + myToolStripMenuItemExecSel.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myToolStripMenuItemExecSel.ForeColor = System.Drawing.Color.White; + myToolStripMenuItemExecSel.Image = DataStreamQueryAnalyzer.Properties.Resources.Button_Blank_Blue_icon16; + myToolStripMenuItemExecSel.Name = "myToolStripMenuItemExecSel"; + myToolStripMenuItemExecSel.ShortcutKeys = System.Windows.Forms.Keys.F12; + myToolStripMenuItemExecSel.Size = new System.Drawing.Size(207, 38); + myToolStripMenuItemExecSel.Text = "Execute Selection"; + myToolStripMenuItemExecSel.Click += myToolStripMenuItemExecSel_Click; // // myToolStripMenuItemFreeze // - this.myToolStripMenuItemFreeze.Image = global::DataStreamQueryAnalyzer.Properties.Resources.Button_Pause_icon16; - this.myToolStripMenuItemFreeze.Name = "myToolStripMenuItemFreeze"; - this.myToolStripMenuItemFreeze.Size = new System.Drawing.Size(190, 22); - this.myToolStripMenuItemFreeze.Text = "Freeze"; - this.myToolStripMenuItemFreeze.Click += new System.EventHandler(this.myToolStripMenuItemFreeze_Click); + myToolStripMenuItemFreeze.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myToolStripMenuItemFreeze.ForeColor = System.Drawing.Color.White; + myToolStripMenuItemFreeze.Image = DataStreamQueryAnalyzer.Properties.Resources.Button_Pause_icon16; + myToolStripMenuItemFreeze.Name = "myToolStripMenuItemFreeze"; + myToolStripMenuItemFreeze.Size = new System.Drawing.Size(207, 38); + myToolStripMenuItemFreeze.Text = "Freeze"; + myToolStripMenuItemFreeze.Click += myToolStripMenuItemFreeze_Click; // // myToolStripMenuItemStep // - this.myToolStripMenuItemStep.Image = global::DataStreamQueryAnalyzer.Properties.Resources.Button_Forward_icon16; - this.myToolStripMenuItemStep.Name = "myToolStripMenuItemStep"; - this.myToolStripMenuItemStep.Size = new System.Drawing.Size(190, 22); - this.myToolStripMenuItemStep.Text = "Step"; - this.myToolStripMenuItemStep.Click += new System.EventHandler(this.myToolStripMenuItemStep_Click); + myToolStripMenuItemStep.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myToolStripMenuItemStep.ForeColor = System.Drawing.Color.White; + myToolStripMenuItemStep.Image = DataStreamQueryAnalyzer.Properties.Resources.Button_Forward_icon16; + myToolStripMenuItemStep.Name = "myToolStripMenuItemStep"; + myToolStripMenuItemStep.Size = new System.Drawing.Size(207, 38); + myToolStripMenuItemStep.Text = "Step"; + myToolStripMenuItemStep.Click += myToolStripMenuItemStep_Click; // // myToolStripMenuItemTools // - this.myToolStripMenuItemTools.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.myToolStripMenuItemLoadAss, - this.myToolStripMenuItemTest, - this.myToolStripMenuItemToolsSep, - this.myToolStripMenuItemClearConsole}); - this.myToolStripMenuItemTools.Name = "myToolStripMenuItemTools"; - this.myToolStripMenuItemTools.Size = new System.Drawing.Size(48, 20); - this.myToolStripMenuItemTools.Text = "&Tools"; + myToolStripMenuItemTools.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { myToolStripMenuItemLoadAss, myToolStripMenuItemTest, myToolStripMenuItemToolsSep, myToolStripMenuItemClearConsole }); + myToolStripMenuItemTools.ForeColor = System.Drawing.Color.White; + myToolStripMenuItemTools.Name = "myToolStripMenuItemTools"; + myToolStripMenuItemTools.Size = new System.Drawing.Size(46, 20); + myToolStripMenuItemTools.Text = "&Tools"; // // myToolStripMenuItemLoadAss // - this.myToolStripMenuItemLoadAss.Image = global::DataStreamQueryAnalyzer.Properties.Resources.Button_Upload_icon16; - this.myToolStripMenuItemLoadAss.Name = "myToolStripMenuItemLoadAss"; - this.myToolStripMenuItemLoadAss.Size = new System.Drawing.Size(154, 22); - this.myToolStripMenuItemLoadAss.Text = "Load Assembly"; - this.myToolStripMenuItemLoadAss.Click += new System.EventHandler(this.myToolStripMenuItemLoadAss_Click); + myToolStripMenuItemLoadAss.Image = DataStreamQueryAnalyzer.Properties.Resources.Button_Upload_icon16; + myToolStripMenuItemLoadAss.Name = "myToolStripMenuItemLoadAss"; + myToolStripMenuItemLoadAss.Size = new System.Drawing.Size(170, 38); + myToolStripMenuItemLoadAss.Text = "Load Assembly"; + myToolStripMenuItemLoadAss.Click += myToolStripMenuItemLoadAss_Click; // // myToolStripMenuItemTest // - this.myToolStripMenuItemTest.Image = global::DataStreamQueryAnalyzer.Properties.Resources.Button_Refresh_icon16; - this.myToolStripMenuItemTest.Name = "myToolStripMenuItemTest"; - this.myToolStripMenuItemTest.ShortcutKeys = System.Windows.Forms.Keys.F4; - this.myToolStripMenuItemTest.Size = new System.Drawing.Size(154, 22); - this.myToolStripMenuItemTest.Text = "Test Resub"; - this.myToolStripMenuItemTest.Click += new System.EventHandler(this.myToolStripMenuItemTest_Click); + myToolStripMenuItemTest.Image = DataStreamQueryAnalyzer.Properties.Resources.Button_Refresh_icon16; + myToolStripMenuItemTest.Name = "myToolStripMenuItemTest"; + myToolStripMenuItemTest.ShortcutKeys = System.Windows.Forms.Keys.F4; + myToolStripMenuItemTest.Size = new System.Drawing.Size(170, 38); + myToolStripMenuItemTest.Text = "Test Resub"; + myToolStripMenuItemTest.Click += myToolStripMenuItemTest_Click; // // myToolStripMenuItemToolsSep // - this.myToolStripMenuItemToolsSep.Name = "myToolStripMenuItemToolsSep"; - this.myToolStripMenuItemToolsSep.Size = new System.Drawing.Size(151, 6); + myToolStripMenuItemToolsSep.Name = "myToolStripMenuItemToolsSep"; + myToolStripMenuItemToolsSep.Size = new System.Drawing.Size(167, 6); // // myToolStripMenuItemClearConsole // - this.myToolStripMenuItemClearConsole.Name = "myToolStripMenuItemClearConsole"; - this.myToolStripMenuItemClearConsole.Size = new System.Drawing.Size(154, 22); - this.myToolStripMenuItemClearConsole.Text = "Clear Console"; - this.myToolStripMenuItemClearConsole.Click += new System.EventHandler(this.myToolStripMenuItemClearConsole_Click); + myToolStripMenuItemClearConsole.BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + myToolStripMenuItemClearConsole.ForeColor = System.Drawing.Color.White; + myToolStripMenuItemClearConsole.Name = "myToolStripMenuItemClearConsole"; + myToolStripMenuItemClearConsole.Size = new System.Drawing.Size(170, 38); + myToolStripMenuItemClearConsole.Text = "Clear Console"; + myToolStripMenuItemClearConsole.Click += myToolStripMenuItemClearConsole_Click; // // myToolStripMenuItemSite // - this.myToolStripMenuItemSite.Name = "myToolStripMenuItemSite"; - this.myToolStripMenuItemSite.Size = new System.Drawing.Size(38, 20); - this.myToolStripMenuItemSite.Text = "&Site"; + myToolStripMenuItemSite.Name = "myToolStripMenuItemSite"; + myToolStripMenuItemSite.Size = new System.Drawing.Size(38, 20); + myToolStripMenuItemSite.Text = "&Site"; // // libraryToolStripMenuItem // - this.libraryToolStripMenuItem.Name = "libraryToolStripMenuItem"; - this.libraryToolStripMenuItem.Size = new System.Drawing.Size(55, 20); - this.libraryToolStripMenuItem.Text = "Library"; - this.libraryToolStripMenuItem.Click += new System.EventHandler(this.libraryToolStripMenuItem_Click); + libraryToolStripMenuItem.Name = "libraryToolStripMenuItem"; + libraryToolStripMenuItem.Size = new System.Drawing.Size(55, 20); + libraryToolStripMenuItem.Text = "Library"; + libraryToolStripMenuItem.Click += libraryToolStripMenuItem_Click; // // MainForm // - this.AutoScaleBaseSize = new System.Drawing.Size(7, 13); - this.BackColor = System.Drawing.Color.Gainsboro; - this.ClientSize = new System.Drawing.Size(904, 589); - this.Controls.Add(this.mySplitter); - this.Controls.Add(this.myTabControl); - this.Controls.Add(this.myQueryTextBox); - this.Controls.Add(this.myMenuStrip); - this.Controls.Add(this.myStatusStrip); - this.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.ForeColor = System.Drawing.Color.Black; - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MainMenuStrip = this.myMenuStrip; - this.Name = "MainForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; - this.Text = "DataStream Query Analyzer"; - this.Closed += new System.EventHandler(this.MainForm_Closed); - this.myTabControl.ResumeLayout(false); - this.myViewTabPage.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.myDataGrid)).EndInit(); - this.myCSharpTabPage.ResumeLayout(false); - this.myErrorTabPage.ResumeLayout(false); - this.myTableListTabPage.ResumeLayout(false); - this.myTableListTopPanel.ResumeLayout(false); - this.myTableListTopPanel.PerformLayout(); - this.myPrimitivesPage.ResumeLayout(false); - this.myConsoleTabPage.ResumeLayout(false); - this.myStatusStrip.ResumeLayout(false); - this.myStatusStrip.PerformLayout(); - this.myMenuStrip.ResumeLayout(false); - this.myMenuStrip.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleBaseSize = new System.Drawing.Size(7, 13); + BackColor = System.Drawing.Color.FromArgb(36, 36, 49); + ClientSize = new System.Drawing.Size(904, 589); + Controls.Add(mySplitter); + Controls.Add(myTabControl); + Controls.Add(myQueryTextBox); + Controls.Add(myMenuStrip); + Controls.Add(myStatusStrip); + Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + ForeColor = System.Drawing.Color.White; + Icon = (System.Drawing.Icon)resources.GetObject("$this.Icon"); + MainMenuStrip = myMenuStrip; + Name = "MainForm"; + StartPosition = System.Windows.Forms.FormStartPosition.Manual; + Text = "BTS-cloud.io"; + Closed += MainForm_Closed; + Load += MainForm_Load; + myTabControl.ResumeLayout(false); + myViewTabPage.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)myDataGrid).EndInit(); + myCSharpTabPage.ResumeLayout(false); + myErrorTabPage.ResumeLayout(false); + myTableListTabPage.ResumeLayout(false); + myTableListTopPanel.ResumeLayout(false); + myTableListTopPanel.PerformLayout(); + myPrimitivesPage.ResumeLayout(false); + myConsoleTabPage.ResumeLayout(false); + myStatusStrip.ResumeLayout(false); + myStatusStrip.PerformLayout(); + myMenuStrip.ResumeLayout(false); + myMenuStrip.PerformLayout(); + ResumeLayout(false); + PerformLayout(); } #endregion @@ -555,5 +610,6 @@ private System.Windows.Forms.Panel myTableListTopPanel; private System.Windows.Forms.ToolStripMenuItem testGridToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem libraryToolStripMenuItem; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; } } diff --git a/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.cs b/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.cs index 2813bce20..bb15b444e 100644 --- a/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.cs +++ b/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.cs @@ -31,8 +31,8 @@ namespace BCG { var login = "bts"; var passwd = String.Empty; Console.WriteLine("Starting DSQA... "); - Log.notnull(login); - Log.notnull(passwd); + // Log.notnull(login); + // Log.notnull(passwd); var service_ctx = bts.api.core.ServiceContext.create(); await service_ctx.login(login, passwd); } @@ -71,7 +71,7 @@ namespace BCG { } private ViewStream myGetAllTagsStream() { // TODO: Port PublishedTagsStream from edge (then we can uncomment impl below) - return new PubSubServerStateStream(); + return new FilterStream(new PubSubServerStateStream(), "tag~='DS_'"); //return new LiteralStream("tag/String", "DS_Comedians;DS_Baldies"); } @@ -295,8 +295,10 @@ namespace BCG { return Math.Max(header_width, min_width); } } - + private HighPerformanceTimer _timer = new HighPerformanceTimer(); + // this is the stream callback private void myCallback(object o) { + _timer.start(); DataPacket dp = o as DataPacket; myCrono.stop(); Log.Ui.diag($"Received callback for {dp.schema.tableName}"); @@ -306,13 +308,18 @@ namespace BCG { return; } Log.Ui.diag(dp.toIncrementalIDString()); + myToolStripStatusLabelTime.BackColor = Color.Black; + myToolStripStatusLabelRows.BackColor = Color.Black; + myToolStripStatusLabelTime.ForeColor = Color.White; + myToolStripStatusLabelRows.ForeColor = Color.White; myToolStripStatusLabelTime.Text = "Last update: " + DateTime.Now.ToString("hh:mm:ss:fff tt"); myToolStripStatusLabelRows.Text = "New = " + dp.newRows.Count + " Added = " + dp.addedRows.Count + " Deleted = " + dp.deletedRows.Count; Log.Ui.diag(Text); int hscrollval = myChangeStyle ? 0 : myDataGrid.HorizScrollBarValue; myDataGrid.DataSource = new SimpleBindableCollection(dp.newRows.schema, dp.newRows); - if (myChangeStyle) { + var force = false; + if (myChangeStyle && force) { myChangeStyle = false; myDataGrid.Columns.Clear(); myDataGrid.Columns.AddRange(Array.ConvertAll(dp.schema.columnInfo, _column_factory)); @@ -328,7 +335,11 @@ namespace BCG { string code = myExp.print(9, varNames); myPrintCode(dp.schema, varNames, code); myConsoleRichTextBox.Clear(); - myConsoleRichTextBox.Text = BlueDataUtility.get_printed_rows(dp.newRows, (col) => 30); + // this was was very very slow + //myConsoleRichTextBox.Text = BlueDataUtility.get_printed_rows(dp.newRows, (col) => 30); + _timer.stop(); + var msecs = _timer.lastIntervalTime; + bts.Log.Gen.info($"DSQA MainForm.myCallback table: {dp.schema.tableName} rows: {dp.newRows.Count} time: {msecs}"); } private Crono myCrono; @@ -442,22 +453,22 @@ namespace BCG { } private void myCSharpText_MouseEnter(object sender, System.EventArgs e) { - myCSharpText.BackColor = Color.Gainsboro; + //myCSharpText.BackColor = Color.Gainsboro; myCSharpText.Font = new Font(myCSharpText.Font.Name, myCSharpText.Font.Size, FontStyle.Bold); } private void myCSharpText_MouseLeave(object sender, System.EventArgs e) { - myCSharpText.BackColor = Color.White; + //myCSharpText.BackColor = Color.White; myCSharpText.Font = new Font(myCSharpText.Font.Name, myCSharpText.Font.Size, FontStyle.Regular); } private void myTableListBox_MouseEnter(object sender, System.EventArgs e) { - myTableListBox.BackColor = Color.Gainsboro; + //myTableListBox.BackColor = Color.Gainsboro; myTableListBox.Font = new Font(myTableListBox.Font.Name, myTableListBox.Font.Size, FontStyle.Bold); } private void myTableListBox_MouseLeave(object sender, System.EventArgs e) { - myTableListBox.BackColor = Color.White; + //myTableListBox.BackColor = Color.White; myTableListBox.Font = new Font(myTableListBox.Font.Name, myTableListBox.Font.Size, FontStyle.Regular); } @@ -697,5 +708,13 @@ namespace BCG { } private void libraryToolStripMenuItem_Click(object sender, EventArgs e) { } + + private void myTableFilterLabel_Click(object sender, EventArgs e) { + + } + + private void MainForm_Load(object sender, EventArgs e) { + + } } } diff --git a/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.resx b/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.resx index 734111055..62068b309 100644 --- a/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.resx +++ b/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.resx @@ -1,64 +1,4 @@ - - diff --git a/src/DataStreamSuite/PubSub/StreamOpCode.cs b/src/DataStreamSuite/PubSub/StreamOpCode.cs index df5481c76..90eeedb43 100644 --- a/src/DataStreamSuite/PubSub/StreamOpCode.cs +++ b/src/DataStreamSuite/PubSub/StreamOpCode.cs @@ -3,10 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; -namespace BCG -{ - public class StreamOpCode - { +namespace BCG { + public class StreamOpCode { public static readonly byte create = 0, //creates a table add = 1, //adds a single row remove = 2, //removes a single row diff --git a/src/DataStreamSuite/SharedStreams/Business/MarketData/MDStream.cs b/src/DataStreamSuite/SharedStreams/Business/MarketData/BBOStream.cs similarity index 58% rename from src/DataStreamSuite/SharedStreams/Business/MarketData/MDStream.cs rename to src/DataStreamSuite/SharedStreams/Business/MarketData/BBOStream.cs index 37a017feb..83d26b193 100644 --- a/src/DataStreamSuite/SharedStreams/Business/MarketData/MDStream.cs +++ b/src/DataStreamSuite/SharedStreams/Business/MarketData/BBOStream.cs @@ -29,44 +29,56 @@ namespace BCG { using SecurityKey = System.UInt32; using System.Data; + using System.Reflection.Metadata; - [DataStreamUserRespresentation("md")] - public class MDStream : ViewStream, IWorker { + [DataStreamUserRespresentation("bbo")] + public class BBOStream : ViewStream, IWorker { private readonly TimeSpan _poll_period = TimeSpan.FromMilliseconds(500); private DateTime _last_poll_time = DateTime.MinValue; private ViewStreamDatabase _vsd; private int _id = 0; - IReadOnlyDictionary _cached_state = null; MarketDataClient _md_client; - private readonly IBlueTableSchema _bbo_schema = BlueDataUtility.form_schema("MarketImpliedVols", + private readonly IBlueTableSchema _bbo_schema = BlueDataUtility.form_schema("bbo", Tuple.Create("id", TypeCode.Int32), Tuple.Create("sec_key", TypeCode.UInt32), Tuple.Create("bid_price", TypeCode.Double), Tuple.Create("bid_sz", TypeCode.Single), Tuple.Create("ask_price", TypeCode.Double), Tuple.Create("ask_sz", TypeCode.Single)); - private KeysBasedTable2 _bbo_table; // TODO: add cons for symbol, exchange etc - public MDStream() + public BBOStream() : this(ViewStreamDatabase.instance) { } - public MDStream(ViewStreamDatabase vsd) { + public BBOStream(ViewStreamDatabase vsd) { + bts.Log.Gen.info("BBOStream.cons"); _vsd = vsd; - _bbo_table = new KeysBasedTable2(_bbo_schema, "sec_key"); _md_client = new MarketDataClient(new MDSource(TimeSpan.FromSeconds(0.5))); } protected override void myOnFirstSubscriber() { _vsd.addWorker(this); - _md_client.books().ObserveOn(SynchronizationContext.Current).Subscribe(_on_books); + _md_client.books().Subscribe(_on_books); + + } + + private void _log_updates(TableUpdate update) { + int i = 0; + foreach (BookTuple bt in update.added) { + bts.Log.Gen.info($"BBOStream added: idx: {i++} bid: {bt.book.bids[0].price} / {bt.book.bids[0].size} ask: {bt.book.asks[0].price} / {bt.book.asks[0].size}"); + } + foreach (Change c in update.changes) { + var bt = c.New; + bts.Log.Gen.info($"BBOStream changes: idx: {i} bid: {bt.book.bids[0].price} / {bt.book.bids[0].size} ask: {bt.book.asks[0].price} / {bt.book.asks[0].size}"); + } } private void _on_books(TableUpdate update) { + _log_updates(update); // just cacching in here, will populate the rows in _poll_scan and fire the datapacket - bts.Log.Gen.info($"MDStream._on_books state: {update.state.Count()} changes: {update.changes.Count()} added: {update.added.Count()}"); + bts.Log.Gen.info($"BBOStream._on_books state: {update.state.Count()} changes: {update.changes.Count()} added: {update.added.Count()}"); _cached_state = update.state; } @@ -76,17 +88,29 @@ namespace BCG { private void _scan_bbo() { // this shouldn be made incremental using the TableUpdate - bts.Log.Gen.info("MDStream._scan_bbo"); + bts.Log.Gen.info("BBOStream._scan_bbo"); if (_cached_state == null) return; + BlueTable new_state = new BlueTable(_bbo_schema); foreach (var kv in _cached_state) { SecurityKey skey = kv.Key; + int id = Convert.ToInt32(skey); BookTuple bt = kv.Value; - IBlueRow r = new BlueRow(_bbo_schema, _id++, skey, bt.book.bids[0].price, bt.book.bids[0].size, + IBlueRow r = new BlueRow(_bbo_schema, id, skey, bt.book.bids[0].price, bt.book.bids[0].size, bt.book.asks[0].price, bt.book.asks[0].size); - _bbo_table.update(r); + new_state.addRow(r); } - DataPacket dp = BlueDataUtility.build_dp(_bbo_table, myLastValue as DataPacket); + DataPacket dp = null; + if (myLastValue == null) { + dp = new DataPacket(new_state, new_state, new BlueTable(_bbo_schema)); + } else { + DataPacket old_dp = myLastValue as DataPacket; + IBlueRowCollection added_rows, del_rows; + BlueDataUtility.compute_differences_fast(new_state, old_dp.newRows, out del_rows, out added_rows); + dp = new DataPacket(new_state, added_rows, del_rows); + } + if (dp.addedRows.Count == 0 && dp.deletedRows.Count == 0) + return; myFireEvent(dp); } diff --git a/src/DataStreamSuite/SharedStreams/Business/MarketData/BookStream.cs b/src/DataStreamSuite/SharedStreams/Business/MarketData/BookStream.cs new file mode 100644 index 000000000..230398791 --- /dev/null +++ b/src/DataStreamSuite/SharedStreams/Business/MarketData/BookStream.cs @@ -0,0 +1,146 @@ +namespace BCG { + using BCG.Utilities.General; + + using bts.api; + using bts.api.domain; + using bts.api.synthetic; + using bts.md; + using bts.spark; + using bts.utils; + + using mbts; + using mbts.co2; + using mbts.config; + using mbts.spark; + using mbts.ui; + + using Spark.Core.Data; + using Spark.Core.Disposables; + using Spark.Core.Reactive; + + using System; + using System.Collections.Concurrent; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Linq; + using System.Reactive.Linq; + using bts.api.core; + using Spark.Api.MarketData; + + using SecurityKey = System.UInt32; + using System.Data; + using System.Reflection.Metadata; + + [DataStreamUserRespresentation("books")] + public class BookStream : ViewStream, IWorker { + private readonly TimeSpan _poll_period = TimeSpan.FromMilliseconds(500); + private DateTime _last_poll_time = DateTime.MinValue; + private ViewStreamDatabase _vsd; + private int _id = 0; + IReadOnlyDictionary _cached_state = null; + MarketDataClient _md_client; + HighPerformanceTimer _timer = new HighPerformanceTimer(); + private readonly IBlueTableSchema _bbo_schema = BlueDataUtility.form_schema("bbo", + Tuple.Create("id", TypeCode.Int32), + Tuple.Create("sec_key", TypeCode.UInt32), + Tuple.Create("level", TypeCode.UInt32), + Tuple.Create("bid_price", TypeCode.Double), + Tuple.Create("bid_sz", TypeCode.Single), + Tuple.Create("ask_price", TypeCode.Double), + Tuple.Create("ask_sz", TypeCode.Single)); + + // TODO: add cons for symbol, exchange etc + public BookStream() + : this(ViewStreamDatabase.instance) { + } + + public BookStream(ViewStreamDatabase vsd) { + bts.Log.Gen.info("BookStream.cons"); + _vsd = vsd; + _md_client = new MarketDataClient(new MDSource(TimeSpan.FromSeconds(0.5))); + } + + protected override void myOnFirstSubscriber() { + _vsd.addWorker(this); + _md_client.books().Subscribe(_on_books); + + } + + private void _log_updates(TableUpdate update) { + int i = 0; + foreach (BookTuple bt in update.added) { + bts.Log.Gen.info($"BookStream added: idx: {i++} bid: {bt.book.bids[0].price} / {bt.book.bids[0].size} ask: {bt.book.asks[0].price} / {bt.book.asks[0].size}"); + } + foreach (Change c in update.changes) { + var bt = c.New; + bts.Log.Gen.info($"BookStream changes: idx: {i} bid: {bt.book.bids[0].price} / {bt.book.bids[0].size} ask: {bt.book.asks[0].price} / {bt.book.asks[0].size}"); + } + } + + private void _on_books(TableUpdate update) { + _log_updates(update); + bts.Log.Gen.info($"BookStream._on_books state: {update.state.Count()} changes: {update.changes.Count()} added: {update.added.Count()}"); + _cached_state = update.state; + } + + protected override void myOnLastSubscriber() { + _vsd.removeWorker(this); + } + + private Dictionary> _id_map = new Dictionary>(); + private int _get_id(SecurityKey skey, int depth) { + Dictionary d_map = null; + if (!_id_map.TryGetValue(skey, out d_map)) { + d_map = new Dictionary(); + d_map.Add(depth, _id++); + _id_map.Add(skey, d_map); + } + int rv = 0; + if (!d_map.TryGetValue(depth, out rv)) { + rv = _id++; + d_map.Add(depth, rv); + } + return rv; + } + + private void _scan_bbo() { + // this shouldn be made incremental using the TableUpdate + bts.Log.Gen.info("BookStream._scan_bbo"); + _timer.start(); + if (_cached_state == null) + return; + BlueTable new_state = new BlueTable(_bbo_schema); + foreach (var kv in _cached_state) { + SecurityKey skey = kv.Key; + BookTuple bt = kv.Value; + for (int level = 0; level < bt.book.bids.Count; level++) { + int id = _get_id(skey, level); + IBlueRow r = new BlueRow(_bbo_schema, id, skey, Convert.ToUInt32(level), bt.book.bids[level].price, bt.book.bids[0].size, + bt.book.asks[level].price, bt.book.asks[level].size); + new_state.addRow(r); + } + } + DataPacket dp = null; + if (myLastValue == null) { + dp = new DataPacket(new_state, new_state, new BlueTable(_bbo_schema)); + } else { + DataPacket old_dp = myLastValue as DataPacket; + IBlueRowCollection added_rows, del_rows; + BlueDataUtility.compute_differences_fast(new_state, old_dp.newRows, out del_rows, out added_rows); + dp = new DataPacket(new_state, added_rows, del_rows); + } + if (dp.addedRows.Count == 0 && dp.deletedRows.Count == 0) + return; + _timer.stop(); + bts.Log.Gen.info($"BookStream._scan_bbo time: {_timer.lastIntervalTime} msecs"); + myFireEvent(dp); + } + + public void doWork() { + if (DateTime.Now - _last_poll_time > _poll_period) { + _last_poll_time = DateTime.Now; + _scan_bbo(); + } + } + } +} \ No newline at end of file diff --git a/src/DataStreamSuite/SharedStreams/Business/MarketData/InstrumentsStream.cs b/src/DataStreamSuite/SharedStreams/Business/MarketData/InstrumentsStream.cs new file mode 100644 index 000000000..078ec78c8 --- /dev/null +++ b/src/DataStreamSuite/SharedStreams/Business/MarketData/InstrumentsStream.cs @@ -0,0 +1,120 @@ +namespace BCG { + using BCG.Utilities.General; + + using bts.api; + using bts.md; + + using Spark.Core.Reactive; + + using System; + + using System.Collections.Generic; + + using System.Linq; + using System.Reactive.Linq; + + using SecurityKey = System.UInt32; + + [DataStreamUserRespresentation("instruments")] + public class InstrumentsStream : ViewStream, IWorker { + private readonly TimeSpan _poll_period = TimeSpan.FromMilliseconds(500); + private DateTime _last_poll_time = DateTime.MinValue; + private ViewStreamDatabase _vsd; + private int _id = 0; + IReadOnlyDictionary _cached_state = null; + MarketDataClient _md_client; + private bool _dirty = false; + private readonly IBlueTableSchema _instrument_schema = BlueDataUtility.form_schema("instruments", + Tuple.Create("id", TypeCode.Int32), + Tuple.Create("sec_key", TypeCode.UInt32), + Tuple.Create("sec", TypeCode.String), + Tuple.Create("sec_type", TypeCode.String), + Tuple.Create("venue", TypeCode.String), + Tuple.Create("symbol", TypeCode.String), + Tuple.Create("expiration", TypeCode.DateTime), + Tuple.Create("strike", TypeCode.Double), + Tuple.Create("callput", TypeCode.String) + ); + + // TODO: add cons for symbol, exchange etc + public InstrumentsStream() + : this(ViewStreamDatabase.instance) { + } + + public InstrumentsStream(ViewStreamDatabase vsd) { + bts.Log.Gen.info("InstrumentsStream.cons"); + _vsd = vsd; + _md_client = new MarketDataClient(new MDSource(TimeSpan.FromSeconds(0.5))); + } + + protected override void myOnFirstSubscriber() { + _vsd.addWorker(this); + _md_client.securities().Subscribe(_on_instruments); + + } + + private void _log_updates(IReadOnlyDictionary state) { + foreach (SecurityImmutable security in state.Values) { + bts.Log.Gen.info($"InstrumentsStream sec: {security.ToString()}"); + } + } + + private void _on_instruments(IReadOnlyDictionary state) { + _dirty = true; + _log_updates(state); + // just cacching in here, will populate the rows in _poll_scan and fire the datapacket + bts.Log.Gen.info($"InstrumentsStream._on_instruments state: {state.Count()}"); + _cached_state = state; + } + + protected override void myOnLastSubscriber() { + _vsd.removeWorker(this); + } + + private void _scan_instruments() { + // this shouldn be made incremental using the TableUpdate + var count = _cached_state == null ? 0 : _cached_state.Count; + bts.Log.Gen.info($"InstrumentsStream._scan_instruments _cached_state: {count}"); + if (_cached_state == null) + return; + BlueTable new_state = new BlueTable(_instrument_schema); + foreach (var kv in _cached_state) { + SecurityKey skey = kv.Key; + int id = Convert.ToInt32(skey); + SecurityImmutable sec = kv.Value; + bts.api.SecurityType sec_type = sec.security_type(); + object exp = DBNull.Value; + if (sec_type == bts.api.SecurityType.Future || sec_type == bts.api.SecurityType.Option) + exp = sec.security_expiration(); + object strike = DBNull.Value; + if (sec_type == bts.api.SecurityType.Option) + strike = sec.strike(); + object cp = DBNull.Value; + if (sec_type == bts.api.SecurityType.Option) + cp = sec.Option.CallPut.ToString(); + IBlueRow r = new BlueRow(_instrument_schema, id, skey, sec.security_desc(), sec.security_type().ToString(), sec.display_exchange().ToString(), sec.Symbol, exp, strike, cp); + new_state.addRow(r); + } + DataPacket dp = null; + if (myLastValue == null) { + dp = new DataPacket(new_state, new_state, new BlueTable(_instrument_schema)); + } else { + DataPacket old_dp = myLastValue as DataPacket; + IBlueRowCollection added_rows, del_rows; + BlueDataUtility.compute_differences_fast(new_state, old_dp.newRows, out del_rows, out added_rows); + dp = new DataPacket(new_state, added_rows, del_rows); + } + if (dp.addedRows.Count == 0 && dp.deletedRows.Count == 0) + return; + myFireEvent(dp); + } + + public void doWork() { + if (_dirty && DateTime.Now - _last_poll_time > _poll_period) { + _last_poll_time = DateTime.Now; + _dirty = false; + _scan_instruments(); + } + } + } +} \ No newline at end of file diff --git a/src/DataStreamSuite/SharedStreams/Business/MarketData/PriceStatsStream.cs b/src/DataStreamSuite/SharedStreams/Business/MarketData/PriceStatsStream.cs new file mode 100644 index 000000000..56e23cf1f --- /dev/null +++ b/src/DataStreamSuite/SharedStreams/Business/MarketData/PriceStatsStream.cs @@ -0,0 +1,125 @@ +namespace BCG { + using BCG.Utilities.General; + + using bts.api; + using bts.api.domain; + using bts.api.synthetic; + using bts.md; + using bts.spark; + using bts.utils; + + using mbts; + using mbts.co2; + using mbts.config; + using mbts.spark; + using mbts.ui; + + using Spark.Core.Data; + using Spark.Core.Disposables; + using Spark.Core.Reactive; + + using System; + using System.Collections.Concurrent; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Linq; + using System.Reactive.Linq; + using bts.api.core; + using Spark.Api.MarketData; + + using SecurityKey = System.UInt32; + using System.Data; + using System.Reflection.Metadata; + + [DataStreamUserRespresentation("price_stats")] + public class PriceStatsStream : ViewStream, IWorker { + private readonly TimeSpan _poll_period = TimeSpan.FromMilliseconds(500); + private DateTime _last_poll_time = DateTime.MinValue; + private ViewStreamDatabase _vsd; + private int _id = 0; + IReadOnlyDictionary _cached_state = null; + MarketDataClient _md_client; + private bool _dirty = false; + private readonly IBlueTableSchema _pstats_scheam = BlueDataUtility.form_schema("bbo", + Tuple.Create("id", TypeCode.Int32), + Tuple.Create("sec_key", TypeCode.Int32), + Tuple.Create("sec", TypeCode.String), + Tuple.Create("open", TypeCode.UInt32), + Tuple.Create("close", TypeCode.Double), + Tuple.Create("settlement", TypeCode.Single)); + + // TODO: add cons for symbol, exchange etc + public PriceStatsStream() + : this(ViewStreamDatabase.instance) { + } + + public PriceStatsStream(ViewStreamDatabase vsd) { + bts.Log.Gen.info("PriceStatsStream.cons"); + _vsd = vsd; + _md_client = new MarketDataClient(new MDSource(TimeSpan.FromSeconds(0.5))); + } + + protected override void myOnFirstSubscriber() { + _vsd.addWorker(this); + _md_client.price_stats().Subscribe(_on_price_stats); + } + + private void _log_updates(TableUpdate update) { + int i = 0; + // foreach (BookTuple bt in update.added) { + // bts.Log.Gen.info($"PriceStatsStream added: idx: {i++} bid: {bt.book.bids[0].price} / {bt.book.bids[0].size} ask: {bt.book.asks[0].price} / {bt.book.asks[0].size}"); + // } + // foreach (Change c in update.changes) { + // var bt = c.New; + // bts.Log.Gen.info($"PriceStatsStream changes: idx: {i} bid: {bt.book.bids[0].price} / {bt.book.bids[0].size} ask: {bt.book.asks[0].price} / {bt.book.asks[0].size}"); + // } + } + + private void _on_price_stats(TableUpdate update) { + _log_updates(update); + // just cacching in here, will populate the rows in _poll_scan and fire the datapacket + bts.Log.Gen.info($"PriceStatsStream._on_price_stats state: {update.state.Count()} changes: {update.changes.Count()} added: {update.added.Count()}"); + _cached_state = update.state; + _dirty = false; + } + + protected override void myOnLastSubscriber() { + _vsd.removeWorker(this); + } + + private void _scan() { + // this shouldn be made incremental using the TableUpdate + bts.Log.Gen.info("PriceStatsStream._scan_bbo"); + if (_cached_state == null) + return; + BlueTable new_state = new BlueTable(_pstats_scheam); + foreach (var kv in _cached_state) { + SecurityKey skey = kv.Key; + int id = Convert.ToInt32(skey); + PriceStats pstats = kv.Value; + IBlueRow r = new BlueRow(_pstats_scheam, id, skey, pstats.security.ToString(), pstats.open, pstats.close, pstats.settlement); + new_state.addRow(r); + } + DataPacket dp = null; + if (myLastValue == null) { + dp = new DataPacket(new_state, new_state, new BlueTable(_pstats_scheam)); + } else { + DataPacket old_dp = myLastValue as DataPacket; + IBlueRowCollection added_rows, del_rows; + BlueDataUtility.compute_differences_fast(new_state, old_dp.newRows, out del_rows, out added_rows); + dp = new DataPacket(new_state, added_rows, del_rows); + } + if (dp.addedRows.Count == 0 && dp.deletedRows.Count == 0) + return; + myFireEvent(dp); + } + + public void doWork() { + if (_dirty && DateTime.Now - _last_poll_time > _poll_period) { + _last_poll_time = DateTime.Now; + _dirty = false; + _scan(); + } + } + } +} \ No newline at end of file diff --git a/src/DataStreamSuite/SharedStreams/Business/MarketData/TimSeriesOperations/TimeSeriesGroupByStream.cs b/src/DataStreamSuite/SharedStreams/Business/MarketData/TimSeriesOperations/TimeSeriesGroupByStream.cs new file mode 100644 index 000000000..823c4ca3e --- /dev/null +++ b/src/DataStreamSuite/SharedStreams/Business/MarketData/TimSeriesOperations/TimeSeriesGroupByStream.cs @@ -0,0 +1,117 @@ +namespace BCG { + using bts.api.orderman; + + enum TSGroupByOperation { + OHLC = 0, + Statistics + } + + [DataStreamUserRespresentation("timeseriesanalysis")] + public class TimeSeriesGroupByStream : ViewStream { + public TimeSeriesGroupByStream(ViewStream md_str, string timestamp_col, string output_col, string operation) { + ViewStream rs = new NonIncGroupByStream(md_str, new OHLCNonIncGroupByEvaluator(timestamp_col, output_col)); + mySetRealSource(rs); + } + } + public class OHLC { + public OHLC(double open_args, double high_args, double low_args, double close_args) { + open = open_args; + high = high_args; + low = low_args; + close = close_args; + } + public readonly double open, high, low, close; + } + public class OHLCNonIncGroupByEvaluator : INonIncGroupByEvaluator { + private string _timestamp_col; + private string _output_col; + private IBlueTableSchema _out_schema; + public OHLCNonIncGroupByEvaluator(string timestamp_col, string output_col) { + _timestamp_col = timestamp_col; + _output_col = output_col; + } + + string open_col { + get { + return $"{_output_col}_open"; ; + } + } + string high_col { + get { + return $"{_output_col}_high"; ; + } + } + string low_col { + get { + return $"{_output_col}_low"; ; + } + } + string close_col { + get { + return $"{_output_col}_close"; ; + } + } + private void _build_schema(IBlueTableSchema input_schema) { + List> new_cols = new List>(); + ColumnInfo ci = input_schema[_output_col]; + new_cols.Add(Tuple.Create(ci.colType, open_col)); + new_cols.Add(Tuple.Create(ci.colType, high_col)); + new_cols.Add(Tuple.Create(ci.colType, low_col)); + new_cols.Add(Tuple.Create(ci.colType, close_col)); + // should hide the output col + _out_schema = BlueDataUtility.add_columns(input_schema, new_cols.ToArray()); + } + + public IBlueRowCollection evaluate(IDictionary> grouped_rows) { + if (_out_schema == null) { + if (grouped_rows.Count > 0) { + foreach (var kv in grouped_rows) { + var rows = kv.Value; + if (rows != null && rows.Count > 0) { + _build_schema(rows.ElementAt(0).schema); + } + } + } + } + BlueTable rv = new BlueTable(_out_schema); + foreach (var kv in grouped_rows) { + int id = kv.Key; + IEnumerable rows = kv.Value; + // sort rows on time to compute o,c correctly?? + if (rows != null && rows.Count() > 0) { + IBlueRow reprow = rows.ElementAt(0); + IEnumerable vals = BlueDataUtility.get_covalues(rows, _output_col); + OHLC ohlc = compute_ohlc(vals); + MutableBlueRow nr = new MutableBlueRow(_out_schema, reprow); + nr.setValue("id", kv.Key); + nr.setValue(open_col, ohlc.open); + nr.setValue(high_col, ohlc.high); + nr.setValue(low_col, ohlc.low); + nr.setValue(close_col, ohlc.close); + rv.addRow(nr); + } + } + return rv; + } + + public string[] get_group_by_cols() { + return new string[] { _timestamp_col }; + } + + static OHLC compute_ohlc(IEnumerable prices) { + double o = prices.ElementAt(0); + double c = prices.ElementAt(prices.Count() - 1); + double l = prices.Min(); + double h = prices.Max(); + return new(o, h, l, c); + } + } + [DataStreamUserRespresentation("ohlc")] + public class OHLCStream : ViewStream { + // for ms_str expects a timeseries with a timestamp col and an output col (price col) to calculate the ohlc for + public OHLCStream(ViewStream md_str, string timestamp_col, string output_col) { + ViewStream rs = new TimeSeriesGroupByStream(md_str, timestamp_col, output_col, TSGroupByOperation.OHLC.ToString()); + mySetRealSource(rs); + } + } +} \ No newline at end of file diff --git a/src/DataStreamSuite/SharedStreams/Business/MarketData/TimeSalesStream.cs b/src/DataStreamSuite/SharedStreams/Business/MarketData/TimeSalesStream.cs new file mode 100644 index 000000000..adcd48b33 --- /dev/null +++ b/src/DataStreamSuite/SharedStreams/Business/MarketData/TimeSalesStream.cs @@ -0,0 +1,93 @@ +namespace BCG { + using BCG.Utilities.General; + + using bts.api; + using bts.md; + + using mbts.spark; + + using Spark.Core.Reactive; + + using System; + using System.Collections.Concurrent; + using System.Collections.Generic; + + using System.Linq; + using System.Reactive.Linq; + using Spark.Api.MarketData; + + using SecurityKey = System.UInt32; + + [DataStreamUserRespresentation("timesales")] + public class TimeSalesStream : ViewStream, IWorker { + private readonly TimeSpan _poll_period = TimeSpan.FromMilliseconds(500); + private DateTime _last_poll_time = DateTime.MinValue; + private ViewStreamDatabase _vsd; + private int _id = 0; + IReadOnlyDictionary _cached_state = null; + MarketDataClient _md_client; + private bool _dirty = false; + private ConcurrentQueue _cached_trades = new ConcurrentQueue(); + private BlueTable _table = new BlueTable(BlueDataUtility.form_schema("instruments", + Tuple.Create("id", TypeCode.Int32), + Tuple.Create("sec_key", TypeCode.UInt32), + Tuple.Create("sec", TypeCode.String), + Tuple.Create("time", TypeCode.Int64), + Tuple.Create("price", TypeCode.Double), + Tuple.Create("qty", TypeCode.UInt32), + Tuple.Create("aggressor", TypeCode.String) + )); + public TimeSalesStream() + : this(ViewStreamDatabase.instance) { + } + + public TimeSalesStream(ViewStreamDatabase vsd) { + bts.Log.Gen.info("TimeSalesStream.cons"); + _vsd = vsd; + _md_client = new MarketDataClient(new MDSource(TimeSpan.FromSeconds(0.5))); + } + + protected override void myOnFirstSubscriber() { + _vsd.addWorker(this); + _md_client.trades(new TradesSubscriptionFilter()).Subscribe(_on_trades); + //_md_client.trades(null).Subscribe(_on_trades); + + } + + private void _log_updates(IList trades) { + bts.Log.Gen.info($"TimeSalesStream update sz: {trades.Count}"); + } + + private void _on_trades(IList trades) { + _dirty = true; + _log_updates(trades); + // just cacching in here, will populate the rows in _poll_scan and fire the datapacket + bts.Log.Gen.info($"TimeSalesStream._on_trades trades: {trades.Count()}"); + foreach (var t in trades) + _cached_trades.Enqueue(t); + } + + protected override void myOnLastSubscriber() { + _vsd.removeWorker(this); + } + + private void _scan_trades() { + BlueTable added_rows = new BlueTable(_table.schema); + foreach (TradeInfo tinf in _cached_trades) { + IBlueRow r = new BlueRow(_table.schema, _id++, tinf.security.Id, tinf.security.ToString(), tinf.trade.Time, tinf.trade.Mantissa, tinf.trade.Size, tinf.trade.AggressorSide.ToString()); + added_rows.addRow(r); + } + _table.addRows(added_rows); + if (added_rows.Count > 0) + myFireEvent(new DataPacket(_table, added_rows, new BlueTable(_table.schema))); + } + + public void doWork() { + if (_dirty && DateTime.Now - _last_poll_time > _poll_period) { + _last_poll_time = DateTime.Now; + _dirty = false; + _scan_trades(); + } + } + } +} \ No newline at end of file diff --git a/src/DataStreamSuite/SharedStreams/SharedStreams.csproj b/src/DataStreamSuite/SharedStreams/SharedStreams.csproj index 7ab108c61..ac8a63aef 100644 --- a/src/DataStreamSuite/SharedStreams/SharedStreams.csproj +++ b/src/DataStreamSuite/SharedStreams/SharedStreams.csproj @@ -14,4 +14,8 @@ + + + + diff --git a/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs b/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs index 2bee846ed..4dcfdf5fe 100644 --- a/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs +++ b/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs @@ -19,28 +19,35 @@ using Spark.Core.Protobuf; using mbts.ui; // using mbts.bb; -namespace mbts.spark { - internal class ResourceAllocator : IDisposable { +namespace mbts.spark +{ + internal class ResourceAllocator : IDisposable + { private List _disps = new List(); private Dictionary _option_driver_map = new Dictionary(); ThreadedBlackboard _bb; - public ResourceAllocator(IBus bus, ThreadedBlackboard bb) { + public ResourceAllocator(IBus bus, ThreadedBlackboard bb) + { bts.Log.Gen.info("ResourceAllocator started"); _bb = bb; var s = bus.subscribe(SparkTags.SystemContractsTag).OnDispatcher().Subscribe(_on_data); _disps.Add(s); } - private void _on_data(SystemContractData d) { + private void _on_data(SystemContractData d) + { bts.Log.Gen.info(String.Format("ResourceAllocator._on_data sz: {0}", d.sec_md_map.Count())); - foreach (SecurityTuple sec_tup in d.get_options()) { - if (!_option_driver_map.ContainsKey(sec_tup)) { + foreach (SecurityTuple sec_tup in d.get_options()) + { + if (!_option_driver_map.ContainsKey(sec_tup)) + { bts.Log.Gen.info($"ResourceAllocator._on_data allocating SingleOptionDriverPricePublisher for '{sec_tup}'"); _option_driver_map.Add(sec_tup, new SingleOptionDriverPricePublisher(sec_tup, _bb)); } } } - public void Dispose() { + public void Dispose() + { _disps.ForEach(d => d.Dispose()); } } @@ -54,7 +61,8 @@ namespace mbts.spark { // - Activation Tag for newly created VS's (VolSurfaceActivationTag) (retired) // 2. Listens to the activation tag (also published by the UI) and // creates the SingleVolSurfaceManager for the VS - public class VolSurfaceBusManager : IDisposable { + public class VolSurfaceBusManager : IDisposable + { private List _disps = new List(); private ThreadedBlackboard _bb; private bts.api.analytics.AnalyticsService _analytics_service; @@ -78,7 +86,8 @@ namespace mbts.spark { public VolSurfaceBusManager(bts.api.IBus bus, bts.api.analytics.AnalyticsService analytics_service, - bts.api.orderman.OrderService order_service) { + bts.api.orderman.OrderService order_service) + { bts.Log.Ui.info("VSBusManager cons tid:{VolSurfaceTroubleshootingFunctions.tid()}"); _bus = bus; _bb = new ThreadedBlackboard("AW2", bus); @@ -115,29 +124,37 @@ namespace mbts.spark { _subs.Add(new InterpTheosServerPublisher(_bb, order_service)); _subs.Add(new VolSurfaceInterpGreeksMultiplexer(_bb)); // usage - var list_sub = _bus.subscribe(SparkTags.VolSurfaceListTag).OnDispatcher().Subscribe(t => { + var list_sub = _bus.subscribe(SparkTags.VolSurfaceListTag).OnDispatcher().Subscribe(t => + { VolSurfaceUsageList ulist = new VolSurfaceUsageList(); IDictionary name_to_ids = new Dictionary(); - foreach (var kv in t) { + foreach (var kv in t) + { name_to_ids[kv.Value] = kv.Key; } Log.Ui.info($"VolSurfaceUsageList name_to_ids count: {name_to_ids.Count}"); var vs_usage = mbts.config.Configuration.get(); Log.Ui.info($"VolSurfaceUsageList vs_usage acount: {vs_usage.Items.Count}"); - foreach (var u in vs_usage.Items) { + foreach (var u in vs_usage.Items) + { string option_name = u.OptionName; string vs_name = u.VsName; int vs_key; - if (name_to_ids.TryGetValue(vs_name, out vs_key)) { - ulist.UsageList.Add(new VolSurfaceUsageEntry() { + if (name_to_ids.TryGetValue(vs_name, out vs_key)) + { + ulist.UsageList.Add(new VolSurfaceUsageEntry() + { VsId = vs_key, - SecTup = new bts.api.SecurityTuple { + SecTup = new bts.api.SecurityTuple + { Type = SecurityType.Option, Venue = Venue.Deribit, Symbol = option_name } }); - } else { + } + else + { Log.Gen.error($"Could not find vol surface with name: {vs_name}"); } } @@ -153,7 +170,8 @@ namespace mbts.spark { _bus.subscribe(SparkTags.TC2Tags.AllLiveTheosTag) .CombineLatest(bus.subscribe(SparkTags.SystemContractsTag), (theos, sc_data) => (theos, sc_data)).Subscribe( - tup => { + tup => + { var keyed_theos = _assemble_keyed_theos(tup.sc_data, tup.theos); _bus.post(SparkTags.KeyedTheos, keyed_theos); } @@ -163,33 +181,40 @@ namespace mbts.spark { static IReadOnlyDictionary _assemble_keyed_theos( SystemContractData sc_data, - IReadOnlyDictionary> theos) { - if (sc_data is null || theos is null) { + IReadOnlyDictionary> theos) + { + if (sc_data is null || theos is null) + { return new Dictionary(0); } HighPerformanceTimer timer = new HighPerformanceTimer(); timer.start(); Dictionary rv = new Dictionary(); - foreach (var kv in theos) { + foreach (var kv in theos) + { var symbol = kv.Key; ExpStrikeKeyedData sym_theos = kv.Value; if (sym_theos == null) continue; - foreach (var s_kv in sym_theos.get_data_linearly()) { + foreach (var s_kv in sym_theos.get_data_linearly()) + { DateTime exp = s_kv.first; double strike = s_kv.second; TheoPoint tp = s_kv.third; // TODO: fix exchange later Tuple keys = sc_data.get_option_sec_id(Venue.Deribit, symbol, exp, strike); - if (keys != null) { + if (keys != null) + { var c_key = keys.Item1; var p_key = keys.Item2; - if (c_key.HasValue) { + if (c_key.HasValue) + { rv[c_key.Value] = new VolSurfaceTheoPoint(tp, true); } - if (p_key.HasValue) { + if (p_key.HasValue) + { rv[p_key.Value] = new VolSurfaceTheoPoint(tp, false); } } @@ -201,78 +226,100 @@ namespace mbts.spark { return rv; } - public ThreadedBlackboard bb() { + public ThreadedBlackboard bb() + { return _bb; } - void _spin_vss(VolSurfaceUsageListImmutable ulist) { - foreach (var u in ulist.UsageList) { + void _spin_vss(VolSurfaceUsageListImmutable ulist) + { + foreach (var u in ulist.UsageList) + { var vs_id = u.VsId; _bb.post(SparkTags.VolSurfaceActiveUITag(vs_id), true); } } - void _on_vs_usage_update(Update update) { + void _on_vs_usage_update(Update update) + { // TODO return; } - void _on_vss(bts.api.core.Update update) { + void _on_vss(bts.api.core.Update update) + { bts.Log.Gen.info(String.Format("VSBusManager._on_vss tid:{0} count:{1}", System.Threading.Thread.CurrentThread.ManagedThreadId, update.all.Count())); IDictionary to_publish = new Dictionary(); // publish a dictionary of vs id vs vs names - foreach (VolSurfaceEntryImmutable vs in update.all) { + foreach (VolSurfaceEntryImmutable vs in update.all) + { to_publish[vs.VsId] = vs.VsName; } _bb.post(SparkTags.VolSurfaceListTag, to_publish); _init_vss(to_publish.Keys); } - private void _init_vss(IEnumerable vs_ids) { + private void _init_vss(IEnumerable vs_ids) + { // we consider every vs in the db as "activated" which might prove to be expensive // (will take care of it later) - foreach (var vs_id in vs_ids) { - if (!_vs_manager_map.ContainsKey(vs_id)) { + foreach (var vs_id in vs_ids) + { + if (!_vs_manager_map.ContainsKey(vs_id)) + { _vs_manager_map.Add(vs_id, new SingleVolSurfaceManager( vs_id, _bb, _analytics_service)); } } } - private void _on_bb_update(object tag, object data) { - if (_in_scdata_tag.Equals(tag)) { + private void _on_bb_update(object tag, object data) + { + if (_in_scdata_tag.Equals(tag)) + { _contract_data = _bb.read_state(_in_scdata_tag); } - if (_in_bb_create_tag.Equals(tag)) { + if (_in_bb_create_tag.Equals(tag)) + { // creations are written in a queue and handled later in the timer // callback mbts.analytics.VolSurfaceSettings vs_settings = data as mbts.analytics.VolSurfaceSettings; bts.Log.Gen.info(String.Format("VSBusManager._on_bb_update received vs creation tag vs:{0}", ProtobufSerializationHelper.serialize_to_string(vs_settings))); _waiting_creations.Enqueue(vs_settings); - } else if (_in_bb_delete_tag.Equals(tag)) { + } + else if (_in_bb_delete_tag.Equals(tag)) + { int vs_id = (int)data; - try { + try + { IntWrapper vs_id_w = new IntWrapper(); vs_id_w.Data = vs_id; _analytics_service.delete_volsurface(vs_id_w); - } catch (Exception ex) { + } + catch (Exception ex) + { Log.Gen.error(String.Format("Vol Surface deletion failed with exception:{0}", ex.Message)); _bb.post(SparkTags.MessageDisplayTag, new MessageDisplayData("Vol Surface Deletion", String.Format("Could not delete Vol Surface, Error : {0}", ex.Message))); } - } else if (_in_bb_exp_params_tag.Equals(tag)) { + } + else if (_in_bb_exp_params_tag.Equals(tag)) + { AnalyticsExpirationParametersMap exp_param_map = data as AnalyticsExpirationParametersMap; // TODO, add whatever else is needed to AnalyticsExpirationParametersMap -> VolSurfaceNonVolInputTag _bb.post(SparkTags.VolSurfaceNonVolInputTag, new mbts.analytics.VolSurfaceNonVolInput(exp_param_map.exp_map.ToDictionary())); - } else if (_in_bb_req_vol.Equals(tag)) { + } + else if (_in_bb_req_vol.Equals(tag)) + { ClientArchivedVolRequest client_req = _bb.read_state(_in_bb_req_vol); bts.Log.Ui.info($"VolSurfaceBusManager._on_bb_update ClientArchivedVolRequest: {client_req.ToString()}"); ArchivedTheoRetrieval ret = client_req.ret; - if (ret == null || ret.SecTup == null) { + if (ret == null || ret.SecTup == null) + { bts.Log.Ui.warn($"VolSurfaceBusManager malformed ArchivedTheoRetrieval"); ArchivedTheoList empty = new ArchivedTheoList(); _bb.post(SparkTags.ResponseArchivedVols, Tuple.Create(client_req, empty)); @@ -290,25 +337,30 @@ namespace mbts.spark { } private int _timer_count = 0; - private void _on_timer() { - Action report_err = (string err_txt) => { + private void _on_timer() + { + Action report_err = (string err_txt) => + { Log.Gen.error(String.Format("VSBusManager, creation failed with message:{0}", err_txt)); _bb.post(SparkTags.MessageDisplayTag, new MessageDisplayData("Vol Surface Addition", String.Format("Could not create Vol Surface, Error : {0}", err_txt))); }; bts.Log.Gen.diag(String.Format("VSBusManager._on_timer tid:{0} count:{1}", System.Threading.Thread.CurrentThread.ManagedThreadId, _timer_count++)); - if (_waiting_creations.Count == 0) { + if (_waiting_creations.Count == 0) + { return; } - if (_contract_data == null) { + if (_contract_data == null) + { return; } mbts.analytics.VolSurfaceSettings vs_settings = _waiting_creations.Dequeue(); IDictionary> exp_map = _contract_data.get_option_expirations(VolSurfaceDataFunctions.get_symbols(vs_settings), false); VolSurfaceInput vs_input = mbts.analytics.VolSurfaceDataFunctions.get_default_vs_input(vs_settings, exp_map); var reply = _analytics_service.get_new_volsurface_id(new VoidMessage()); - if (!reply.Ok) { + if (!reply.Ok) + { report_err("Could not obtain new ID"); return; } @@ -317,7 +369,8 @@ namespace mbts.spark { _timer.start(); ResultMessage res = VolSurfaceUtilityFunctions.save_volsurface(vs_input, _analytics_service); _timer.stop(); - if (!res.Success) { + if (!res.Success) + { report_err(res.ErrorMessage); return; } @@ -327,7 +380,8 @@ namespace mbts.spark { _bb.post(SparkTags.VolSurfaceActivationTag(reply.NewId), true, false); } - public void Dispose() { + public void Dispose() + { _subs.ForEach(s => s.Dispose()); } diff --git a/src/client/spark/AW2/Misc/Pair.cs b/src/client/spark/AW2/Misc/Pair.cs index 558a29b8b..5d33ae404 100644 --- a/src/client/spark/AW2/Misc/Pair.cs +++ b/src/client/spark/AW2/Misc/Pair.cs @@ -1,78 +1,78 @@ -using ProtoBuf; +// using ProtoBuf; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Media; +// using System; +// using System.Collections.Generic; +// using System.Linq; +// using System.Text; +// using System.Threading.Tasks; +// using System.Windows; +// using System.Windows.Media; -namespace mbts.spark { - // TODO move it out or replace it with Tuple - [Serializable] - public class Pair { - public F first; - public S second; +// namespace mbts.spark { +// // TODO move it out or replace it with Tuple +// [Serializable] +// public class Pair { +// public F first; +// public S second; - public Pair() { } - public Pair(F f, S s) { - first = f; - second = s; - } +// public Pair() { } +// public Pair(F f, S s) { +// first = f; +// second = s; +// } - public Pair(KeyValuePair kvp) - : this(kvp.Key, kvp.Value) { } +// public Pair(KeyValuePair kvp) +// : this(kvp.Key, kvp.Value) { } - public override string ToString() { - return String.Format("{0},{1}", first != null ? first.ToString() : "NULL", - second != null ? second.ToString() : "NULL"); - } +// public override string ToString() { +// return String.Format("{0},{1}", first != null ? first.ToString() : "NULL", +// second != null ? second.ToString() : "NULL"); +// } - public override int GetHashCode() { - return ToString().GetHashCode(); - } +// public override int GetHashCode() { +// return ToString().GetHashCode(); +// } - public override bool Equals(object obj) { - return obj != null && obj is Pair && ToString() == obj.ToString(); - } - } +// public override bool Equals(object obj) { +// return obj != null && obj is Pair && ToString() == obj.ToString(); +// } +// } - [Serializable] - public class Triplet { - public F first; - public S second; - public T third; +// [Serializable] +// public class Triplet { +// public F first; +// public S second; +// public T third; - public Triplet() { } +// public Triplet() { } - public Triplet(Tuple tp) { - first = tp.Item1; - second = tp.Item2; - third = tp.Item3; - } +// public Triplet(Tuple tp) { +// first = tp.Item1; +// second = tp.Item2; +// third = tp.Item3; +// } - public Triplet(F f, S s, T t) { - first = f; - second = s; - third = t; - } +// public Triplet(F f, S s, T t) { +// first = f; +// second = s; +// third = t; +// } - public static Triplet from_tuple(Tuple t) { return new Triplet(t.Item1, t.Item2, t.Item3); } +// public static Triplet from_tuple(Tuple t) { return new Triplet(t.Item1, t.Item2, t.Item3); } - public override string ToString() { - return String.Format("{0},{1},{2}", first != null ? first.ToString() : "NULL", - second != null ? second.ToString() : "NULL", - third != null ? third.ToString() : "NULL"); - } +// public override string ToString() { +// return String.Format("{0},{1},{2}", first != null ? first.ToString() : "NULL", +// second != null ? second.ToString() : "NULL", +// third != null ? third.ToString() : "NULL"); +// } - public override bool Equals(object obj) { - return obj != null && obj is Triplet && ToString() == obj.ToString(); - } +// public override bool Equals(object obj) { +// return obj != null && obj is Triplet && ToString() == obj.ToString(); +// } - public override int GetHashCode() { - return ToString().GetHashCode(); - } - } +// public override int GetHashCode() { +// return ToString().GetHashCode(); +// } +// } -} +// } diff --git a/src/client/spark/Daemons/MergedMDDaemon.cs b/src/client/spark/Daemons/MergedMDDaemon.cs index 780af2edd..72d9c0cf9 100644 --- a/src/client/spark/Daemons/MergedMDDaemon.cs +++ b/src/client/spark/Daemons/MergedMDDaemon.cs @@ -23,9 +23,11 @@ using System.Threading.Tasks; using SecurityKey = System.UInt32; -namespace bts { +namespace bts +{ [Export(typeof(IShellDaemon))] - internal class MergedMDDaemon : IShellDaemon, IDisposable { + internal class MergedMDDaemon : IShellDaemon, IDisposable + { private readonly IBus _bus; IDisposable _dispose; Dictionary _server_sec_map = new Dictionary(); @@ -33,7 +35,8 @@ namespace bts { private readonly IList _subs = new List(); [ImportingConstructor] - public MergedMDDaemon(IBus bus) { + public MergedMDDaemon(IBus bus) + { //TempTester.test_analytics(); bts.Log.Gen.info("MergedMDDaemon started"); _bus = bus; @@ -46,17 +49,43 @@ namespace bts { // works with the various UI windows) // _subs.Add(_bus.subscribe(SparkTags.SparkTimer).BufferLatest(TimeSpan.FromMinutes(1)) // .Subscribe(t => _merge_and_post())); + //_test_md_stream(); + } + // BCG.MDStream _md_stream = null; + // private void _test_md_stream() + // { + // _bus.subscribe(SparkTags.SparkTimer).Subscribe(t => + // { + // if (_md_stream == null) + // { + // _md_stream = new BCG.MDStream(); + // _md_stream.onChange += _on_md; + // } + // else + // { + // BCG.ViewStreamDatabase.instance.doWork(); + // } + // }); + // } + + private void _on_md(object obj) + { + BCG.DataPacket dp = obj as DataPacket; + bts.Log.Gen.info($"MDStream callback dp: {dp}"); } - private void _log_options(IReadOnlyDictionary sec_map) { + private void _log_options(IReadOnlyDictionary sec_map) + { string rv = "MergedMDDaemon Options:\n"; - foreach (var kv in sec_map) { + foreach (var kv in sec_map) + { var sec = kv.Value.security; var md = kv.Value.md; ulong time = 0; NativePriceSize bid, ask; var has_md = md.get_bbo(ref time, out bid, out ask); - if (sec.HasOption) { + if (sec.HasOption) + { rv += $"id: {kv.Key} desc: {sec.security_desc()} sym: {sec.Symbol} " + $"exp: {sec.security_expiration()} " + $"k: {sec.Option.Strike} cp: {sec.Option.CallPut} " + @@ -67,26 +96,31 @@ namespace bts { Log.Gen.info(rv); } - private void _on_server_sec_map(IReadOnlyDictionary sec_map) { + private void _on_server_sec_map(IReadOnlyDictionary sec_map) + { //_log_options(sec_map); bts.Log.Gen.info(String.Format("MergedMDDaemon._on_server_sec_map sz: {0}", sec_map.Count())); _server_sec_map = new Dictionary(sec_map); _merge_and_post(); } - private void _on_fake_sec_map(IReadOnlyDictionary sec_map) { + private void _on_fake_sec_map(IReadOnlyDictionary sec_map) + { bts.Log.Gen.info(String.Format("MergedMDDaemon._on_fake_sec_map sz: {0}", sec_map.Count())); _fake_sec_map = new Dictionary(sec_map); _merge_and_post(); } - private void _merge_and_post() { - Func is_active = (sec_md) => { + private void _merge_and_post() + { + Func is_active = (sec_md) => + { var sec = sec_md.security; return SecurityExpirationHelper.is_unexpired(sec); }; var to_pub = _server_sec_map.Where(kv => is_active(kv.Value)).ToDictionary(kv => kv.Key, kv => kv.Value); - foreach (var kv in _fake_sec_map) { + foreach (var kv in _fake_sec_map) + { to_pub[kv.Key] = kv.Value; } bts.Log.Gen.info(String.Format("MergedMDDaemon._merge_and_post sz: {0}", to_pub.Count())); diff --git a/src/client/spark/NMSheets/BlackboardStructure/MNSheetTheoRequest.cs b/src/client/spark/NMSheets/BlackboardStructure/MNSheetTheoRequest.cs index 196648ed8..baabfbc7d 100644 --- a/src/client/spark/NMSheets/BlackboardStructure/MNSheetTheoRequest.cs +++ b/src/client/spark/NMSheets/BlackboardStructure/MNSheetTheoRequest.cs @@ -3,21 +3,24 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; - +using mbts; using mbts.spark; -namespace BCG { +namespace BCG +{ /// This is the theo request for an NMSheetGrid. Its send out by /// the driver stip at the top (NMSheetDriverControlStrip). The /// NMSheetSingleOptionMainDataSource filters it for its own /// symbol and computes the data. - public class NMSheetDataRequest { + public class NMSheetDataRequest + { public readonly IEnumerable> expiration_request_list; public NMSheetDataRequest(IEnumerable> the_expiration_request_list) { expiration_request_list = the_expiration_request_list; } /// Returns a new request thats restricted for the /// symbol in the argument - public static NMSheetDataRequest restrict_for_symbol(NMSheetDataRequest request, NMSheetSymbol option_symbol) { + public static NMSheetDataRequest restrict_for_symbol(NMSheetDataRequest request, NMSheetSymbol option_symbol) + { List> rv = new List>(); foreach (Triplet t in request.expiration_request_list) if (t.first.option_name == option_symbol.option_name && t.first.option_exchange == option_symbol.option_exchange) @@ -27,7 +30,8 @@ namespace BCG { /// Returns a new request thats restricted for the /// symbol in the argument - public static NMSheetDataRequest restrict_for_expirations(NMSheetDataRequest request, IEnumerable exps) { + public static NMSheetDataRequest restrict_for_expirations(NMSheetDataRequest request, IEnumerable exps) + { HashSet exp_map = new HashSet(exps); List> rv = new List>(); foreach (Triplet t in request.expiration_request_list) diff --git a/src/client/spark/NMSheets/BlackboardStructure/NMSheetSingleOptionData.cs b/src/client/spark/NMSheets/BlackboardStructure/NMSheetSingleOptionData.cs index 05f1eb376..8e2fbe453 100644 --- a/src/client/spark/NMSheets/BlackboardStructure/NMSheetSingleOptionData.cs +++ b/src/client/spark/NMSheets/BlackboardStructure/NMSheetSingleOptionData.cs @@ -6,7 +6,7 @@ using System.Text; using mbts.ui; using bts.utils; using mbts.spark; - +using mbts; namespace BCG { /// /// Holds together data for one NMSheetSymbol. Its constructed by diff --git a/src/client/spark/NMSheets/BlackboardStructure/NMSheetSingleOptionDataTaskEye.cs b/src/client/spark/NMSheets/BlackboardStructure/NMSheetSingleOptionDataTaskEye.cs index 1b4efadf2..bbb2991da 100644 --- a/src/client/spark/NMSheets/BlackboardStructure/NMSheetSingleOptionDataTaskEye.cs +++ b/src/client/spark/NMSheets/BlackboardStructure/NMSheetSingleOptionDataTaskEye.cs @@ -1,16 +1,19 @@ using System; using bts.api; - +using mbts; using mbts.spark; using mbts.ui; -namespace BCG { - public partial class NMSheetSingleOptionData { +namespace BCG +{ + public partial class NMSheetSingleOptionData + { // Gets the data from the bus, and fills in out_eye_data, and cp_row private void _fill_eye_data(Triplet tp_with_seckeys, ref double[] cp_row, - out NMSheetCallPutBidAskWrapper out_eye_data) { + out NMSheetCallPutBidAskWrapper out_eye_data) + { NMSheetTaskEyeData call_bid_data, call_ask_data, put_bid_data, put_ask_data; // call _get_eye_security_side_data(tp_with_seckeys.second, Side.Buy, out call_bid_data); @@ -23,7 +26,8 @@ namespace BCG { } private void _get_eye_security_side_data(uint sec_key, Side side, - out NMSheetTaskEyeData inp_out_data) { + out NMSheetTaskEyeData inp_out_data) + { inp_out_data = null; if (_ee_tasking_data == null) return; diff --git a/src/client/spark/NMSheets/BlackboardStructure/NMSheetSingleOptionDataTaskQuoter.cs b/src/client/spark/NMSheets/BlackboardStructure/NMSheetSingleOptionDataTaskQuoter.cs index 35d88217c..2607f395d 100644 --- a/src/client/spark/NMSheets/BlackboardStructure/NMSheetSingleOptionDataTaskQuoter.cs +++ b/src/client/spark/NMSheets/BlackboardStructure/NMSheetSingleOptionDataTaskQuoter.cs @@ -1,12 +1,15 @@ using System; using bts.api; - +using mbts; using mbts.spark; -namespace BCG { - public partial class NMSheetSingleOptionData { - private void _fill_quoter_data(Triplet tp_with_seckeys, Tuple driver_bid_ask, double[] cp_row, out NMSheetCallPutBidAskWrapper out_quoter_data) { +namespace BCG +{ + public partial class NMSheetSingleOptionData + { + private void _fill_quoter_data(Triplet tp_with_seckeys, Tuple driver_bid_ask, double[] cp_row, out NMSheetCallPutBidAskWrapper out_quoter_data) + { NMSheetTaskQuoterData call_bid_data, call_ask_data, put_bid_data, put_ask_data; _get_quoter_security_side_data(tp_with_seckeys.first, PutOrCall.Call, Side.Buy, tp_with_seckeys.second, driver_bid_ask, out call_bid_data, ref cp_row, NMSheetColumnName.call_quoter_set_bid_edge, NMSheetColumnName.call_quoter_set_bid_size, NMSheetColumnName.call_quoter_bid_price, NMSheetColumnName.call_quoter_bid_size); @@ -23,7 +26,8 @@ namespace BCG { out NMSheetTaskQuoterData sheet_quoter_data, ref double[] out_array, NMSheetColumnName inp_edge_col, NMSheetColumnName inp_size_col, - NMSheetColumnName quoter_price_col, NMSheetColumnName quoter_size_col) { + NMSheetColumnName quoter_price_col, NMSheetColumnName quoter_size_col) + { out_array = new double[] { }; sheet_quoter_data = new NMSheetTaskQuoterData(new mbts.tasks.TaskSecurityQuoterData()); // mbts.tasks.TaskSecurityQuoterData quoter_data = _tasking_data.get_quoter_data(sec_key, side); diff --git a/src/client/spark/NMSheets/DataProviders/NMSheetMainDataSource.cs b/src/client/spark/NMSheets/DataProviders/NMSheetMainDataSource.cs index 81641f8bb..01603ad1f 100644 --- a/src/client/spark/NMSheets/DataProviders/NMSheetMainDataSource.cs +++ b/src/client/spark/NMSheets/DataProviders/NMSheetMainDataSource.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; - +using mbts; using BCG.Utilities; using BCG.Utilities.General; diff --git a/src/client/spark/NMSheets/Outside/ColorRetriever.cs b/src/client/spark/NMSheets/Outside/ColorRetriever.cs index 09ce67f1e..f4d5b3d81 100644 --- a/src/client/spark/NMSheets/Outside/ColorRetriever.cs +++ b/src/client/spark/NMSheets/Outside/ColorRetriever.cs @@ -5,7 +5,7 @@ using System.Windows; using System.Windows.Controls; using System.Collections.Generic; using System.Windows.Media; - +using mbts; using mbts.ui; using mbts.spark; @@ -34,7 +34,7 @@ namespace BCG public static System.Drawing.Color convert_color(BTSColor o_color) { - return (System.Drawing.Color) o_color; + return (System.Drawing.Color)o_color; } public static Color clone_color(Color color) diff --git a/src/client/spark/NMSheets/Outside/ExchangeSecurityMap.cs b/src/client/spark/NMSheets/Outside/ExchangeSecurityMap.cs index 2302fa49a..2237c671d 100644 --- a/src/client/spark/NMSheets/Outside/ExchangeSecurityMap.cs +++ b/src/client/spark/NMSheets/Outside/ExchangeSecurityMap.cs @@ -5,10 +5,11 @@ using System.Text; using System.Threading.Tasks; using mbts.ui; using bts.api; - +using mbts; using mbts.spark; -namespace BCG { +namespace BCG +{ /// /// This is the list of all exchange listed securities /// in the system. It provides : @@ -17,7 +18,8 @@ namespace BCG { /// // TODO: SystemSecurityData will replace this (for backwards Tc2 bckwards compat // it is created from SystemContractData) - public class ExchangeSecurityMap/* : mbts.bb.IExchangeSecurityMap */{ + public class ExchangeSecurityMap/* : mbts.bb.IExchangeSecurityMap */ + { public const uint error_key = 0; private readonly IDictionary _key_sec_map; private readonly IDictionary _option_map; @@ -25,17 +27,22 @@ namespace BCG { private readonly IDictionary> _spread_map; - public ExchangeSecurityMap(SystemContractData sc_data) { - Func get_sec = (id) => { + public ExchangeSecurityMap(SystemContractData sc_data) + { + Func get_sec = (id) => + { return sc_data.sec_md_map[id].security.CloneToMutable(); }; var key_sec_map_aux = new Dictionary(); - foreach (var kv in sc_data.sec_md_map) { + foreach (var kv in sc_data.sec_md_map) + { key_sec_map_aux[kv.Key] = kv.Value.security.CloneToMutable(); } var option_map_aux = new Dictionary(); - foreach (var o_kv in sc_data.strike_map) { - foreach (var k in o_kv.Value) { + foreach (var o_kv in sc_data.strike_map) + { + foreach (var k in o_kv.Value) + { var (call_id, put_id) = k.call_put_id; if (call_id.HasValue && put_id.HasValue) option_map_aux[k] = new[] { get_sec(call_id.Value), get_sec(put_id.Value) }; @@ -52,7 +59,8 @@ namespace BCG { public ExchangeSecurityMap(IDictionary key_sec_map, IDictionary option_map, IDictionary fut_map, - IDictionary> spread_map) { + IDictionary> spread_map) + { _key_sec_map = key_sec_map; _option_map = option_map; _fut_map = fut_map; @@ -61,19 +69,22 @@ namespace BCG { #region IExchangeSecurityMap public Security get_option_security(Venue exchange, string symbol, DateTime exp, - double strike, PutOrCall cp) { + double strike, PutOrCall cp) + { mbts.SecurityStrike k = new mbts.SecurityStrike(new mbts.SecurityExpiration(exchange, SecurityType.Option, symbol, exp), strike); Security[] rv = _option_map.TryGetValue(k, out rv) ? rv : null; return rv != null ? rv[cp == PutOrCall.Call ? 0 : 1] : null; } - public Security get_future_security(Venue exchange, string symbol, DateTime exp) { + public Security get_future_security(Venue exchange, string symbol, DateTime exp) + { mbts.SecurityExpiration sec_exp = new mbts.SecurityExpiration(exchange, SecurityType.Future, symbol, exp); Security rv = _fut_map.TryGetValue(sec_exp, out rv) ? rv : null; return rv; } - public Security get_spread_security(Venue exchange, string spread_def) { + public Security get_spread_security(Venue exchange, string spread_def) + { IDictionary exch_spread_map; Security rv = null; if (_spread_map.TryGetValue(exchange, out exch_spread_map)) @@ -88,7 +99,8 @@ namespace BCG { public IEnumerable> get_spots() { return new List>(); } - public Security get_o2_security(uint sec_key) { + public Security get_o2_security(uint sec_key) + { Security rv = _key_sec_map.TryGetValue(sec_key, out rv) ? rv : null; return rv; } @@ -97,10 +109,12 @@ namespace BCG { /// Given an ExpStrikeKeyedData it attaches /// the call and put security keys - public ExpStrikeKeyedData> attach_sec_keys(ExpStrikeKeyedData data, string option_name, Venue exchange) { + public ExpStrikeKeyedData> attach_sec_keys(ExpStrikeKeyedData data, string option_name, Venue exchange) + { ExpStrikeKeyedData> rv = new ExpStrikeKeyedData>(); uint[] uninit_keys = new uint[] { 0, 0 }; - foreach (Triplet t in data.get_data_linearly()) { + foreach (Triplet t in data.get_data_linearly()) + { mbts.SecurityStrike k = new mbts.SecurityStrike(new mbts.SecurityExpiration(exchange, SecurityType.Option, option_name, t.first), t.second); Security[] cp_keys = _option_map.TryGetValue(k, out cp_keys) ? cp_keys : null; uint c_key = cp_keys != null && cp_keys[0] != null ? cp_keys[0].Id : 0, @@ -114,7 +128,8 @@ namespace BCG { // return new DateTime((int)t.ExpirationYear, (int)t.ExpirationMonth, (int)t.ExpirationDay); // } - public Security fill_partial_security(Security s) { + public Security fill_partial_security(Security s) + { if (s.security_type() == SecurityType.Option && s.Option != null) return get_option_security(s.Exchange, s.Symbol, new DateTime((int)s.Option.ExpirationYear, (int)s.Option.ExpirationMonth, (int)s.Option.ExpirationDay), s.Option.Strike, s.Option.CallPut); else if (s.security_type() == SecurityType.Future && s.Future != null) @@ -124,9 +139,11 @@ namespace BCG { return null; } - public IEnumerable get_matching_option_securities(string symbol, Venue exchange) { + public IEnumerable get_matching_option_securities(string symbol, Venue exchange) + { List rv = new List(); - foreach (var v in _option_map.Where(kv => String.Compare(kv.Key.expiration.symbol, symbol, true) == 0).Select(kv => kv.Value)) { + foreach (var v in _option_map.Where(kv => String.Compare(kv.Key.expiration.symbol, symbol, true) == 0).Select(kv => kv.Value)) + { rv.Add(v[0]); rv.Add(v[1]); } diff --git a/src/client/spark/NMSheets/Outside/OptionContractKeyedData.cs b/src/client/spark/NMSheets/Outside/OptionContractKeyedData.cs index acd383841..80533143a 100644 --- a/src/client/spark/NMSheets/Outside/OptionContractKeyedData.cs +++ b/src/client/spark/NMSheets/Outside/OptionContractKeyedData.cs @@ -2,41 +2,49 @@ using System; using System.Collections.Generic; using System.Text; - +using mbts; using mbts.spark; -namespace BCG { - public class CallPutValue { +namespace BCG +{ + public class CallPutValue + { public T call_value; public T put_value; - public void set_value(bool is_call, T t) { + public void set_value(bool is_call, T t) + { if (is_call) call_value = t; else put_value = t; } public T get_value(bool is_call) { return is_call ? call_value : put_value; } - public bool value_exists(bool is_call) { + public bool value_exists(bool is_call) + { T v = get_value(is_call); return v != null && !v.Equals(default(T)); } public void remove_value(bool is_call) { set_value(is_call, default(T)); } - public CallPutValue shallow_copy() { + public CallPutValue shallow_copy() + { return new CallPutValue() { call_value = call_value, put_value = put_value }; } } - public class OptionContractKeyedData { + public class OptionContractKeyedData + { private Dictionary>> _map = new Dictionary>>(); public OptionContractKeyedData() { } - public IReadOnlyDictionary>> get_data() { + public IReadOnlyDictionary>> get_data() + { Dictionary>> rv = new Dictionary>>(); foreach (DateTime exp in _map.Keys) rv[exp] = get_exp_data(exp); return rv; } - public void setValue(DateTime e, double k, bool is_call, T data) { + public void setValue(DateTime e, double k, bool is_call, T data) + { Dictionary> k_map = null; if (!_map.TryGetValue(e, out k_map)) _map.Add(e, k_map = new Dictionary>()); @@ -46,7 +54,8 @@ namespace BCG { k_val.set_value(is_call, data); } - public T getValue(DateTime e, double k, bool is_call) { + public T getValue(DateTime e, double k, bool is_call) + { Dictionary> k_map = null; CallPutValue k_val = null; if (_map.TryGetValue(e, out k_map)) @@ -55,7 +64,8 @@ namespace BCG { return default(T); } - public T get_value(DateTime e, double k, bool is_call, T not_found_val) { + public T get_value(DateTime e, double k, bool is_call, T not_found_val) + { Dictionary> k_map = null; CallPutValue k_val = null; if (_map.TryGetValue(e, out k_map)) @@ -64,7 +74,8 @@ namespace BCG { return not_found_val; } - public void remove(DateTime e, double k, bool is_call) { + public void remove(DateTime e, double k, bool is_call) + { Dictionary> k_map = null; CallPutValue k_val = null; if (_map.TryGetValue(e, out k_map)) @@ -72,7 +83,8 @@ namespace BCG { k_val.remove_value(is_call); } - public bool contains(DateTime e, double k, bool is_call) { + public bool contains(DateTime e, double k, bool is_call) + { Dictionary> k_map = null; CallPutValue k_val = null; if (_map.TryGetValue(e, out k_map)) @@ -81,14 +93,17 @@ namespace BCG { return false; } - public bool contain_exp(DateTime e) { + public bool contain_exp(DateTime e) + { Dictionary> k_map; return _map.TryGetValue(e, out k_map) && k_map != null && k_map.Count > 0; } - public List>> get_linear_data() { + public List>> get_linear_data() + { List>> rv = new List>>(); - foreach (KeyValuePair>> kv1 in _map) { + foreach (KeyValuePair>> kv1 in _map) + { DateTime e = kv1.Key; foreach (KeyValuePair> kv2 in kv1.Value) rv.Add(new Triplet>(e, kv2.Key, kv2.Value)); @@ -96,14 +111,17 @@ namespace BCG { return rv; } - public IReadOnlyDictionary> get_exp_data(DateTime exp) { + public IReadOnlyDictionary> get_exp_data(DateTime exp) + { Dictionary> exp_map = null; return _map.TryGetValue(exp, out exp_map) ? exp_map : new Dictionary>(); } - public OptionContractKeyedData shallow_copy() { + public OptionContractKeyedData shallow_copy() + { Dictionary>> rv = new Dictionary>>(); - foreach (KeyValuePair>> kv1 in _map) { + foreach (KeyValuePair>> kv1 in _map) + { Dictionary> k_map = new Dictionary>(); foreach (KeyValuePair> kv2 in kv1.Value) k_map.Add(kv2.Key, kv2.Value.shallow_copy()); @@ -112,15 +130,18 @@ namespace BCG { return new OptionContractKeyedData() { _map = rv }; } - public void mutate_data(Action mutate_func) { + public void mutate_data(Action mutate_func) + { foreach (Dictionary> k_map in _map.Values) - foreach (CallPutValue kp_val in k_map.Values) { + foreach (CallPutValue kp_val in k_map.Values) + { mutate_func(kp_val.call_value); mutate_func(kp_val.put_value); } } - public IDictionary> get_contracts() { + public IDictionary> get_contracts() + { Dictionary> rv = new Dictionary>(); foreach (KeyValuePair>> k in _map) rv.Add(k.Key, k.Value.Keys); diff --git a/src/client/spark/NMSheets/Outside/tc2/Calculator2/MainForm/ATM/ATMData.cs b/src/client/spark/NMSheets/Outside/tc2/Calculator2/MainForm/ATM/ATMData.cs index 546de21e3..23fd61d81 100644 --- a/src/client/spark/NMSheets/Outside/tc2/Calculator2/MainForm/ATM/ATMData.cs +++ b/src/client/spark/NMSheets/Outside/tc2/Calculator2/MainForm/ATM/ATMData.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; - +using mbts; using mbts.spark; namespace BCG { diff --git a/src/client/spark/NMSheets/Outside/tc2/Calculator2/MainForm/ATM/OptionATMDataSource.cs b/src/client/spark/NMSheets/Outside/tc2/Calculator2/MainForm/ATM/OptionATMDataSource.cs index c246face9..c05997398 100644 --- a/src/client/spark/NMSheets/Outside/tc2/Calculator2/MainForm/ATM/OptionATMDataSource.cs +++ b/src/client/spark/NMSheets/Outside/tc2/Calculator2/MainForm/ATM/OptionATMDataSource.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using mbts.ui; - +using mbts; using BCG.Utilities; using mbts.spark; diff --git a/src/client/spark/NMSheets/UIComponents/ExpirationHeaderDriverControl/NMSheetDriverControlStrip.cs b/src/client/spark/NMSheets/UIComponents/ExpirationHeaderDriverControl/NMSheetDriverControlStrip.cs index 0b28979a7..853219239 100644 --- a/src/client/spark/NMSheets/UIComponents/ExpirationHeaderDriverControl/NMSheetDriverControlStrip.cs +++ b/src/client/spark/NMSheets/UIComponents/ExpirationHeaderDriverControl/NMSheetDriverControlStrip.cs @@ -9,7 +9,7 @@ using BCG.Utilities; using mbts.ui.dpi; using mbts.spark; using bts.api; - +using mbts; namespace BCG { /// Control that sits on top (under the vol control strip). /// For every selected option expiration, theres a driver diff --git a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGrid.cs b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGrid.cs index f1c486aba..8e0a253ee 100644 --- a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGrid.cs +++ b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGrid.cs @@ -7,7 +7,7 @@ using System.Data; using System.Windows.Forms; using System.Drawing.Imaging; using System.Drawing.Drawing2D; - +using mbts; using BCG.Utilities; using BCG.Utilities.General; using mbts.spark; diff --git a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGridMouseHandling.cs b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGridMouseHandling.cs index b25354bfd..480b79362 100644 --- a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGridMouseHandling.cs +++ b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetTheoGridMouseHandling.cs @@ -7,7 +7,7 @@ using System.Data; using System.Windows.Forms; using System.Drawing.Imaging; using System.Drawing.Drawing2D; - +using mbts; using BCG.Utilities; using BCG.Utilities.General; using mbts.spark; diff --git a/src/client/spark/Spark.csproj b/src/client/spark/Spark.csproj index 397d2ad9e..c18698616 100644 --- a/src/client/spark/Spark.csproj +++ b/src/client/spark/Spark.csproj @@ -55,6 +55,7 @@ + diff --git a/src/client/spark/SpreadBox/Calculators/StatelessSpreadCalculator.cs b/src/client/spark/SpreadBox/Calculators/StatelessSpreadCalculator.cs index b88eaa97c..ffe456e20 100644 --- a/src/client/spark/SpreadBox/Calculators/StatelessSpreadCalculator.cs +++ b/src/client/spark/SpreadBox/Calculators/StatelessSpreadCalculator.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; - +using mbts; using mbts.ui; using mbts.spark; using bts.api; diff --git a/src/client/spark_api/MarketData/MarketDataClient.cs b/src/client/spark_api/MarketData/MarketDataClient.cs index 9d800ec08..a539a19bd 100644 --- a/src/client/spark_api/MarketData/MarketDataClient.cs +++ b/src/client/spark_api/MarketData/MarketDataClient.cs @@ -101,7 +101,7 @@ namespace bts.md { } public IObservable> trades(TradesSubscriptionFilter filter) { - var sec_mds = filter.security_criteria is null ? + var sec_mds = filter.security_criteria == null ? _source.subscribe_securities() : filter.security_criteria.subscribe_md_map(_source.subscribe_securities()); return TradesSource.create(_source.consumer, sec_mds, _poll_interval);