This commit is contained in:
Kevin Darby committed 2019-12-09 00:30:36 -05:00
1 parent 8817b22376
commit c33662dc2c
2 files changed
+630

No files matched your search

@@ -0,0 +1,310 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Invalid: Command: #r C:/Users/darby/.nuget/packages/google.protobuf/3.6.1/lib/netstandard1.0/Google.Protobuf.dllInvalid: Command: #r C:/Users/darby/.nuget/packages/newtonsoft.json/12.0.3/lib/netstandard2.0/Newtonsoft.Json.dllInvalid: Command: #r C:/Users/darby/.nuget/packages/system.linq.dynamic.core/1.0.19/lib/netstandard2.0/System.Linq.Dynamic.Core.dllInvalid: Command: #r C:/Users/darby/.nuget/packages/mongodb.driver/2.9.3/lib/netstandard1.5/MongoDB.Driver.dllInvalid: Command: #r C:/Users/darby/.nuget/packages/mongodb.driver.core/2.9.3/lib/netstandard1.5/MongoDB.Driver.Core.dllInvalid: Command: #r C:/Users/darby/.nuget/packages/mongodb.bson/2.9.3/lib/netstandard1.5/MongoDB.Bson.dll"
]
}
],
"source": [
"//#r \"nuget:Google.Protobuf, 3.6.1\"\n",
"#r \"C:/Users/darby/.nuget/packages/google.protobuf/3.6.1/lib/netstandard1.0/Google.Protobuf.dll\"\n",
"//#r \"nuget:Microsoft.CSharp, 4.5.0\"\n",
"//#r \"C:/Users/darby/.nuget/packages/microsoft.netcore.app.runtime.linux-x64/3.0.0/runtimes/linux-x64/lib/netcoreapp3.0/Microsoft.CSharp.dll\" \n",
"//#r \"nuget:Newtonsoft.Json, 12.0.3\"\n",
"#r \"C:/Users/darby/.nuget/packages/newtonsoft.json/12.0.3/lib/netstandard2.0/Newtonsoft.Json.dll\"\n",
"//#r \"nuget:System.Linq.Dynamic, 1.0.7\"\n",
"#r \"C:/Users/darby/.nuget/packages/system.linq.dynamic.core/1.0.19/lib/netstandard2.0/System.Linq.Dynamic.Core.dll\"\n",
"//#r \"nuget:MongoDB.Driver, 2.9.3\"\n",
"#r \"C:/Users/darby/.nuget/packages/mongodb.driver/2.9.3/lib/netstandard1.5/MongoDB.Driver.dll\" \n",
"#r \"C:/Users/darby/.nuget/packages/mongodb.driver.core/2.9.3/lib/netstandard1.5/MongoDB.Driver.Core.dll\"\n",
"//#r \"nuget:MongoDB.Bson, 2.9.3\"\n",
"#r \"C:/Users/darby/.nuget/packages/mongodb.bson/2.9.3/lib/netstandard1.5/MongoDB.Bson.dll\" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Invalid: Command: #r c:/code/bts/spark/build/Debug/bin/netstandard2.0/spark_historical.dll"
]
}
],
"source": [
"#r \"c:/code/bts/spark/build/Debug/bin/netstandard2.0/spark_historical.dll\" \n",
"using bts.history;\n",
"using MongoDB.Driver;\n",
"using MongoDB.Driver.Linq;\n",
"using Google.Protobuf.WellKnownTypes;\n",
"using static bts.history.Query;\n",
"using mbts.co2;\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var q = new Query(\"oil_nov\", \"bigblue\");\n",
"//Timestamp ts = new Timestamp();\n",
"//ts.Seconds = 15;\n",
"//DateTime dt = ts.ToDateTime();\n",
"//display(dt.Kind);"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"var c1 = q.collection<HistoryRow>(\"CLZ9-CLF0\");\n",
"var c2 = q.collection<HistoryRow>(\"CLF0-CLG0\");\n",
"var c3 = q.collection<HistoryRow>(\"CLZ9-CLG0\");\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//var s = q.series<HistoryRow>(\"ZNZ9-ZNH0\").Where( x=> x.Book != null );\n",
"//var s1 = s.Where( x => x.Book.Bids[0].Size > 0);\n",
"//display(s.Count())\n",
"//var s2 = s.Where( x => x.sending_time >= new DateTime(2019, 11, 25));\n",
"//display(s2.Count());"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 19, 0, 0, 0), DateTimeKind.Utc);\n",
"var end = DateTime.SpecifyKind(new DateTime(2019, 11, 22, 23, 59, 59), DateTimeKind.Utc);\n",
"var c1t = q.timeseries<HistoryRow>(c1, begin, end);\n",
"var c2t = q.timeseries<HistoryRow>(c2, begin, end);\n",
"var c3t = q.timeseries<HistoryRow>(c3, begin, end);\n",
"\n",
"//var ft = q.timeseries<HistoryRow>(f, new DateTime(2019, 11, 20, 21, 21, 22), new DateTime(2019, 11, 20, 21, 21, 23));\n",
"//var jt = q.timeseries<HistoryRow>(j, new DateTime(2019, 11, 20, 21, 21, 22), new DateTime(2019, 11, 20, 21, 21, 23));\n",
"//var mt = q.timeseries<HistoryRow>(m, new DateTime(2019, 11, 20, 21, 21, 22), new DateTime(2019, 11, 20, 21, 21, 23));"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"2547"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"243436"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"6044"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(c1t.Count());\n",
"display(c2t.Count());\n",
"display(c3t.Count());\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th>TopBook</th><th>value</th><th>trade_date</th><th>sending_time</th><th>transact_time</th><th>MsgSeqNum</th></tr></thead><tbody><tr><td>{ bts.co2.TopBookMessage: Bid: { bts.co2.PriceSizeMessage: Mantissa: -10, Exponent: 0, Size: 4 }, Ask: { bts.co2.PriceSizeMessage: Mantissa: -4, Exponent: 0, Size: 4 } }</td><td>{ bts.history.HistoryRow: trade_date: 2019-11-20 00:00:00Z, sending_time: 2019-11-20 09:27:26Z, transact_time: 2019-11-20 09:27:26Z, TradeDate: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574208000, Nanos: 0 }, MsgSeqNum: 85400264, SendingTime: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574242046, Nanos: 515773700 }, TransactTime: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574242046, Nanos: 515675500 }, SecurityDesc: CLZ9-CLG0, Book: { bts.co2.BookMessage: Bids: [ { bts.co2.PriceSizeMessage: Mantissa: -10, Exponent: 0, Size: 4 }, { bts.co2.PriceSizeMessage: Mantissa: -11, Exponent: 0, Size: 1 }, { bts.co2.PriceSizeMessage: Mantissa: -14, Exponent: 0, Size: 1 }, { bts.co2.PriceSizeMessage: Mantissa: -15, Exponent: 0, Size: 1 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 } ], Asks: [ { bts.co2.PriceSizeMessage: Mantissa: -4, Exponent: 0, Size: 4 }, { bts.co2.PriceSizeMessage: Mantissa: -3, Exponent: 0, Size: 1 }, { bts.co2.PriceSizeMessage: Mantissa: 1, Exponent: 0, Size: 1 }, { bts.co2.PriceSizeMessage: Mantissa: 2, Exponent: 0, Size: 1 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 } ] }, TopBook: &lt;null&gt;, Trade: &lt;null&gt;, Order: &lt;null&gt; }</td><td>2019-11-20 00:00:00Z</td><td>2019-11-20 09:27:26Z</td><td>2019-11-20 09:27:26Z</td><td>85400264</td></tr></tbody></table>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"var c1f = c1t.Where(x => x.Book != null && (x.Book.Bids.Count > 0 || x.Book.Asks.Count > 0));\n",
"var c2f = c2t.Where(x => x.Book != null && (x.Book.Bids.Count > 0 || x.Book.Asks.Count > 0));\n",
"var c3f = c3t.Where(x => x.Book != null && (x.Book.Bids.Count > 0 || x.Book.Asks.Count > 0));\n",
"\n",
"var c1top = c1f.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var c2top = c2f.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var c3top = c3f.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"\n",
"display(c3top.Last());\n",
"//display(z9f.Take(1));"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"class TopReport<T> where T : IHasTopBook, IHasTimestamp, Google.Protobuf.IDeepCloneable<T>\n",
"{\n",
" readonly T[] _legs;\n",
" readonly T _synth;\n",
" public TopReport(T[] legs, T synth)\n",
" {\n",
" _legs = (T[])legs.Clone();\n",
" _synth = synth.Clone();\n",
" }\n",
" public uint seq_num => _synth.MsgSeqNum;\n",
" public string trade_date => _synth.trade_date.ToString(\"yyyy-MM-dd\");\n",
" public string sending_time => _synth.sending_time.ToString(\"yyyy-MM-dd HH:mm:ss.ffffff\");\n",
" public string transact_time => _synth.transact_time.ToString(\"yyyy-MM-dd HH:mm:ss.ffffff\");\n",
" public uint bidsize => _synth.TopBook.Bid.Size;\n",
" public double bid => _synth.TopBook.Bid.price();\n",
" public double ask => _synth.TopBook.Ask.price();\n",
" public uint asksize => _synth.TopBook.Ask.Size;\n",
" \n",
" public string[] legbids => _legs.Select( x=> x.MsgSeqNum + \" \" + x.TopBook.Bid.Size + \" \" + \n",
" x.TopBook.Bid.price().ToString(\"0.00 |\") ).ToArray();\n",
" public string[] legasks => _legs.Select( x=> x.MsgSeqNum + \" \" + x.TopBook.Ask.Size + \" \" + \n",
" x.TopBook.Ask.price().ToString(\"0.00 |\") ).ToArray();\n",
"}\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
" "
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"\n",
"var synth = create_synthetic_top( new []{c1top, c2top, c3top}, new[] {1.0, 1.0, -1.0}, new[] {1.0, 1.0, -1.0}, \n",
" x => x.TopBook.Bid.price() > 0.0 || x.TopBook.Ask.price() < 0.0, \n",
" (legs, synth)=> new TopReport<GetTopOfBook>(legs, synth));"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//BUY:CL_F0J0M0 t:\"2019-11-20T21:21:22.209544500Z\" active_for:210100 ns -0.01:8\n",
"//BUY:CL_F0J0M0 t:\"2019-11-20T21:21:22.211537800Z\" active_for:11000 ns -0.01:7\n",
"//BUY:CL_F0J0M0 t:\"2019-11-20T21:21:22.211548800Z\" active_for:42400 ns -0.01:7\n",
"//BUY:CL_F0J0M0 t:\"2019-11-20T21:21:22.211591200Z\" active_for:296400 ns -0.01:7\n",
"display(synth.OrderBy(x => x.sending_time));\n",
"//Console.WriteLine(synth.Take(10).Count());"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".NET (C#)",
"language": "C#",
"name": ".net-csharp"
},
"language_info": {
"file_extension": ".cs",
"mimetype": "text/x-csharp",
"name": "C#",
"pygments_lexer": "csharp",
"version": "8.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
@@ -0,0 +1,320 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Invalid: Command: #r C:/Users/darby/.nuget/packages/google.protobuf/3.6.1/lib/netstandard1.0/Google.Protobuf.dllInvalid: Command: #r C:/Users/darby/.nuget/packages/newtonsoft.json/12.0.3/lib/netstandard2.0/Newtonsoft.Json.dllInvalid: Command: #r C:/Users/darby/.nuget/packages/system.linq.dynamic.core/1.0.19/lib/netstandard2.0/System.Linq.Dynamic.Core.dllInvalid: Command: #r C:/Users/darby/.nuget/packages/mongodb.driver/2.9.3/lib/netstandard1.5/MongoDB.Driver.dllInvalid: Command: #r C:/Users/darby/.nuget/packages/mongodb.driver.core/2.9.3/lib/netstandard1.5/MongoDB.Driver.Core.dllInvalid: Command: #r C:/Users/darby/.nuget/packages/mongodb.bson/2.9.3/lib/netstandard1.5/MongoDB.Bson.dll"
]
}
],
"source": [
"//#r \"nuget:Google.Protobuf, 3.6.1\"\n",
"#r \"C:/Users/darby/.nuget/packages/google.protobuf/3.6.1/lib/netstandard1.0/Google.Protobuf.dll\"\n",
"//#r \"nuget:Microsoft.CSharp, 4.5.0\"\n",
"//#r \"C:/Users/darby/.nuget/packages/microsoft.netcore.app.runtime.linux-x64/3.0.0/runtimes/linux-x64/lib/netcoreapp3.0/Microsoft.CSharp.dll\" \n",
"//#r \"nuget:Newtonsoft.Json, 12.0.3\"\n",
"#r \"C:/Users/darby/.nuget/packages/newtonsoft.json/12.0.3/lib/netstandard2.0/Newtonsoft.Json.dll\"\n",
"//#r \"nuget:System.Linq.Dynamic, 1.0.7\"\n",
"#r \"C:/Users/darby/.nuget/packages/system.linq.dynamic.core/1.0.19/lib/netstandard2.0/System.Linq.Dynamic.Core.dll\"\n",
"//#r \"nuget:MongoDB.Driver, 2.9.3\"\n",
"#r \"C:/Users/darby/.nuget/packages/mongodb.driver/2.9.3/lib/netstandard1.5/MongoDB.Driver.dll\" \n",
"#r \"C:/Users/darby/.nuget/packages/mongodb.driver.core/2.9.3/lib/netstandard1.5/MongoDB.Driver.Core.dll\"\n",
"//#r \"nuget:MongoDB.Bson, 2.9.3\"\n",
"#r \"C:/Users/darby/.nuget/packages/mongodb.bson/2.9.3/lib/netstandard1.5/MongoDB.Bson.dll\" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Invalid: Command: #r c:/code/bts/spark/build/Debug/bin/netstandard2.0/spark_historical.dll"
]
}
],
"source": [
"#r \"c:/code/bts/spark/build/Debug/bin/netstandard2.0/spark_historical.dll\" \n",
"using bts.history;\n",
"using MongoDB.Driver;\n",
"using MongoDB.Driver.Linq;\n",
"using Google.Protobuf.WellKnownTypes;\n",
"using static bts.history.Query;\n",
"using mbts.co2;\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var q = new Query(\"oil_nov\", \"bigblue\");\n",
"//Timestamp ts = new Timestamp();\n",
"//ts.Seconds = 15;\n",
"//DateTime dt = ts.ToDateTime();\n",
"//display(dt.Kind);"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"var c1 = q.collection<HistoryRow>(\"CLZ9-CLF0\");\n",
"var c2 = q.collection<HistoryRow>(\"CLF0-CLG0\");\n",
"var c3 = q.collection<HistoryRow>(\"CLZ9-CLG0\");\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//var s = q.series<HistoryRow>(\"ZNZ9-ZNH0\").Where( x=> x.Book != null );\n",
"//var s1 = s.Where( x => x.Book.Bids[0].Size > 0);\n",
"//display(s.Count())\n",
"//var s2 = s.Where( x => x.sending_time >= new DateTime(2019, 11, 25));\n",
"//display(s2.Count());"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 19, 0, 0, 0), DateTimeKind.Utc);\n",
"var end = DateTime.SpecifyKind(new DateTime(2019, 11, 22, 23, 59, 59), DateTimeKind.Utc);\n",
"var c1t = q.timeseries<HistoryRow>(c1, begin, end);\n",
"var c2t = q.timeseries<HistoryRow>(c2, begin, end);\n",
"var c3t = q.timeseries<HistoryRow>(c3, begin, end);\n",
"\n",
"//var ft = q.timeseries<HistoryRow>(f, new DateTime(2019, 11, 20, 21, 21, 22), new DateTime(2019, 11, 20, 21, 21, 23));\n",
"//var jt = q.timeseries<HistoryRow>(j, new DateTime(2019, 11, 20, 21, 21, 22), new DateTime(2019, 11, 20, 21, 21, 23));\n",
"//var mt = q.timeseries<HistoryRow>(m, new DateTime(2019, 11, 20, 21, 21, 22), new DateTime(2019, 11, 20, 21, 21, 23));"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"2547"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"243436"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"6044"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(c1t.Count());\n",
"display(c2t.Count());\n",
"display(c3t.Count());\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th>TopBook</th><th>value</th><th>trade_date</th><th>sending_time</th><th>transact_time</th><th>MsgSeqNum</th></tr></thead><tbody><tr><td>{ bts.co2.TopBookMessage: Bid: { bts.co2.PriceSizeMessage: Mantissa: -10, Exponent: 0, Size: 4 }, Ask: { bts.co2.PriceSizeMessage: Mantissa: -4, Exponent: 0, Size: 4 } }</td><td>{ bts.history.HistoryRow: trade_date: 2019-11-20 00:00:00Z, sending_time: 2019-11-20 09:27:26Z, transact_time: 2019-11-20 09:27:26Z, TradeDate: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574208000, Nanos: 0 }, MsgSeqNum: 85400264, SendingTime: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574242046, Nanos: 515773700 }, TransactTime: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574242046, Nanos: 515675500 }, SecurityDesc: CLZ9-CLG0, Book: { bts.co2.BookMessage: Bids: [ { bts.co2.PriceSizeMessage: Mantissa: -10, Exponent: 0, Size: 4 }, { bts.co2.PriceSizeMessage: Mantissa: -11, Exponent: 0, Size: 1 }, { bts.co2.PriceSizeMessage: Mantissa: -14, Exponent: 0, Size: 1 }, { bts.co2.PriceSizeMessage: Mantissa: -15, Exponent: 0, Size: 1 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 } ], Asks: [ { bts.co2.PriceSizeMessage: Mantissa: -4, Exponent: 0, Size: 4 }, { bts.co2.PriceSizeMessage: Mantissa: -3, Exponent: 0, Size: 1 }, { bts.co2.PriceSizeMessage: Mantissa: 1, Exponent: 0, Size: 1 }, { bts.co2.PriceSizeMessage: Mantissa: 2, Exponent: 0, Size: 1 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 }, { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 0 } ] }, TopBook: &lt;null&gt;, Trade: &lt;null&gt;, Order: &lt;null&gt; }</td><td>2019-11-20 00:00:00Z</td><td>2019-11-20 09:27:26Z</td><td>2019-11-20 09:27:26Z</td><td>85400264</td></tr></tbody></table>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"var c1f = c1t.Where(x => x.Book != null && (x.Book.Bids.Count > 0 || x.Book.Asks.Count > 0));\n",
"var c2f = c2t.Where(x => x.Book != null && (x.Book.Bids.Count > 0 || x.Book.Asks.Count > 0));\n",
"var c3f = c3t.Where(x => x.Book != null && (x.Book.Bids.Count > 0 || x.Book.Asks.Count > 0));\n",
"\n",
"var c1top = c1f.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var c2top = c2f.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var c3top = c3f.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"\n",
"display(c3top.Last());\n",
"//display(z9f.Take(1));"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"class TopReport<T> where T : IHasTopBook, IHasTimestamp, Google.Protobuf.IDeepCloneable<T>\n",
"{\n",
" readonly T[] _legs;\n",
" readonly T _synth;\n",
" public TopReport(T[] legs, T synth)\n",
" {\n",
" _legs = (T[])legs.Clone();\n",
" _synth = synth.Clone();\n",
" }\n",
" public uint seq_num => _synth.MsgSeqNum;\n",
" public string trade_date => _synth.trade_date.ToString(\"yyyy-MM-dd\");\n",
" public string sending_time => _synth.sending_time.ToString(\"yyyy-MM-dd HH:mm:ss.ffffff\");\n",
" public string transact_time => _synth.transact_time.ToString(\"yyyy-MM-dd HH:mm:ss.ffffff\");\n",
" public uint bidsize => _synth.TopBook.Bid.Size;\n",
" public double bid => _synth.TopBook.Bid.price();\n",
" public double ask => _synth.TopBook.Ask.price();\n",
" public uint asksize => _synth.TopBook.Ask.Size;\n",
" \n",
" public string[] legbids => _legs.Select( x=> x.MsgSeqNum + \" \" + x.TopBook.Bid.Size + \" \" + \n",
" x.TopBook.Bid.price().ToString(\"0.00 |\") ).ToArray();\n",
" public string[] legasks => _legs.Select( x=> x.MsgSeqNum + \" \" + x.TopBook.Ask.Size + \" \" + \n",
" x.TopBook.Ask.price().ToString(\"0.00 |\") ).ToArray();\n",
"}\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
" "
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"\n",
"var synth = create_synthetic_top( new []{c1top, c2top, c3top}, new[] {1.0, 1.0, -1.0}, new[] {1.0, 1.0, -1.0}, \n",
" x => x.TopBook.Bid.price() > 0.0 || x.TopBook.Ask.price() < 0.0, \n",
" (legs, synth)=> new TopReport<GetTopOfBook>(legs, synth));"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>seq_num</th><th>trade_date</th><th>sending_time</th><th>transact_time</th><th>bidsize</th><th>bid</th><th>ask</th><th>asksize</th><th>legbids</th><th>legasks</th></tr></thead><tbody><tr><td>0</td><td>77632899</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:29.444834</td><td>2019-11-19 23:01:29.444674</td><td>1</td><td>-25</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77632359 599 10.00 |77632899 0 0.00 |</td><td>77623170 9 -12.00 |77632359 809 11.00 |77632899 1 22.00 |</td></tr><tr><td>1</td><td>77632900</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:29.444935</td><td>2019-11-19 23:01:29.444830</td><td>1</td><td>-25</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77632359 599 10.00 |77632900 0 0.00 |</td><td>77623170 9 -12.00 |77632359 809 11.00 |77632900 1 22.00 |</td></tr><tr><td>2</td><td>77633139</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:31.008894</td><td>2019-11-19 23:01:31.008777</td><td>1</td><td>-25</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77633139 599 10.00 |77632900 0 0.00 |</td><td>77623170 9 -12.00 |77633139 809 11.00 |77632900 1 22.00 |</td></tr><tr><td>3</td><td>77633233</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:31.507462</td><td>2019-11-19 23:01:31.507346</td><td>1</td><td>-25</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77633233 599 10.00 |77632900 0 0.00 |</td><td>77623170 9 -12.00 |77633233 809 11.00 |77632900 1 22.00 |</td></tr><tr><td>4</td><td>77633265</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:32.157546</td><td>2019-11-19 23:01:32.157409</td><td>1</td><td>-10</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77633233 599 10.00 |77633265 0 0.00 |</td><td>77623170 9 -12.00 |77633233 809 11.00 |77633265 1 7.00 |</td></tr><tr><td>5</td><td>77633266</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:32.157639</td><td>2019-11-19 23:01:32.157536</td><td>1</td><td>-10</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77633233 599 10.00 |77633266 0 0.00 |</td><td>77623170 9 -12.00 |77633233 809 11.00 |77633266 1 7.00 |</td></tr><tr><td>6</td><td>77633967</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:38.955779</td><td>2019-11-19 23:01:38.955632</td><td>1</td><td>-6</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77633233 599 10.00 |77633967 0 0.00 |</td><td>77623170 9 -12.00 |77633233 809 11.00 |77633967 1 3.00 |</td></tr><tr><td>7</td><td>77633968</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:38.955866</td><td>2019-11-19 23:01:38.955760</td><td>1</td><td>-6</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77633233 599 10.00 |77633968 0 0.00 |</td><td>77623170 9 -12.00 |77633233 809 11.00 |77633968 1 3.00 |</td></tr><tr><td>8</td><td>77634067</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:41.509218</td><td>2019-11-19 23:01:41.509092</td><td>1</td><td>-6</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77634067 599 10.00 |77633968 0 0.00 |</td><td>77623170 9 -12.00 |77634067 809 11.00 |77633968 1 3.00 |</td></tr><tr><td>9</td><td>77634146</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:42.008457</td><td>2019-11-19 23:01:42.008346</td><td>1</td><td>-6</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77634146 599 10.00 |77633968 0 0.00 |</td><td>77623170 9 -12.00 |77634146 809 11.00 |77633968 1 3.00 |</td></tr><tr><td>10</td><td>77634662</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:44.039520</td><td>2019-11-19 23:01:44.039346</td><td>1</td><td>-4</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77634146 599 10.00 |77634662 0 0.00 |</td><td>77623170 9 -12.00 |77634146 809 11.00 |77634662 1 1.00 |</td></tr><tr><td>11</td><td>77634663</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:44.039606</td><td>2019-11-19 23:01:44.039493</td><td>1</td><td>-4</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77634146 599 10.00 |77634663 0 0.00 |</td><td>77623170 9 -12.00 |77634146 809 11.00 |77634663 1 1.00 |</td></tr><tr><td>12</td><td>77635060</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:52.009603</td><td>2019-11-19 23:01:52.009478</td><td>1</td><td>-4</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77635060 599 10.00 |77634663 0 0.00 |</td><td>77623170 9 -12.00 |77635060 809 11.00 |77634663 1 1.00 |</td></tr><tr><td>13</td><td>77635104</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:52.509048</td><td>2019-11-19 23:01:52.508929</td><td>1</td><td>-4</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77635104 599 10.00 |77634663 0 0.00 |</td><td>77623170 9 -12.00 |77635104 809 11.00 |77634663 1 1.00 |</td></tr><tr><td>14</td><td>77635195</td><td>2019-11-20 00:00:00.000000</td><td>2019-11-19 23:01:54.107257</td><td>2019-11-19 23:01:54.107128</td><td>1</td><td>-4</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77635104 599 10.00 |77635195 0 0.00 |</td><td>77623170 9 -12.00 |77635104 809 11.00 |77635195 1 1.00 |</td></tr><tr><td>15</td><td>77635196</td><td>2019-Line truncated
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"//BUY:CL_F0J0M0 t:\"2019-11-20T21:21:22.209544500Z\" active_for:210100 ns -0.01:8\n",
"//BUY:CL_F0J0M0 t:\"2019-11-20T21:21:22.211537800Z\" active_for:11000 ns -0.01:7\n",
"//BUY:CL_F0J0M0 t:\"2019-11-20T21:21:22.211548800Z\" active_for:42400 ns -0.01:7\n",
"//BUY:CL_F0J0M0 t:\"2019-11-20T21:21:22.211591200Z\" active_for:296400 ns -0.01:7\n",
"display(synth.OrderBy(x => x.sending_time));\n",
"//Console.WriteLine(synth.Take(10).Count());"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".NET (C#)",
"language": "C#",
"name": ".net-csharp"
},
"language_info": {
"file_extension": ".cs",
"mimetype": "text/x-csharp",
"name": "C#",
"pygments_lexer": "csharp",
"version": "8.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}