BEtter formatting of output
This commit is contained in:
1 parent
d3a0595934
commit
a57b99b2e8
3 files changed
+32
-23
No files matched your search
@@ -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<T> (IEnumerable<T> 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;
|
||||
|
||||
@@ -14,13 +14,15 @@ namespace bts.history{
|
||||
|
||||
#region Synthetic Book Calc
|
||||
public class SyntheticPrice{
|
||||
public readonly IEnumerable<BookEntry> leg_book;
|
||||
public readonly IEnumerable<BookEntry> leg_books;
|
||||
public readonly BookEntry synthetic_book;
|
||||
public SyntheticPrice(IEnumerable<BookEntry> 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,
|
||||
|
||||
@@ -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;i<opps.Count;i++)
|
||||
opps[i].idx=i;
|
||||
// write to file
|
||||
string output_file = String.Format("{0}/sniper.csv",
|
||||
output_path);
|
||||
@@ -116,12 +118,14 @@ namespace bts.history{
|
||||
Console.WriteLine("SELL:{0} t:{1} active_for:{2} ns {3}:{4}",
|
||||
n, p.TimeRange.T1,
|
||||
MarketQueriesHelper.period_ns(p.TimeRange),b,bq);
|
||||
spr.viable_side = api.Side.Buy;
|
||||
return true;
|
||||
}
|
||||
if(aq>0 && 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;
|
||||
|
||||
Reference in new issue
Block a user