From 2740de913c6598707dcca4e4f18d97ebfef3eb6e Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Fri, 29 Nov 2019 09:47:46 -0500 Subject: [PATCH] BookState is now called BookSeries --- .../{DayBookState.cs => BookSeries.cs} | 22 +++++++++---------- .../StaticAnalysis/MarketQueries.cs | 19 ++++++++++------ .../StaticAnalysis/MarketQueriesHelper.cs | 4 ++-- .../SpreaderTickSniperAnalyzer.cs | 10 ++++----- 4 files changed, 29 insertions(+), 26 deletions(-) rename src/client/sparkcmd/Cmd/Historical/StaticAnalysis/{DayBookState.cs => BookSeries.cs} (87%) diff --git a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/DayBookState.cs b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/BookSeries.cs similarity index 87% rename from src/client/sparkcmd/Cmd/Historical/StaticAnalysis/DayBookState.cs rename to src/client/sparkcmd/Cmd/Historical/StaticAnalysis/BookSeries.cs index b7de64ce1..f9c4dc00d 100644 --- a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/DayBookState.cs +++ b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/BookSeries.cs @@ -6,9 +6,9 @@ using System.IO; namespace bts.history{ // all book states for a security, for the duration of a day - class BookState{ + class BookSeries{ private readonly List _books = new List(); - public BookState(string file_path){ + public BookSeries(string file_path){ var pbooks = new List(); FileStream fs = new FileStream (file_path, FileMode.Open); while (fs.Position < fs.Length){ @@ -28,7 +28,7 @@ namespace bts.history{ public int count(){ return _books.Count; } - // returns all books values that exist in the timerange t + // returns all book enties that exist in the timerange t // (note, these are not necassarily the updates in t // but the possible book values that existed in timerange t) public IEnumerable find_books_in_time_range (Timerange t){ @@ -52,15 +52,15 @@ namespace bts.history{ // given a book, finds all co-existing books // in another book // source_book_ptr -> {t1,t2} -> books in {t1,t2} - public IEnumerable find_coexisting_books ( + public static IEnumerable find_coexisting_books ( BookEntry book, - BookState b2_s){ + BookSeries b2_s){ return b2_s.find_books_in_time_range(book.time_range); } public IEnumerable> find_coexisting_books ( BookEntry book, - BookState b2_s, - BookState b3_s){ + BookSeries b2_s, + BookSeries b3_s){ var rv = new List>(); var b2_coex = b2_s.find_books_in_time_range(book.time_range); foreach (BookEntry b2_e in b2_coex){ @@ -72,7 +72,7 @@ namespace bts.history{ } return rv; } - public void align_books_2(BookState bs_2, + public void align_books_2(BookSeries bs_2, Action on_book){ foreach (var b in _books){ var bs_2_coex = find_coexisting_books(b,bs_2); @@ -80,8 +80,8 @@ namespace bts.history{ on_book(b,bs2_e); } } - public void align_books_3(BookState bs_2, - BookState bs_3, + public void align_books_3(BookSeries bs_2, + BookSeries bs_3, Action on_book){ foreach (var b in _books) foreach (var t in find_coexisting_books(b,bs_2,bs_3)) @@ -90,7 +90,7 @@ namespace bts.history{ #region static helpers public static Timestamp timestamp (ProcessedBook b){ return b!=null?b.SendingTime:Timerange.max_timestamp(); - } + } #endregion } } \ No newline at end of file diff --git a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/MarketQueries.cs b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/MarketQueries.cs index 4e72793ff..e82597407 100644 --- a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/MarketQueries.cs +++ b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/MarketQueries.cs @@ -8,11 +8,11 @@ using bts.co2; namespace bts.history{ class MarketQueries{ + // works only for glbx static IEnumerable get_synthetic_prices( - string synthetic_text, + SpreaderOrderDefinition synth, DateTime date){ - var synth = MarketQueriesHelper.parse_synthetic(synthetic_text); - IEnumerable book_states = + IEnumerable book_states = synth.Security.Synthetic.Legs.Select( l => MarketQueriesHelper.get_book_state(l.Security.Symbol, l.Security.Glbx.SecurityDesc, @@ -34,10 +34,15 @@ namespace bts.history{ params BookEntry[] leg_books){ bts.co2.BookMessage rv = new bts.co2.BookMessage(); return rv; - } - static BookState get_book_state (string sec_txt,DateTime date){ - string book_path = BookAnalyzer.get_book_path(sec_txt,date); - return null; } + #region Alligning Books + + public static IEnumerable find_coexisting_books ( + BookSeries bser, + BookEntry other_be){ + return bser.find_books_in_time_range(other_be.time_range); + } + + #endregion } } \ No newline at end of file diff --git a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/MarketQueriesHelper.cs b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/MarketQueriesHelper.cs index eb9ab109d..3888faf85 100644 --- a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/MarketQueriesHelper.cs +++ b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/MarketQueriesHelper.cs @@ -55,11 +55,11 @@ namespace bts.history{ } return rv; } - public static BookState get_book_state (string symbol, + public static BookSeries get_book_state (string symbol, string sec_txt, DateTime date){ string book_path = BookAnalyzer.get_book_path(symbol, sec_txt,date); - return new BookState(book_path); + return new BookSeries(book_path); } public static string get_algo_input_path (string algo_name){ return String.Format(@"{0}{1}/{2}/{3}/", diff --git a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/SpreaderTickSniperAnalyzer.cs b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/SpreaderTickSniperAnalyzer.cs index b3b2a3839..0abd34c3c 100644 --- a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/SpreaderTickSniperAnalyzer.cs +++ b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/SpreaderTickSniperAnalyzer.cs @@ -23,14 +23,12 @@ namespace bts.history{ string output_file = sr.ReadLine (); IDictionary spread_map = new Dictionary(); - while (true){ + string spread_txt = sr.ReadLine(); + while (!spread_txt.is_null_or_empty()){ // read spreads - string spread_txt = sr.ReadLine(); - if(spread_txt.is_null_or_empty()) - break; - SpreaderOrderDefinition spreader_ord = + spread_map[spread_txt] = MarketQueriesHelper.parse_synthetic(spread_txt); - spread_map[spread_txt] = spreader_ord; + spread_txt = sr.ReadLine(); } }