diff --git a/src/client/spark_historical/StaticAnalysis/DataIOHelper.cs b/src/client/spark_historical/StaticAnalysis/DataIOHelper.cs index 04c119cad..4639dc1d4 100644 --- a/src/client/spark_historical/StaticAnalysis/DataIOHelper.cs +++ b/src/client/spark_historical/StaticAnalysis/DataIOHelper.cs @@ -212,15 +212,18 @@ namespace bts.history{ #region Writing out - private static string _format_timestamp(Timestamp t){ - string tm = t.ToString().Split('T')[1]; - string[] toks = tm.Split('.'); - string time_secs = toks[0], - nsecs = toks.Length == 2 ? toks[1] : "0"; - nsecs = new string(nsecs.Where(c => char.IsDigit(c)).ToArray()); - nsecs = String.Format("{0:n0}", Int32.Parse(nsecs)); - //nsecs = nsecs.Replace(',','`'); - return String.Format("{0}{1}:{2}{3}", '"',time_secs,nsecs,'"'); + private static string _format_timestamp(Timestamp t, bool show_date = true){ + // string[] tmtoks = t.ToString().Split('T'); + // string dt = tmtoks[0]; + // string tm = tmtoks[1]; + // string[] toks = tm.Split('.'); + // string time_secs = toks[0], + // nsecs = toks.Length == 2 ? toks[1] : "0"; + // nsecs = new string(nsecs.Where(c => char.IsDigit(c)).ToArray()); + // nsecs = String.Format("{0:n0}", Int32.Parse(nsecs)); + // //nsecs = nsecs.Replace(',','`'); + // return String.Format("{0}{1}:{2}{3}", (show_date ? dt : String.Empty),time_secs,nsecs,'"'); + return t.ToString().Replace("T"," "); } private static string _array_to_string (IEnumerable entries){ @@ -266,32 +269,32 @@ namespace bts.history{ } public static string synthetic_book_header(){ - return string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}", + return string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", "Synth", + "idx", "T1", "T2", "En:Ex", "ActivePeriod", - "b_0", - "bq_0", - "a_0", - "aq_0"); + "p", + "q"); } public static string synthetic_book_entry_to_csv(MarketQueries.SyntheticPrice p){ var b = p.synthetic_book; var min_max = MarketQueriesHelper.intersection_range_idx( - p.leg_book.Select(lb=>lb.TimeRange).ToArray()); - return string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}", + p.leg_books.Select(lb=>lb.TimeRange).ToArray()); + return string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", b.PBook.Security, + p.idx, _format_timestamp(b.TimeRange.T1), _format_timestamp(b.TimeRange.T2), String.Format("{0}:{1}",min_max.Item1,min_max.Item2), MarketQueriesHelper.period_ns(b.TimeRange), - MarketQueriesHelper.book_price(b,true,0), - MarketQueriesHelper.book_qty(b,true,0), - MarketQueriesHelper.book_price(b,false,0), - MarketQueriesHelper.book_qty(b,false,0)); + p.viable_side == Side.Buy ? MarketQueriesHelper.book_price(b,true,0) : + MarketQueriesHelper.book_price(b,false,0), + p.viable_side == Side.Buy ? MarketQueriesHelper.book_qty(b,true,0) : + MarketQueriesHelper.book_qty(b,false,0)); } public static string book_entry_to_csv(BookEntry b){ @@ -310,7 +313,7 @@ namespace bts.history{ public static string synthetic_price_to_csv(MarketQueries.SyntheticPrice p){ string rv = String.Empty; - foreach (var l in p.leg_book) + foreach (var l in p.leg_books) rv += String.Format("{0},",leg_book_entry_to_csv(l)); rv += synthetic_book_entry_to_csv(p); return rv; diff --git a/src/client/spark_historical/StaticAnalysis/MarketQueries.cs b/src/client/spark_historical/StaticAnalysis/MarketQueries.cs index 406b7ae8b..17fdb88dc 100644 --- a/src/client/spark_historical/StaticAnalysis/MarketQueries.cs +++ b/src/client/spark_historical/StaticAnalysis/MarketQueries.cs @@ -14,13 +14,15 @@ namespace bts.history{ #region Synthetic Book Calc public class SyntheticPrice{ - public readonly IEnumerable leg_book; + public readonly IEnumerable leg_books; public readonly BookEntry synthetic_book; public SyntheticPrice(IEnumerable leg_book_a, BookEntry synthetic_book_a){ - leg_book = leg_book_a.ToArray(); + leg_books = leg_book_a.ToArray(); synthetic_book = synthetic_book_a; } + public api.Side viable_side = api.Side.Undefined; + public UInt16 idx = 0; } public static void get_synthetic_prices( SpreaderOrderDefinition synth, diff --git a/src/client/spark_historical/StaticAnalysis/SpreaderTickSniperAnalyzer.cs b/src/client/spark_historical/StaticAnalysis/SpreaderTickSniperAnalyzer.cs index 36a0d1b63..b92794e6d 100644 --- a/src/client/spark_historical/StaticAnalysis/SpreaderTickSniperAnalyzer.cs +++ b/src/client/spark_historical/StaticAnalysis/SpreaderTickSniperAnalyzer.cs @@ -35,6 +35,8 @@ namespace bts.history{ } opps.Sort((a,b) => a.synthetic_book.TimeRange.T1.compare( b.synthetic_book.TimeRange.T1)); + for(UInt16 i=0;i0 && a<0){ Console.WriteLine("BUY:{0} t:{1} active_for:{2} ns {3}:{4}", n, p.TimeRange.T1, MarketQueriesHelper.period_ns(p.TimeRange), a,aq); + spr.viable_side = api.Side.Sell; return true; } return false;