This commit is contained in:
Taha Afzal committed 2019-11-29 15:34:44 -05:00
commit 0535eedbbf
17 files changed
+273 -262

No files matched your search

+8 -94
View File
@@ -46,7 +46,7 @@
"sourceFileMap": {
"/home/bts/spark/": "${workspaceRoot}"
}
},
},
{
"name": "(gdb) Launch",
"type": "cppdbg",
@@ -98,30 +98,6 @@
"externalConsole": true,
"requireExactSource": false
},
{
"name": "sparkcmd Launch",
"type": "clr",
"request": "launch",
"program": "${workspaceRoot}/build/Debug/bin/net471/sparkcmd.exe",
"args": [
"historical",
"--algo_type", "sniper",
"--algo_params", "test.txt",
"--post_process_db_ip", "127.0.0.1",
"--rskip", "11/20/2019 10:00AM",
"--rstart", "11/20/2019 02:00PM",
"--rend", "11/20/2019 11:00PM",
"--rsymbol", "CL",
"--rsecuritytype", "Spread",
"--algo_security", "CLZ9-CLF0;CLF0-CLG0;CLZ9-CLG0",
"--algo_type", "RoundTrip",
"--algo_params", "size=1;profit_ticks=1;tick_size=1,1,1;;hedge_factors=1,1,-1",
],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"externalConsole": true,
"requireExactSource": false
},
{
"name": "Excel Launch",
"type": "clr",
@@ -366,22 +342,15 @@
"justMyCode": true
},
{
"name": "sparkcmd vsdbg (c#)",
"name": ".NET Core Remote Launch",
"type": "coreclr",
"request": "launch",
"program": "sparkcmd",
"program": "/usr/bin/dotnet",
"args": [
"historical",
"--rstart", "10/21/2019",
"--rend", "10/21/2019",
"--rsymbol", "CL",
"--rsecuritytype", "Future",
"--algo_security", "CLX9",
"--algo_type", "TWAP",
"--algo_params", "size=100;profit_ticks=1;tick_size=1,1,1;hedge_factors=1,1,-1",
"--skip_preanalysis", "true",
"sparkcmd.dll",
"test",
"test_join_create_and_takeout_market"
],
"env": {"LD_LIBRARY_PATH" : "."},
"stopAtEntry": false,
"cwd": "/home/bts/spark/build/ninja_debug/server",
"pipeTransport": {
@@ -392,66 +361,11 @@
"debuggerPath": "/home/bts/vsdbg/vsdbg",
"pipeCwd": "${workspaceRoot}",
"quoteArgs": true
},
},
"sourceFileMap": {
"/home/bts/spark/": "${workspaceRoot}"
},
"justMyCode": false
},
{
"name": "sparkcmd gdb (c++)",
"type": "cppdbg",
"request": "launch",
"program": "/home/bts/spark/build/ninja_debug/server/sparkcmd",
"args": [
"historical",
"--rstart", "10/21/2019",
"--rend", "10/21/2019",
"--rsymbol", "CL",
"--rsecuritytype", "Future",
"--algo_security", "CLX9",
"--algo_type", "TWAP",
"--algo_params", "'size=100;profit_ticks=1;tick_size=1,1,1;;hedge_factors=1,1,-1'",
"--skip_preanalysis", "true",
],
"stopAtEntry": false,
"cwd": "/home/bts/spark/build/ninja_debug/server/",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "",
"logging": {
"engineLogging": false
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "enable pretty-printer",
"ignoreFailures": true
},
{
"description": "Skip STL",
"text": "skip -gfi /usr/include/c++/7/bits/*.h",
"ignoreFailures": true
},
{
"description": "LD LIBRARY",
"text": "set env LD_LIBRARY_PATH=.",
"ignoreFailures": false
}
],
"pipeTransport": {
"pipeCwd": "${workspaceRoot}",
"pipeProgram": "c:\\program files\\git\\usr\\bin\\ssh.exe",
"pipeArgs": [
"bts@sparkvm"
],
"debuggerPath": "/usr/bin/gdb"
},
"sourceFileMap": {
"/home/bts/spark/": "${workspaceRoot}"
}
},
},
]
}
+1 -1
View File
@@ -117,7 +117,7 @@
<Message Importance="High" Text="Generating service %(Proto3.FileName)" />
<Exec Command="
$(protoc) \
PYTHONPATH=$(Externals)/python $(protoc) \
%(Proto3.FullPath) \
--error_format=gcc \
--proto_path=$(protoinc):$(SourceRoot) \
@@ -29,7 +29,9 @@ namespace bts.history
public BookAnalyzer(string symbol,
HistoricalDataOptions options) {
_book_path = get_book_path(symbol, DateTime.Parse(options.replaystart));
_book_path = MarketQueriesHelper.get_book_path(
symbol,
DateTime.Parse(options.replaystart));
System.IO.Directory.CreateDirectory(_book_path);
}
@@ -52,30 +54,12 @@ namespace bts.history
_books[entry.Symbol] = book;
}
OrderBook.keep_book(book, entry);
on_new_book(book, entry, md);
if (OrderBook.quote_event_done(md))
on_new_book(book, entry, md);
}
// else if (entry.MdEntryType == MDEntryType.Trade)
// handle trades here
}
}
public static string get_book_path (string symbol,
DateTime date){
return String.Format(@"{0}{1}/{2}/{3}/{4}/{5}/",
Configuration.get<bts.config.System>().data_path,
"trade_analysis",
"market_data",
date.ToShortDateString().Replace("/","_"),
"books",
symbol);
}
public static string get_book_path (string symbol,
string sec_name,
DateTime date){
return String.Format(@"{0}{1}",
get_book_path(symbol, date),
sec_name);
}
private void on_new_book(co2.BookMessage book,
@@ -337,13 +337,20 @@ namespace bts.history
public bool cancel_my_order(ulong my_order_id)
{
return remove_my_order(my_order_id);
}
}
//https://www.cmegroup.com/confluence/display/EPICSANDBOX/MDP+3.0+-+Market+Data+Incremental+Refresh
//yes, but they make it a big-endian string
public static bool quote_event_done(MarketDataIncrementalRefresh md)
{
return md.MatchEventIndicator[0] == '1' || md.MatchEventIndicator[5] == '1';
}
public static bool implied_quote_event_done(MarketDataIncrementalRefresh md)
{
return md.MatchEventIndicator[0] == '1' || md.MatchEventIndicator[3] == '1';
}
public void process_md(MarketDataIncrementalRefresh md, Func<MDEntry, OrderIDEntry, bool> filter, string debug_fix = null)
{
bool bidoffer = false, trade = false;
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using bts.api;
using bts.co2;
@@ -10,31 +13,42 @@ namespace bts.history
class HistoricalDatabaseGenerator : IDisposable
{
readonly HistoricalDataStreamer _stream;
MarketDataIncrementalRefresh _last = new MarketDataIncrementalRefresh() { SendingTime = new Timestamp(), TransactTime = new Timestamp() };
readonly string _post_process_db;
readonly string _post_process_db_ip;
Npgsql.NpgsqlConnection _sql;
readonly string _post_process_db_host;
readonly Dictionary<string, co2.BookMessage> _books = new Dictionary<string, co2.BookMessage>();
readonly ConcurrentQueue<Npgsql.NpgsqlCommand> _operations = new ConcurrentQueue<Npgsql.NpgsqlCommand>();
public HistoricalDatabaseGenerator(string post_process_db, string post_process_db_ip)
Npgsql.NpgsqlConnection _sql;
readonly CancellationTokenSource _cts = new CancellationTokenSource();
Task _qtask;
public HistoricalDatabaseGenerator(string post_process_db, string post_process_db_host)
{
_post_process_db = post_process_db;
_post_process_db_ip = post_process_db_ip;
_post_process_db_host = post_process_db_host;
_stream = new HistoricalDataStreamer();
var conn = $@"Server={_post_process_db_ip};Port=5432; User Id=postgres;Password=enter;";
var conn = $@"Server={_post_process_db_host};Port=5432; User Id=postgres;Password=enter;";
_sql = new Npgsql.NpgsqlConnection(conn);
var create = new Npgsql.NpgsqlCommand(
$@"create database if not exists {_post_process_db}
$@"CREATE DATABASE {_post_process_db}
with owner = postgres
encoding = 'UTF8'
connection limit = -1;
", _sql);
_sql.Open();
create.ExecuteNonQuery();
_sql.Close(); //TODO google says I have to do this
try
{
create.ExecuteNonQuery();
}
catch(Exception ex)
{
if(!ex.Message.Contains("already exists"))
throw ex;
}
//TODO google says I have to do this
_sql.Close();
_sql = null;
}
readonly Dictionary<string, co2.BookMessage> _books = new Dictionary<string, co2.BookMessage>();
async public Task generate(DateTime start, DateTime end, string symbol, SecurityType st,
HistoricalDataOptions o)
@@ -54,10 +68,19 @@ namespace bts.history
if (DateTime.TryParse(o.replayskip, out DateTime skip) && skip != DateTime.MinValue)
query.Skip = Timestamp.FromDateTime(skip.ToUniversalTime());
int count = 0;
var comparer = Comparer<MarketDataIncrementalRefresh>.Create((x, y)
=> x.timestamp().ToDateTime().CompareTo(y.timestamp().ToDateTime()));
#pragma warning disable CS4014
start_transaction_queue().ContinueWith( t => { throw t.Exception; }, TaskContinuationOptions.OnlyOnFaulted );
await _stream.process_md_stream<MarketDataIncrementalRefresh>(query, (sectype, md, line) =>
{
if(++count % 10000 == 1)
Console.WriteLine($"preprocessed {count} lines, {_operations.Count} write queue length");
if(md.timestamp().ToDateTime() > end)
throw new System.IO.EndOfStreamException();
foreach (var entry in md.MdEntries)
{
if (entry.MdEntryType == MDEntryType.Bid || entry.MdEntryType == MDEntryType.Offer)
@@ -69,7 +92,8 @@ namespace bts.history
_books[entry.security_desc()] = book;
}
OrderBook.keep_book(book, entry);
write_book(tname, book, entry, md);
if(OrderBook.quote_event_done(md))
write_book_with_prepare(tname, book, entry, md);
}
else if (entry.MdEntryType == MDEntryType.Trade)
{
@@ -80,44 +104,106 @@ namespace bts.history
}, comparer);
}
private string maybe_create_table(DateTime start, DateTime end, string symbol, SecurityType st, HistoricalDataOptions o)
string maybe_create_table(DateTime start, DateTime end, string symbol, SecurityType st, HistoricalDataOptions o)
{
var conn = $@"Server={_post_process_db_ip};Port=5432; User Id=postgres;Password=enter;Database={_post_process_db}";
var conn = $@"Server={_post_process_db_host};Port=5432; User Id=postgres;Password=enter;Database={_post_process_db}";
_sql = new Npgsql.NpgsqlConnection(conn);
var name = $"{symbol}_history";
var tname = $"{symbol}_{st.ToString()}_history";
var cmd = new Npgsql.NpgsqlCommand(
$@"CREATE TABLE IF NOT EXISTS {name} (id serial NOT NULL PRIMARY KEY,
$@"CREATE TABLE IF NOT EXISTS {tname} (id serial NOT NULL PRIMARY KEY,
seqnum INTEGER NOT NULL CHECK(seqnum > 0), transact_time TIMESTAMPTZ NOT NULL, sending_time TIMESTAMPTZ NOT NULL,
security_desc TEXT NOT NULL, data_type TEXT NOT NULL, data jsonb NOT NULL)",
_sql);
_sql.Open();
cmd.ExecuteNonQuery();
return name;
prepare_book_insert(tname);
return tname;
}
private void write_trade(string tname, TradeMessage tm, MDEntry entry, MarketDataIncrementalRefresh md)
void prepare_book_insert(string tname)
{
var prep = new Npgsql.NpgsqlCommand(
$@"PREPARE bookplan (integer, timestamptz, timestamptz, text, text, jsonb) AS
INSERT INTO {tname} (seqnum, transact_time, sending_time, security_desc, data_type, data )
VALUES($1, $2, $3, $4, $5, $6) ", _sql);
try
{
prep.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
}
async Task start_transaction_queue()
{
_qtask = Task.Run( async () =>
{
while(true)
{
await Task.Delay(500);
if (_cts.IsCancellationRequested)
throw new TaskCanceledException(_qtask);
if(_operations.Count == 0)
continue;
var trans = _sql.BeginTransaction();
try
{
while(_operations.TryDequeue(out Npgsql.NpgsqlCommand cmd))
{
try
{
cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
throw ex;
}
}
}
finally
{
trans.Commit();
}
}
}, _cts.Token);
await _qtask;
}
void write_trade(string tname, TradeMessage tm, MDEntry entry, MarketDataIncrementalRefresh md)
{
var json = Google.Protobuf.JsonFormatter.Default.Format(tm);
var cmd = new Npgsql.NpgsqlCommand(
$@"INSERT INTO {tname} (transact_time, sending_time, symbol, security_type, security_desc, data_type, data )
VALUES ({md.MsgSeqNum}, {md.TransactTime.ToString()}, {md.SendingTime.ToString()},
{entry.security_desc()}, {nameof(TradeMessage)}, { json } )
", _sql);
cmd.ExecuteNonQuery();
var cmd = new Npgsql.NpgsqlCommand(
$@"INSERT INTO {tname} (seqnum, transact_time, sending_time, security_desc, data_type, data )
VALUES ({md.MsgSeqNum}, '{md.TransactTime.ToString().Replace('T', ' ').Replace("Z", "+00")}',
'{md.SendingTime.ToString().Replace('T', ' ').Replace("Z", "+00")}', '{entry.security_desc()}',
'{nameof(TradeMessage)}', '{ json }' )",
_sql);
_operations.Enqueue(cmd);
}
private void write_book(string tname, BookMessage book, MDEntry entry, MarketDataIncrementalRefresh md)
void write_book_with_prepare(string tname, BookMessage book, MDEntry entry, MarketDataIncrementalRefresh md)
{
if (!book.Bids.Any(x => x.Size > 0) && !book.Asks.Any(x => x.Size > 0))
return;
var json = Google.Protobuf.JsonFormatter.Default.Format(book);
var cmd = new Npgsql.NpgsqlCommand(
$@"INSERT INTO {tname} (transact_time, sending_time, symbol, security_type, security_desc, data_type, data )
VALUES ({md.MsgSeqNum}, {md.TransactTime.ToString()}, {md.SendingTime.ToString()},
{entry.security_desc()}, {nameof(BookMessage)}, { json } )
", _sql);
}
public void Dispose()
$@"EXECUTE bookplan ({md.MsgSeqNum}, '{md.TransactTime.ToString().Replace('T', ' ').Replace("Z", "+00")}',
'{md.SendingTime.ToString().Replace('T', ' ').Replace("Z", "+00")}', '{entry.security_desc()}',
'{nameof(BookMessage)}', '{ json }' ) ",
_sql);
_operations.Enqueue(cmd);
}
public async void Dispose()
{
_cts.Cancel();
await _qtask;
if(_sql != null)
_sql.Close();
}
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using bts.co2;
namespace bts.history{
class BookEntry{
@@ -12,6 +13,17 @@ namespace bts.history{
Timerange time_range_a){
_pbook = pbook_a;
time_range = time_range_a;
// temp
foreach (var b in pbook_a.Book.Bids)
b.Exponent = -2;
foreach (var a in pbook_a.Book.Asks)
a.Exponent = -2;
}
public double price (bool is_bid, UInt16 level){
var vals = is_bid ? _pbook.Book.Bids : _pbook.Book.Asks;
var i = vals[level];
var iprice = new mbts.co2.IntPrice(i.Mantissa, Convert.ToSByte(i.Exponent));
return iprice.price();
}
}
}
@@ -10,18 +10,19 @@ namespace bts.history{
private readonly List<BookEntry> _books = new List<BookEntry>();
public BookSeries(string file_path){
var pbooks = new List<ProcessedBook>();
FileStream fs = new FileStream (file_path, FileMode.Open);
while (fs.Position < fs.Length){
ProcessedBook pb = new ProcessedBook();
Google.Protobuf.MessageExtensions.MergeDelimitedFrom(pb,fs);
pbooks.Add(pb);
}
for (int i=0; i<pbooks.Count(); i++){
ProcessedBook pb_i = pbooks.ElementAt(i),
pb_i_next = i+1 >= pbooks.Count() ? null :
pbooks.ElementAt(i+1);
Timerange r = new Timerange(timestamp(pb_i),timestamp(pb_i_next));
_books.Add(new BookEntry(pb_i,r));
using (FileStream fs = new FileStream (file_path, FileMode.Open)){
while (fs.Position < fs.Length){
ProcessedBook pb = new ProcessedBook();
Google.Protobuf.MessageExtensions.MergeDelimitedFrom(pb,fs);
pbooks.Add(pb);
}
for (int i=0; i<pbooks.Count(); i++){
ProcessedBook pb_i = pbooks.ElementAt(i),
pb_i_next = i+1 >= pbooks.Count() ? null :
pbooks.ElementAt(i+1);
Timerange r = new Timerange(timestamp(pb_i),timestamp(pb_i_next));
_books.Add(new BookEntry(pb_i,r));
}
}
}
@@ -49,44 +50,9 @@ namespace bts.history{
}
return rv;
}
// given a book, finds all co-existing books
// in another book
// source_book_ptr -> {t1,t2} -> books in {t1,t2}
public static IEnumerable<BookEntry> find_coexisting_books (
BookEntry book,
BookSeries b2_s){
return b2_s.find_books_in_time_range(book.time_range);
}
public IEnumerable<Tuple<BookEntry,BookEntry>> find_coexisting_books (
BookEntry book,
BookSeries b2_s,
BookSeries b3_s){
var rv = new List<Tuple<BookEntry,BookEntry>>();
var b2_coex = b2_s.find_books_in_time_range(book.time_range);
foreach (BookEntry b2_e in b2_coex){
Timerange b1_b2_tr = Timerange.intersection(book.time_range,
b2_e.time_range);
var b3_coex = b3_s.find_books_in_time_range(b1_b2_tr);
foreach (var b3_e in b3_coex)
rv.Add(Tuple.Create(b2_e, b3_e));
}
return rv;
}
public void align_books_2(BookSeries bs_2,
Action<BookEntry, BookEntry> on_book){
foreach (var b in _books){
var bs_2_coex = find_coexisting_books(b,bs_2);
foreach(var bs2_e in bs_2_coex)
on_book(b,bs2_e);
}
}
public void align_books_3(BookSeries bs_2,
BookSeries bs_3,
Action<BookEntry, BookEntry, BookEntry> on_book){
foreach (var b in _books)
foreach (var t in find_coexisting_books(b,bs_2,bs_3))
on_book(b,t.Item1,t.Item2);
}
public IReadOnlyCollection<BookEntry> book_entries(){
return _books;
}
#region static helpers
public static Timestamp timestamp (ProcessedBook b){
return b!=null?b.SendingTime:Timerange.max_timestamp();
@@ -9,29 +9,37 @@ using bts.co2;
namespace bts.history{
class MarketQueries{
// works only for glbx
static IEnumerable<BookMessage> get_synthetic_prices(
public static IEnumerable<BookMessage> get_synthetic_prices(
SpreaderOrderDefinition synth,
DateTime date){
IEnumerable<BookSeries> book_states =
synth.Security.Synthetic.Legs.Select(
l => MarketQueriesHelper.get_book_state(l.Security.Symbol,
l.Security.Glbx.SecurityDesc,
date));
List<BookSeries> leg_book_series = new List<BookSeries>();
foreach (ContractLeg l in synth.Security.Synthetic.Legs){
BookSeries bser =
MarketQueriesHelper.get_book_state(l.Security.Symbol,
l.Security.Glbx.SecurityDesc,
date);
leg_book_series.Add(bser);
}
// assert >= 2 and <= 3
UInt64 synth_book_count = 0;
var synth_books = new List<BookMessage>();
book_states.ElementAt(0).align_books_3(
book_states.ElementAt(1),
book_states.ElementAt(2),
(b1,b2,b3) => {
var b = compute_synthetic_book(synth,
b1,b2,b3);
synth_books.Add(b);
Console.WriteLine("t1:{0}",DateTime.Now);
align_3_bookseries(leg_book_series.ElementAt(0),
leg_book_series.ElementAt(1),
leg_book_series.ElementAt(2),
(b1,b2,b3) => {
synth_book_count++;
// var b = compute_synthetic_book(synth,
// b1,b2,b3);
// synth_books.Add(b);
});
Console.WriteLine("t2:{0} synth books:{1}",DateTime.Now, synth_book_count);
return synth_books;
}
// given a spread def and leg books computes the synthetic price
static BookMessage compute_synthetic_book(SpreaderOrderDefinition order_def,
params BookEntry[] leg_books){
public static BookMessage compute_synthetic_book(
SpreaderOrderDefinition order_def,
params BookEntry[] leg_books){
bts.co2.BookMessage rv = new bts.co2.BookMessage();
return rv;
}
@@ -41,7 +49,47 @@ namespace bts.history{
BookSeries bser,
BookEntry other_be){
return bser.find_books_in_time_range(other_be.time_range);
}
}
// finds all coexisting books in b1_ser and b2_ser
public static IEnumerable<Tuple<BookEntry,BookEntry>> find_coexisting_books (
BookSeries b1_ser,
BookSeries b2_ser,
Timerange tr){
var rv = new List<Tuple<BookEntry,BookEntry>>();
var b1_coex = b1_ser.find_books_in_time_range(tr);
foreach (BookEntry b1_e in b1_coex){
Timerange b1_e_strict_tr = Timerange.intersection(tr,
b1_e.time_range);
var b2_coex = b2_ser.find_books_in_time_range(b1_e_strict_tr);
foreach (var b2_e in b2_coex)
rv.Add(Tuple.Create(b1_e, b2_e));
}
return rv;
}
public static void align_2_bookseries(
BookSeries bser_1,
BookSeries bser_2,
Action<BookEntry, BookEntry> on_book){
foreach (var be_1 in bser_1.book_entries()){
var bser_2_coex = bser_2.find_books_in_time_range(be_1.time_range);
foreach(var be_2 in bser_2_coex)
on_book(be_1, be_2);
}
}
public static void align_3_bookseries(BookSeries bser_1,
BookSeries bser_2,
BookSeries bser_3,
Action<BookEntry, BookEntry, BookEntry> on_book){
int i1=0;
foreach (var be_1 in bser_1.book_entries()){
i1++;
var be_1_coex = find_coexisting_books(bser_2, bser_3, be_1.time_range);
foreach (var t in be_1_coex)
on_book(be_1, t.Item1, t.Item2);
}
}
#endregion
}
@@ -58,8 +58,8 @@ namespace bts.history{
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 BookSeries(book_path);
string fp = get_book_file(symbol,sec_txt,date);
return new BookSeries(fp);
}
public static string get_algo_input_path (string algo_name){
return String.Format(@"{0}{1}/{2}/{3}/",
@@ -68,5 +68,23 @@ namespace bts.history{
"algos",
algo_name);
}
public static string get_book_path (string symbol,
DateTime date){
return String.Format(@"{0}{1}/{2}/{3}/{4}/{5}/",
Configuration.get<bts.config.System>().data_path,
"trade_analysis",
"market_data",
date.ToShortDateString().Replace("/","_"),
"books",
symbol);
}
public static string get_book_file (string symbol,
string sec_name,
DateTime date){
return String.Format(@"{0}{1}",
get_book_path(symbol, date),
sec_name);
}
}
}
@@ -26,44 +26,15 @@ namespace bts.history{
string spread_txt = sr.ReadLine();
while (!spread_txt.is_null_or_empty()){
// read spreads
spread_map[spread_txt] =
if(!spread_txt.StartsWith("#"))
spread_map[spread_txt] =
MarketQueriesHelper.parse_synthetic(spread_txt);
spread_txt = sr.ReadLine();
}
foreach (var s in spread_map.Values)
MarketQueries.get_synthetic_prices(s,day);
}
// public void _temp_test()
// {
// System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
// sw.Start();
// List<long> time_diff = new List<long>();
// string file = @"C:\Users\taha.BLUETRADESYS\AppData\Roaming\bts\data\preprocessed_md\CL\10_29_2019\CLZ9-BZZ9";
// FileStream fs = new FileStream (file, FileMode.Open);
// while (fs.Position < fs.Length){
// try{
// ProcessedBook pb = new ProcessedBook();
// Google.Protobuf.MessageExtensions.MergeDelimitedFrom(pb,fs);
// Timerange tr = new Timerange (pb.TransactTime,pb.SendingTime);
// time_diff.Add(tr.period_ns());
// if(time_diff.Count%1000==0)
// Console.WriteLine(tr.period_ns());
// }
// catch (Exception ex){
// Console.WriteLine(ex);
// }
// }
// sw.Stop();
// time_diff.Sort();
// var median = time_diff[time_diff.Count/2];
// Console.WriteLine ("count:{0} time_ms:{1} min:{2} max:{3} mean:{4} median:{5}",
// time_diff.Count,
// sw.ElapsedMilliseconds,
// time_diff.Min(),
// time_diff.Max(),
// time_diff.Average(),
// time_diff[time_diff.Count/2]);
// }
public void analyze(){
}
}
@@ -16,7 +16,7 @@ namespace bts.history{
// Wrapper for a start/stop (with ns precision) and helper functions
class Timerange{
public readonly Timestamp t1, t2;
public static UInt64 ref_secs = Convert.ToUInt64(
private readonly static UInt64 _ref_secs = Convert.ToUInt64(
(new DateTime(DateTime.Now.Year, 1,1) -
new DateTime(1970, 1, 1)).TotalSeconds);
public Timerange(Timestamp t1_a, Timestamp t2_a){
@@ -43,7 +43,8 @@ namespace bts.history{
}
public static Timestamp max_timestamp(){
Timestamp ts = new Timestamp();
ts.Seconds = long.MaxValue;
ts.Seconds = Convert.ToInt64(
(new DateTime(2020, 12, 31) - new DateTime(1970, 1, 1)).TotalSeconds);
ts.Nanos = 0;
return ts;
}
@@ -60,7 +61,7 @@ namespace bts.history{
private static UInt64 _from_ref_ns (Timestamp ts){
UInt64 secs = Convert.ToUInt64(ts.Seconds),
ns = Convert.ToUInt64(ts.Nanos);
return (secs - ref_secs)*1000000000 + ns;
return (secs - _ref_secs)*1000000000 + ns;
}
}
}
@@ -95,8 +95,8 @@ namespace bts.history
[Option('5', "post_process_db", Required = false, Default = "", HelpText = "Name of the postgres db to generate from post processing")]
public string post_process_db { get; set; }
[Option('6', "post_process_db_ip", Required = true, Default = "127.0.0.1", HelpText = "IP of the postgres db to generate from post processing")]
public string post_process_db_ip { get; set; }
[Option('6', "post_process_db_host", Required = false, Default = "localhost", HelpText = "IP of the postgres db to generate from post processing")]
public string post_process_db_host { get; set; }
public override string ToString()
@@ -129,7 +129,7 @@ namespace bts.history
st = (SecurityType)Enum.Parse(typeof(SecurityType), o.replaysecuritytype, true);
if(!string.IsNullOrEmpty(o.post_process_db))
{
var rep = new HistoricalDatabaseGenerator(o.post_process_db, o.post_process_db_ip);
var rep = new HistoricalDatabaseGenerator(o.post_process_db, o.post_process_db_host);
rep.generate(start, end, o.replaysymbol.ToUpper(), st, o).GetAwaiter().GetResult();
}
else
@@ -145,7 +145,8 @@ message MDQuery
int32 line_skip = 60;
}
message ProcessedBook{
message ProcessedBook
{
uint32 book_seq_num = 1;
uint32 msg_seq_num = 10;
google.protobuf.Timestamp sending_time = 20;
+3
View File
@@ -0,0 +1,3 @@
#!/bin/bash
(cd /sparkdata/conf; python -m SimpleHTTPServer)
+1 -1
View File
@@ -22,7 +22,7 @@ docker run \
-e DISPLAY=$DISPLAY \
--name bts \
-d \
-t bluetradingsystems/linux_docker:postgres \
-t bluetradingsystems/linux_docker \
/bin/bash -c "(sudo /usr/sbin/sshd) & (cd ~ && $DIR/../externals/linux/bin/unison -socket 8080) & /bin/bash --login"
+1 -1
View File
@@ -1,3 +1,3 @@
#!/bin/bash
su postgres -c '/usr/lib/postgresql/10/bin/pg_ctl start -D /home/bts/sparkdata/data/pgdata/ -l serverlog'
docker run --net host -d --name pg postgres:12