debugging KFillModel

This commit is contained in:
Kevin Darby committed 2019-12-22 16:46:06 -05:00
1 parent 41c8351709
commit 4e440fc218
12 files changed
+1169 -2095

No files matched your search

@@ -19,7 +19,7 @@ namespace bts.history
string[] _security_list;
//algo parameters
public double hedge_ticks { get; set; } = 1;
public double profit_ticks { get; set; } = 0.0;
public double hedge_factor { get; set; } = 1.0;
protected override void do_launch(string[] security_list, Side side, double price, uint size, Timestamp asof, ulong order_key)
@@ -51,8 +51,8 @@ namespace bts.history
var side = Utils.opposite_side(fill.order.side);
uint size = (uint)(fill.size*this.hedge_factor);
double price = (side == Side.Buy) ?
fill.price - this.hedge_ticks :
fill.price + this.hedge_ticks;
fill.price - this.profit_ticks :
fill.price + this.profit_ticks;
send_hedge(fill.order.security_desc, side, price, size, fill.TransactTime);
}
@@ -149,13 +149,12 @@ namespace bts.history
uint aggressor_qty = trade_summary.Size; //this could be greater than the aggressor size in some cases where implieds trade
if(aggressor_qty != orders.First().LastQty)
Log.Testing.warn("trade had some implied");
if (_use_top)
{
match_top(queue, trade_summary, ref aggressor_qty, matches);
}
if(_fifo_percent > 0.0)
{
uint fifo_lots = (uint)Math.Truncate(_fifo_percent*aggressor_qty);
uint fifo_lots = (uint)Math.Truncate(_fifo_percent * aggressor_qty);
if(fifo_lots > 0)
{
if(aggressor_qty == 1 || aggressor_qty == 2)
fifo_lots = 1;
else if(aggressor_qty == 3)
@@ -163,8 +162,10 @@ namespace bts.history
aggressor_qty -= fifo_lots;
match_fifo(queue, trade_summary, ref fifo_lots, matches);
}
match_prorata(queue, trade_summary, ref aggressor_qty, matches);
match_fifo(queue, trade_summary, ref aggressor_qty, matches);
if(aggressor_qty > 0)
match_prorata(queue, trade_summary, ref aggressor_qty, matches);
if(aggressor_qty > 0)
match_fifo(queue, trade_summary, ref aggressor_qty, matches);
validate_matches(orders, matches);
}
//https://www.cmegroup.com/confluence/display/EPICSANDBOX/CME+Globex+Matching+Algorithm+Steps#CMEGlobexMatchingAlgorithmSteps-Split
@@ -209,6 +210,7 @@ namespace bts.history
void match_prorata(QueueType queue, TradeMessage trade_summary, ref uint aggressor_qty, List<ITradeDetail> matches)
{
uint orig_aggressor_qty = aggressor_qty;
uint total = queue.Sum(x => (uint)x.Value.size);
uint rata = 0;
var noqueue = new QueueType(); //this is the list of orders that received no prorata, and are therefore eligible for leveling
@@ -218,22 +220,25 @@ namespace bts.history
if(alloc >= _min_prorata)
{
var q = make_match(alloc, lot.Value.order_id, matches);
q = Math.Min(q, aggressor_qty);
aggressor_qty -= q;
rata += q;
if (aggressor_qty <= 0)
{
Log.assert(aggressor_qty == 0);
break;
}
}
else
noqueue.Add(lot.Key, lot.Value);
}
if(_use_leveling && rata < total)
if(_use_leveling && aggressor_qty > 0 && noqueue.Count > 0)
{
var l = noqueue.Select( x => x.Value ).OrderBy( xx => xx.size ).ThenBy( yy => yy.last_change.to_datetime() ).ToArray();
var diff = total - rata;
int i = 0;
while(diff > 0)
for(int i = 0; i < l.Length && aggressor_qty > 0; i++)
{
var lentry = l[i++];
var q = make_match(1, lentry.order_id, matches);
diff--;
var q = make_match(1, l[i].order_id, matches);
aggressor_qty--;
}
}
}
@@ -1,307 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 19,
"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": 20,
"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": 21,
"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": 22,
"metadata": {},
"outputs": [],
"source": [
"var f = q.collection<HistoryRow>(\"CLF0-CLJ0\");\n",
"var j = q.collection<HistoryRow>(\"CLJ0-CLM0\");\n",
"var m = q.collection<HistoryRow>(\"CLF0-CLM0\");\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": 24,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var ft = q.timeseries<HistoryRow>(f, new DateTime(2019, 11, 19, 0, 0, 0), new DateTime(2019, 11, 21, 23, 59, 59));\n",
"var jt = q.timeseries<HistoryRow>(j, new DateTime(2019, 11, 19, 0, 0, 0), new DateTime(2019, 11, 21, 23, 59, 59));\n",
"var mt = q.timeseries<HistoryRow>(m, new DateTime(2019, 11, 19, 0, 0, 0), new DateTime(2019, 11, 21, 23, 59, 59));\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": 13,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"317961"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"402409"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"438568"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(ft.Count());\n",
"display(jt.Count());\n",
"display(mt.Count());\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var ff = ft.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"var jf = jt.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"var mf = mt.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"\n",
"var ftop = ff.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var jtop = jf.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var mtop = mf.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"\n",
"//display(h0f.Take(1));\n",
"//display(z9f.Take(1));"
]
},
{
"cell_type": "code",
"execution_count": 26,
"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 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": 27,
"metadata": {},
"outputs": [],
"source": [
"\n",
"var synth = create_synthetic_top( new []{ftop, jtop, mtop}, 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": 28,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>seq_num</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>77608908</td><td>2019-11-19 23:00:00.200092</td><td>2019-11-19 23:00:00.010916</td><td>0</td><td>140</td><td>9</td><td>1</td><td>77608433 1 69.00 |77608393 88 71.00 |77608908 4 141.00 |</td><td>77608433 1 77.00 |77608393 82 73.00 |77608908 0 0.00 |</td></tr><tr><td>1</td><td>77608909</td><td>2019-11-19 23:00:00.200105</td><td>2019-11-19 23:00:00.010918</td><td>0</td><td>140</td><td>9</td><td>1</td><td>77608433 1 69.00 |77608393 88 71.00 |77608909 4 141.00 |</td><td>77608433 1 77.00 |77608393 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>2</td><td>77609069</td><td>2019-11-19 23:00:00.202060</td><td>2019-11-19 23:00:00.016665</td><td>0</td><td>140</td><td>9</td><td>1</td><td>77608433 1 69.00 |77609069 88 71.00 |77608909 4 141.00 |</td><td>77608433 1 77.00 |77609069 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>3</td><td>77609070</td><td>2019-11-19 23:00:00.202068</td><td>2019-11-19 23:00:00.016666</td><td>0</td><td>140</td><td>9</td><td>1</td><td>77608433 1 69.00 |77609070 89 71.00 |77608909 4 141.00 |</td><td>77608433 1 77.00 |77609070 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>4</td><td>77609115</td><td>2019-11-19 23:00:00.202598</td><td>2019-11-19 23:00:00.017703</td><td>0</td><td>140</td><td>9</td><td>1</td><td>77608433 1 69.00 |77609115 89 71.00 |77608909 4 141.00 |</td><td>77608433 1 77.00 |77609115 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>5</td><td>77609123</td><td>2019-11-19 23:00:00.202678</td><td>2019-11-19 23:00:00.017813</td><td>0</td><td>141</td><td>9</td><td>1</td><td>77609123 2 70.00 |77609115 89 71.00 |77608909 4 141.00 |</td><td>77609123 1 77.00 |77609115 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>6</td><td>77609124</td><td>2019-11-19 23:00:00.202687</td><td>2019-11-19 23:00:00.017813</td><td>0</td><td>141</td><td>9</td><td>4</td><td>77609124 2 70.00 |77609115 89 71.00 |77608909 4 141.00 |</td><td>77609124 4 77.00 |77609115 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>7</td><td>77609369</td><td>2019-11-19 23:00:00.205493</td><td>2019-11-19 23:00:00.020957</td><td>0</td><td>142</td><td>9</td><td>4</td><td>77609369 3 71.00 |77609115 89 71.00 |77608909 4 141.00 |</td><td>77609369 4 77.00 |77609115 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>8</td><td>77609370</td><td>2019-11-19 23:00:00.205506</td><td>2019-11-19 23:00:00.020959</td><td>0</td><td>142</td><td>6</td><td>3</td><td>77609370 3 71.00 |77609115 89 71.00 |77608909 4 141.00 |</td><td>77609370 3 74.00 |77609115 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>9</td><td>77609460</td><td>2019-11-19 23:00:00.206467</td><td>2019-11-19 23:00:00.021838</td><td>0</td><td>142</td><td>5</td><td>3</td><td>77609370 3 71.00 |77609115 89 71.00 |77609460 3 142.00 |</td><td>77609370 3 74.00 |77609115 82 73.00 |77609460 0 0.00 |</td></tr><tr><td>10</td><td>127750158</td><td>2019-11-20 22:47:47.470815</td><td>2019-11-20 22:47:47.470477</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750158 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750158 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>11</td><td>127750159</td><td>2019-11-20 22:47:47.470854</td><td>2019-11-20 22:47:47.470478</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750159 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750159 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>12</td><td>127750160</td><td>2019-11-20 22:47:47.470864</td><td>2019-11-20 22:47:47.470479</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750160 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750160 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>13</td><td>127750161</td><td>2019-11-20 22:47:47.470875</td><td>2019-11-20 22:47:47.470480</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750161 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750161 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>14</td><td>127750162</td><td>2019-11-20 22:47:47.470885</td><td>2019-11-20 22:47:47.470481</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750162 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750162 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>15</td><td>127750163</td><td>2019-11-20 22:47:47.470900</td><td>2019-11-20 22:47:47.470483</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750163 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750163 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>16</td><td>127750164</td><td>2019-11-20 22:47:47.470909</td><td>2019-11-20 22:47:47.470484</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750164 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750164 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>17</td><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.Take(5000).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
}
@@ -1,295 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"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": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"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": 3,
"metadata": {},
"outputs": [],
"source": [
"var q = new Query(\"oil_11_20\", \"bigblue\");\n",
"//Timestamp ts = new Timestamp();\n",
"//ts.Seconds = 15;\n",
"//DateTime dt = ts.ToDateTime();\n",
"//display(dt.Kind);"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"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": 6,
"metadata": {},
"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": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"18844"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"83773"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"35257"
]
},
"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": 16,
"metadata": {},
"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: 0, Exponent: 0, Size: 9 }, Ask: { bts.co2.PriceSizeMessage: Mantissa: 4, Exponent: 0, Size: 17 } }</td><td>{ bts.history.HistoryRow: trade_date: 2019-11-20 00:00:00Z, sending_time: 2019-11-20 16:23:37Z, transact_time: 2019-11-20 16:23:37Z, TradeDate: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574208000, Nanos: 0 }, MsgSeqNum: 106692306, SendingTime: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574267017, Nanos: 559710300 }, TransactTime: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574267017, Nanos: 559610900 }, SecurityDesc: CLZ9-CLG0, Book: { bts.co2.BookMessage: Bids: [ { bts.co2.PriceSizeMessage: Mantissa: 0, Exponent: 0, Size: 9 }, { bts.co2.PriceSizeMessage: Mantissa: -1, Exponent: 0, Size: 14 }, { bts.co2.PriceSizeMessage: Mantissa: -2, Exponent: 0, Size: 50 }, { bts.co2.PriceSizeMessage: Mantissa: -3, Exponent: 0, Size: 10 }, { bts.co2.PriceSizeMessage: Mantissa: -4, Exponent: 0, Size: 10 }, { bts.co2.PriceSizeMessage: Mantissa: -5, Exponent: 0, Size: 10 }, { bts.co2.PriceSizeMessage: Mantissa: -6, Exponent: 0, Size: 10 }, { bts.co2.PriceSizeMessage: Mantissa: -7, Exponent: 0, Size: 10 }, { bts.co2.PriceSizeMessage: Mantissa: -8, Exponent: 0, Size: 10 }, { bts.co2.PriceSizeMessage: Mantissa: -9, Exponent: 0, Size: 10 } ], Asks: [ { bts.co2.PriceSizeMessage: Mantissa: 4, Exponent: 0, Size: 17 }, { bts.co2.PriceSizeMessage: Mantissa: 5, Exponent: 0, Size: 15 }, { bts.co2.PriceSizeMessage: Mantissa: 6, Exponent: 0, Size: 10 }, { bts.co2.PriceSizeMessage: Mantissa: 7, Exponent: 0, Size: 10 }, { bts.co2.PriceSizeMessage: Mantissa: 8, Exponent: 0, Size: 10 }, { bts.co2.PriceSizeMessage: Mantissa: 9, Exponent: 0, Size: 10 }, { bts.co2.PriceSizeMessage: Mantissa: 10, Exponent: 0, Size: 10 }, { bts.co2.PriceSizeMessage: Mantissa: 11, Exponent: 0, Size: 10 }, { 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 16:23:37Z</td><td>2019-11-20 16:23:37Z</td><td>106692306</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": 17,
"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": 18,
"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": 19,
"metadata": {},
"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</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</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</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</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</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</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</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</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</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</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</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</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</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</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</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-11-20</td><td>2019-11-19 23:01:54.107340</td><td>2019-11-19 23:01:54.107238</td><td>1</td><td>-4</td><td>-1</td><td>0</td><td>77623170 26 -13.00 |77635104 599 10.00 |77635196 0 0.00 |</td><td>77623170 9 -12.00 |77635104 809 11.00 |77635196 Line truncated
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(synth.OrderBy(x => x.sending_time));\n"
]
},
{
"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
}
@@ -1,309 +0,0 @@
{
"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": 2,
"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": 12,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var q = new Query(\"oil_12_4_2019\", \"bigblue\");\n",
"//Timestamp ts = new Timestamp();\n",
"//ts.Seconds = 15;\n",
"//DateTime dt = ts.ToDateTime();\n",
"//display(dt.Kind);"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"var f = q.collection<HistoryRow>(\"CLH0-CLM0\");\n",
"var j = q.collection<HistoryRow>(\"CLM0-CLZ0\");\n",
"var m = q.collection<HistoryRow>(\"CLH0-CLZ0\");\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 14,
"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": 15,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var start = new DateTime(2019, 12, 4, 0, 0, 0);\n",
"var end = new DateTime(2019, 12, 5, 23, 59, 59);\n",
"var ft = q.timeseries<HistoryRow>(f, start, end);\n",
"var jt = q.timeseries<HistoryRow>(j, start, end);\n",
"var mt = q.timeseries<HistoryRow>(m,start, 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": 16,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"223173"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"273808"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"223254"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(ft.Count());\n",
"display(jt.Count());\n",
"display(mt.Count());\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var ff = ft.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"var jf = jt.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"var mf = mt.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"\n",
"var ftop = ff.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var jtop = jf.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var mtop = mf.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"\n",
"//display(h0f.Take(1));\n",
"//display(z9f.Take(1));"
]
},
{
"cell_type": "code",
"execution_count": 18,
"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 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": 24,
"metadata": {},
"outputs": [],
"source": [
"\n",
"var synth = create_synthetic_top( new []{ftop, jtop, mtop}, 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": 25,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>seq_num</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>113288047</td><td>2019-12-04 15:09:12.008300</td><td>2019-12-04 15:09:12.008131</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288047 106 116.00 |112831258 32 200.00 |113288020 3 319.00 |</td><td>113288047 30 117.00 |112831258 17 201.00 |113288020 40 321.00 |</td></tr><tr><td>1</td><td>113288049</td><td>2019-12-04 15:09:12.008331</td><td>2019-12-04 15:09:12.008144</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288049 106 116.00 |112831258 32 200.00 |113288020 3 319.00 |</td><td>113288049 30 117.00 |112831258 17 201.00 |113288020 40 321.00 |</td></tr><tr><td>2</td><td>113288065</td><td>2019-12-04 15:09:12.008554</td><td>2019-12-04 15:09:12.008279</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288065 106 116.00 |112831258 32 200.00 |113288020 3 319.00 |</td><td>113288065 30 117.00 |112831258 17 201.00 |113288020 40 321.00 |</td></tr><tr><td>3</td><td>113288069</td><td>2019-12-04 15:09:12.008614</td><td>2019-12-04 15:09:12.008330</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288069 106 116.00 |112831258 32 200.00 |113288020 3 319.00 |</td><td>113288069 30 117.00 |112831258 17 201.00 |113288020 40 321.00 |</td></tr><tr><td>4</td><td>113288070</td><td>2019-12-04 15:09:12.008633</td><td>2019-12-04 15:09:12.008330</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288070 106 116.00 |112831258 32 200.00 |113288020 3 319.00 |</td><td>113288070 30 117.00 |112831258 17 201.00 |113288020 40 321.00 |</td></tr><tr><td>5</td><td>113288079</td><td>2019-12-04 15:09:12.008763</td><td>2019-12-04 15:09:12.008346</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288070 106 116.00 |112831258 32 200.00 |113288079 3 319.00 |</td><td>113288070 30 117.00 |112831258 17 201.00 |113288079 40 321.00 |</td></tr><tr><td>6</td><td>113288081</td><td>2019-12-04 15:09:12.008783</td><td>2019-12-04 15:09:12.008350</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288081 106 116.00 |112831258 32 200.00 |113288079 3 319.00 |</td><td>113288081 30 117.00 |112831258 17 201.00 |113288079 40 321.00 |</td></tr><tr><td>7</td><td>113288090</td><td>2019-12-04 15:09:12.008903</td><td>2019-12-04 15:09:12.008420</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288090 106 116.00 |112831258 32 200.00 |113288079 3 319.00 |</td><td>113288090 30 117.00 |112831258 17 201.00 |113288079 40 321.00 |</td></tr><tr><td>8</td><td>113288099</td><td>2019-12-04 15:09:12.009058</td><td>2019-12-04 15:09:12.008476</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288090 106 116.00 |112831258 32 200.00 |113288099 3 319.00 |</td><td>113288090 30 117.00 |112831258 17 201.00 |113288099 45 321.00 |</td></tr><tr><td>9</td><td>113288100</td><td>2019-12-04 15:09:12.009071</td><td>2019-12-04 15:09:12.008477</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288090 106 116.00 |112831258 32 200.00 |113288100 3 319.00 |</td><td>113288090 30 117.00 |112831258 17 201.00 |113288100 45 321.00 |</td></tr><tr><td>10</td><td>113288122</td><td>2019-12-04 15:09:12.009381</td><td>2019-12-04 15:09:12.008909</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288122 106 116.00 |112831258 32 200.00 |113288100 3 319.00 |</td><td>113288122 30 117.00 |112831258 17 201.00 |113288100 45 321.00 |</td></tr><tr><td>11</td><td>113288123</td><td>2019-12-04 15:09:12.009399</td><td>2019-12-04 15:09:12.008910</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288123 106 116.00 |112831258 32 200.00 |113288100 3 319.00 |</td><td>113288123 30 117.00 |112831258 17 201.00 |113288100 45 321.00 |</td></tr><tr><td>12</td><td>113288124</td><td>2019-12-04 15:09:12.009407</td><td>2019-12-04 15:09:12.008916</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288124 106 116.00 |112831258 32 200.00 |113288100 3 319.00 |</td><td>113288124 30 117.00 |112831258 17 201.00 |113288100 45 321.00 |</td></tr><tr><td>13</td><td>113288133</td><td>2019-12-04 15:09:12.009536</td><td>2019-12-04 15:09:12.009143</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288133 106 116.00 |112831258 32 200.00 |113288100 3 319.00 |</td><td>113288133 30 117.00 |112831258 17 201.00 |113288100 45 321.00 |</td></tr><tr><td>14</td><td>113288147</td><td>2019-12-04 15:09:12.009857</td><td>2019-12-04 15:09:12.009582</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288147 100 116.00 |112831258 32 200.00 |113288100 3 319.00 |</td><td>113288147 30 117.00 |112831258 17 201.00 |113288100 45 321.00 |</td></tr><tr><td>15</td><td>113288152</td><td>2019-12-04 15:09:12.010024</td><td>2019-12-04 15:09:12.009665</td><td>32</td><td>-5</td><td>-1</td><td>3</td><td>113288152 100 116.00 |112831258 32 200.00 |113288100 3 319.00 |</td><td>113288152 30 117.00 |112831258 17 201.00 |113288100 45 321.00 |</td></tr><tr><td>16</td><td>113288155</td><td>2019-12-04 15:09:12.010201</td><td>201Line 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.Take(15000).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,475 @@
{
"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.dllInvalid: Command: #r C:/Users/darby/.nuget/packages/protobuf-net/2.3.2/lib/netstandard1.3/protobuf-net.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\"\n",
"//#r \"nuget:protobuf-net, 2.3.2.0\"\n",
"#r \"C:/Users/darby/.nuget/packages/protobuf-net/2.3.2/lib/netstandard1.3/protobuf-net.dll\" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"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 MathNet.Numerics.Statistics;\n",
"using mbts.co2;\n",
"\n",
"bts.BTS.init();\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var q = new Query(\"ZN_201911_W4\", \"bigblue\");"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"var z9 = q.collection<HistoryRow>(\"ZNZ9\");\n",
"var h0 = q.collection<HistoryRow>(\"ZNH0\");\n",
"var spd = q.collection<HistoryRow>(\"ZNZ9-ZNH0\");\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 14, 0, 0), DateTimeKind.Utc); //9am east\n",
"var end = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 23, 0, 0), DateTimeKind.Utc); //6pm east\n",
"//var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 0, 0, 0), DateTimeKind.Utc);\n",
"//var end = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 23, 59, 59), DateTimeKind.Utc);\n",
"\n",
"var z9t = q.timeseries_cached<HistoryRow>(z9, begin, end);\n",
"var h0t = q.timeseries_cached<HistoryRow>(h0, begin, end);\n",
"var spdt = q.timeseries_cached<HistoryRow>(spd, begin, end);\n",
"\n",
"await Task.WhenAll(new[] {z9t, h0t, spdt} );\n",
"\n",
"//local copy so we don't beat up the database\n",
"var z9f = await z9t;\n",
"var h0f = await h0t;\n",
"var spdf = await spdt;"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"919548"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"479145"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"536630"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(z9f.Count()); display(h0f.Count()); display(spdf.Count());"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//quotes the last leg\n",
"var algo_type = typeof(PegCoverLean);\n",
"\n",
"var latency_in = 50_000u;\n",
"var latency_out = 50_000u;\n",
"var latency_iceberg = 60_000u;\n",
"var incoming_latency = new Bucket(latency_in, latency_in+1);\n",
"var outgoing_latency = new Bucket(latency_out, latency_out+1);\n",
"var sink = new LatencyOrderSink(incoming_latency, outgoing_latency);\n",
"var fill_model = new KFillModel(outgoing_latency, false, 0.20, 1u, true);\n",
"\n",
"var security_list = new [] {\"ZNZ9-ZNH0\"};\n",
"var algo_params = \"size=10;tick_size=0.015625,0.0078125,0.015625;hedge_factors=1,-1,-1;profit_ticks=0.0078125\";\n",
"var algo_orders = algo_results<HistoryRow>(sink, fill_model, \n",
" algo_type, algo_params, \n",
" bts.api.Side.Undefined, 0.0, 10, \n",
" security_list, //must match below\n",
" new[] {spdf}, latency_iceberg);"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"ename": "Unhandled Exception",
"evalue": "An item with the same key has already been added. Key: 846782689978",
"output_type": "error",
"traceback": [
"Unhandled Exception",
"An item with the same key has already been added. Key: 846782689978",
" at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)",
" at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](List`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)",
" at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)",
" at bts.history.KFillModel.validate_matches(IEnumerable`1 orders, List`1 matches) in c:\\code\\bts\\spark\\src\\client\\spark_historical\\FillModel\\KFillModel.cs:line 244",
" at bts.history.KFillModel.process_trade(Timestamp transact_time, String security_desc, TradeMessage trade_summary, IEnumerable`1 orders) in c:\\code\\bts\\spark\\src\\client\\spark_historical\\FillModel\\KFillModel.cs:line 169",
" at bts.history.Query.<>c__DisplayClass16_0`1.<algo_results>b__3(T[] valcache, Int32 min) in c:\\code\\bts\\spark\\src\\client\\spark_historical\\Query\\Query.cs:line 280",
" at bts.history.Query.stream_data[T,U](IEnumerable`1[] datastream, Func`3 function)+MoveNext() in c:\\code\\bts\\spark\\src\\client\\spark_historical\\Query\\Query.cs:line 133",
" at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)",
" at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)",
" at Submission#10.<<Initialize>>d__0.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
" at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)"
]
}
],
"source": [
"var algo_orders_cached = algo_orders.ToArray().OrderBy(x => x.order?.TransactTime ?? x.fill.TransactTime, \n",
" HistoricalExtensions.timestamp_comparer);\n",
"//var first_pass_fills = algo_orders.Where(x => x.fill != null).Select(x => x.fill);"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"100"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"35"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>order</th><th>fill</th></tr></thead><tbody><tr><td>0</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.777871200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.777821200Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.777871200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.777821200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>2</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.787706300Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.787656300Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.788590500Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.788540500Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>4</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789026900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.788976900Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789026900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.788976900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>6</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789093800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.789043800Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789321200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.789271200Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>8</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.790255800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.790205800Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.790255800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.790205800Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>10</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773164900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773114900Z&quot;, order_side: Sell, order_status: Working, order_price: 129.5, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>11</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773164900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773114900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.453125, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773510Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773460Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>13</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773715700Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773665700Z&quot;, order_side: Buy, order_status: Working, order_price: 129.453125, order_size: 10, order_filled: 0 }</td><td>&lt;nullLine truncated
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\n",
"display(algo_orders_cached.Where(x => x.fill != null).Sum(x => (int)x.fill.size) / 3.0);\n",
"display(algo_orders_cached.Where(x => x.fill != null).Count() / 3.0);\n",
"display(algo_orders_cached.Select(x => new Display(x)).Take(1000));"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"var exchange_orders = exchange_orders<HistoryRow>(h0f);"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>OrderUpdateAction</th><th>OrderId</th><th>SecurityDesc</th><th>MdOrderPriority</th><th>MdEntryPx</th><th>MdPriceLevel</th><th>MdDisplayQty</th><th>LastQty</th><th>MdEntryType</th><th>TradeDate</th><th>MsgSeqNum</th><th>SendingTime</th><th>TransactTime</th><th>MdEntry</th><th>OrderEntry</th></tr></thead><tbody><tr><td>0</td><td>New</td><td>846784119686</td><td>ZNH0</td><td>12365190692</td><td>129.359375</td><td>2</td><td>8</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4361037</td><td>&quot;2019-11-25T13:30:20.470246800Z&quot;</td><td>&quot;2019-11-25T13:30:20.470147Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 463670, MdEntryPx: 129.359375, MdEntrySize: 1590, NumberOfOrders: 105, MdPriceLevel: 2, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784119686, MdOrderPriority: 12365190692, MdDisplayQty: 8 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784119686, MdDisplayQty: 8, MdOrderPriority: 12365190692, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 48 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>1</td><td>Delete</td><td>846784119686</td><td>ZNH0</td><td>12365190692</td><td>129.359375</td><td>2</td><td>8</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4374305</td><td>&quot;2019-11-25T13:31:08.565352Z&quot;</td><td>&quot;2019-11-25T13:31:08.553691900Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 464774, MdEntryPx: 129.359375, MdEntrySize: 1816, NumberOfOrders: 105, MdPriceLevel: 2, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784119686, MdOrderPriority: 12365190692, MdDisplayQty: 8 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784119686, MdDisplayQty: 8, MdOrderPriority: 12365190692, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 50 }, ReferenceId: 1, LastQty: 0 }</td></tr></tbody></table>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\n",
"//display(exchange_orders.Skip(20000).Take(100));\n",
"display(exchange_orders.Where(x => x.OrderId == 846784119686).Select(x => new Display.MBODisplay(x)));"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//display(fill_model.my_orders.Count());\n",
"//display(fill_model.my_orders.Skip(0).Take(300).Select(x => new Display.OrderDisplay(x)));"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"\n",
"//var passive_fills = compute_fills<HistoryRow>(fill_model, h0f, 50_000);"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"//var passive_fills_local = passive_fills.ToArray();"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"//var qty = passive_fills_local.Sum( x=> (int)x.size);\n",
"//display(qty);\n",
"//display(passive_fills_local.Take(500).Select(x => new Display.FillDisplay(x)));"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"var h0trades = h0f.Where(x => x.Trade != null && x.sending_time > new DateTime(2019, 11, 25, 13, 30, 0 , 0));\n",
"var spdtrades = spdf.Where(x => x.Trade != null && x.sending_time > new DateTime(2019, 11, 25, 13, 30, 0 , 0));"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//display(h0trades.Take(1000));\n",
"var buy_spread = spdtrades.Where(x => (int)x.Trade.AggressorSide == 1).Sum(x => x.Trade.Size);\n",
"var sell_spread = spdtrades.Where(x => (int)x.Trade.AggressorSide == 2).Sum(x => x.Trade.Size);\n",
"var neither_spread = spdtrades.Where(x => (int)x.Trade.AggressorSide == 0).Sum(x => x.Trade.Size);"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"808923"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"544367"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"0"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(buy_spread);\n",
"display(sell_spread);\n",
"display(neither_spread);"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"544367"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": []
},
{
"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
}
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {
"scrolled": true
},
@@ -44,7 +44,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {
"scrolled": true
},
@@ -72,7 +72,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"metadata": {
"scrolled": true
},
@@ -83,7 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@@ -96,16 +96,16 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 13, 30, 0), DateTimeKind.Utc);\n",
"//var end = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 14, 0, 0), DateTimeKind.Utc);\n",
"var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 0, 0, 0), DateTimeKind.Utc);\n",
"var end = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 23, 59, 59), DateTimeKind.Utc);\n",
"var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 14, 0, 0), DateTimeKind.Utc); //9am east\n",
"var end = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 23, 0, 0), DateTimeKind.Utc); //6pm east\n",
"//var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 0, 0, 0), DateTimeKind.Utc);\n",
"//var end = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 23, 59, 59), DateTimeKind.Utc);\n",
"\n",
"var z9t = q.timeseries_cached<HistoryRow>(z9, begin, end);\n",
"var h0t = q.timeseries_cached<HistoryRow>(h0, begin, end);\n",
@@ -121,7 +121,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 19,
"metadata": {
"scrolled": true
},
@@ -129,7 +129,7 @@
{
"data": {
"text/html": [
"103398"
"1736137"
]
},
"metadata": {},
@@ -138,7 +138,7 @@
{
"data": {
"text/html": [
"63197"
"955981"
]
},
"metadata": {},
@@ -147,7 +147,7 @@
{
"data": {
"text/html": [
"31323"
"823320"
]
},
"metadata": {},
@@ -181,7 +181,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 20,
"metadata": {
"scrolled": true
},
@@ -213,7 +213,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
@@ -224,7 +224,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 31,
"metadata": {
"scrolled": true
},
@@ -232,7 +232,7 @@
{
"data": {
"text/html": [
"2"
"100"
]
},
"metadata": {},
@@ -241,7 +241,7 @@
{
"data": {
"text/html": [
"2"
"35"
]
},
"metadata": {},
@@ -250,7 +250,7 @@
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>order</th><th>fill</th></tr></thead><tbody><tr><td>0</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000001, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:00.654558700Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:00.654508700Z&quot;, our_order_side: Sell, our_order_status: Working, our_order_price: 129.40625, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>1</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000002, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:00.654558700Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:00.654508700Z&quot;, our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>2</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000001, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:15.423407500Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:15.423357500Z&quot;, our_order_side: Sell, our_order_status: Working, our_order_price: 129.390625, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>3</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000002, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:15.423407500Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:15.423357500Z&quot;, our_order_side: Buy, our_order_status: Working, our_order_price: 129.34375, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>4</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000001, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:15.432881500Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:15.432831500Z&quot;, our_order_side: Sell, our_order_status: Working, our_order_price: 129.40625, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>5</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000002, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:15.432881500Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:15.432831500Z&quot;, our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>6</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000001, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.553445200Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.553395200Z&quot;, our_order_side: Sell, our_order_status: Working, our_order_price: 129.421875, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>7</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000002, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.554332600Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.554282600Z&quot;, our_order_side: Buy, our_order_status: Working, our_order_price: 129.375, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>8</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000001, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.575899900Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.575849900Z&quot;, our_order_side: Sell, our_order_status: Working, our_order_price: 129.40625, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>9</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000002, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.575899900Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.575849900Z&quot;, our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>10</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000001, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.633398700Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.633348700Z&quot;, our_order_side: Sell, our_order_status: Working, our_order_price: 129.421875, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>11</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000002, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.633398700Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.633348700Z&quot;, our_order_side: Buy, our_order_status: Working, our_order_price: 129.375, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>12</td><td>{ Submission#10+Display2+OrderDisplay: order_id: 1000001, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.638645400Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.638595400Z&quot;, our_order_side: Sell, our_order_status: Working, our_order_price: 129.40625, our_order_size: 10, our_oLine truncated
"<table><thead><tr><th><i>index</i></th><th>order</th><th>fill</th></tr></thead><tbody><tr><td>0</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.777871200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.777821200Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.777871200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.777821200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>2</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.787706300Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.787656300Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.788590500Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.788540500Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>4</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789026900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.788976900Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789026900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.788976900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>6</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789093800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.789043800Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789321200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.789271200Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>8</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.790255800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.790205800Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.790255800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.790205800Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>10</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773164900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773114900Z&quot;, order_side: Sell, order_status: Working, order_price: 129.5, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>11</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773164900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773114900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.453125, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773510Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773460Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>13</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773715700Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773665700Z&quot;, order_side: Buy, order_status: Working, order_price: 129.453125, order_size: 10, order_filled: 0 }</td><td>&lt;nullLine truncated
]
},
"metadata": {},
@@ -258,92 +258,10 @@
}
],
"source": [
" public class Display2\n",
" {\n",
" OrderOrFill _res;\n",
" public OrderDisplay order;\n",
" public FillDisplay fill;\n",
" public Display2(OrderOrFill res)\n",
" {\n",
" _res = res;\n",
" if (res.order != null)\n",
" order = new OrderDisplay(res);\n",
" else if (res.fill != null)\n",
" fill = new FillDisplay(res);\n",
" }\n",
" public Display2(OrderStatus res)\n",
" {\n",
" order = new OrderDisplay(res);\n",
" }\n",
" public Display2(FillEntry res)\n",
" {\n",
" fill = new FillDisplay(res);\n",
" }\n",
" public class OrderDisplay\n",
" {\n",
" OrderOrFill _res;\n",
" public OrderDisplay(OrderOrFill res) { _res = res; }\n",
" public OrderDisplay(OrderStatus res) { _res = new OrderOrFill(res); }\n",
" public ulong? order_id => _res.order?.order.order_id;\n",
" public string security_desc => _res.order?.order.security_desc;\n",
" public string our_order_sendingtime => _res.order?.SendingTime.ToString();\n",
" public string our_order_transacttime => _res.order?.TransactTime.ToString();\n",
" public string our_order_side => _res.order?.side.ToString();\n",
" public string our_order_status => _res.order?.state.Status.ToString();\n",
" public double? our_order_price => _res.order?.state.Price;\n",
" public uint? our_order_size => _res.order?.state.Quantity;\n",
" public uint? our_order_filled => _res.order?.state.FilledQuantity;\n",
" }\n",
" public class FillDisplay\n",
" {\n",
" OrderOrFill _res;\n",
" public FillDisplay(OrderOrFill res) { _res = res; }\n",
" public FillDisplay(FillEntry res) { _res = new OrderOrFill(res); }\n",
" public string our_fill_sending_time => _res.fill?.SendingTime.ToString();\n",
" public string our_fill_transact_time => _res.fill?.TransactTime.ToString(); \n",
" public ulong? order_id => _res.fill?.order.order_id;\n",
" public string security_desc => _res.fill?.order.security_desc;\n",
" public string our_fill_side => _res.fill?.side.ToString();\n",
" public double? our_fill_price => _res.fill?.price;\n",
" public ulong? our_fill_size => _res.fill?.size;\n",
" public ulong? fill_id => _res.fill?.fill_id;\n",
" public uint? total_traded => _res.fill?.total_traded;\n",
" public uint? num_orders => _res.fill?.num_orders;\n",
" public string tag => _res.fill?.tag;\n",
"\n",
" public double? best_bid => _res.fill?.bid;\n",
" public double? best_ask => _res.fill?.ask;\n",
" }\n",
" public class MBODisplay\n",
" {\n",
" MBOMessage _res;\n",
" public MBODisplay(MBOMessage res)\n",
" {\n",
" _res = res;\n",
" }\n",
" public string OrderUpdateAction => _res.OrderUpdateAction.ToString();\n",
" public ulong OrderId => _res.OrderId;\n",
" public string SecurityDesc => _res.SecurityDesc;\n",
" public ulong MdOrderPriority => _res.MdOrderPriority;\n",
" public double MdEntryPx => _res.MdEntryPx;\n",
" public uint MdPriceLevel => _res.MdPriceLevel;\n",
" public ulong MdDisplayQty => _res.MdDisplayQty;\n",
" public uint LastQty => _res.LastQty;\n",
" public string MdEntryType => _res.MdEntryType.ToString();\n",
" public string TradeDate => _res.TradeDate.ToString();\n",
" public uint MsgSeqNum => _res.MsgSeqNum;\n",
" public string SendingTime => _res.SendingTime.ToString();\n",
" public string TransactTime => _res.TransactTime.ToString();\n",
"\n",
" public MDEntry MdEntry => _res.MdEntry;\n",
" public OrderIDEntry OrderEntry => _res.OrderEntry;\n",
"\n",
" } \n",
" }\n",
"\n",
"display(algo_orders_cached.Where(x => x.fill != null).Sum(x => (int)x.fill.size) / 3.0);\n",
"display(algo_orders_cached.Where(x => x.fill != null).Count() / 3.0);\n",
"display(algo_orders_cached.Select(x => new Display2(x)).Take(1000));"
"display(algo_orders_cached.Select(x => new Display(x)).Take(1000));"
]
},
{
@@ -355,7 +273,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
@@ -364,7 +282,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 24,
"metadata": {},
"outputs": [
{
@@ -385,7 +303,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 25,
"metadata": {
"scrolled": true
},
@@ -404,7 +322,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
@@ -414,7 +332,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
@@ -423,7 +341,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
@@ -434,30 +352,64 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"var h0trades = h0f.Where(x => x.Trade != null && x.sending_time > new DateTime(2019, 11, 25, 13, 30, 0 , 0));"
"var h0trades = h0f.Where(x => x.Trade != null && x.sending_time > new DateTime(2019, 11, 25, 13, 30, 0 , 0));\n",
"var spdtrades = spdf.Where(x => x.Trade != null && x.sending_time > new DateTime(2019, 11, 25, 13, 30, 0 , 0));"
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 19,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//display(h0trades.Take(1000));"
"//display(h0trades.Take(1000));\n",
"var buy_spread = spdtrades.Where(x => (int)x.Trade.AggressorSide == 1).Sum(x => x.Trade.Size);\n",
"var sell_spread = spdtrades.Where(x => (int)x.Trade.AggressorSide == 2).Sum(x => x.Trade.Size);"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"text/html": [
"808923"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(buy_spread);"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"544367"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(sell_spread);"
]
},
{
"cell_type": "code",
@@ -1,307 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 19,
"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": 20,
"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": 21,
"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": 22,
"metadata": {},
"outputs": [],
"source": [
"var f = q.collection<HistoryRow>(\"CLF0-CLJ0\");\n",
"var j = q.collection<HistoryRow>(\"CLJ0-CLM0\");\n",
"var m = q.collection<HistoryRow>(\"CLF0-CLM0\");\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": 24,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var ft = q.timeseries<HistoryRow>(f, new DateTime(2019, 11, 19, 0, 0, 0), new DateTime(2019, 11, 21, 23, 59, 59));\n",
"var jt = q.timeseries<HistoryRow>(j, new DateTime(2019, 11, 19, 0, 0, 0), new DateTime(2019, 11, 21, 23, 59, 59));\n",
"var mt = q.timeseries<HistoryRow>(m, new DateTime(2019, 11, 19, 0, 0, 0), new DateTime(2019, 11, 21, 23, 59, 59));\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": 13,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"317961"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"402409"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"438568"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(ft.Count());\n",
"display(jt.Count());\n",
"display(mt.Count());\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var ff = ft.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"var jf = jt.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"var mf = mt.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"\n",
"var ftop = ff.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var jtop = jf.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var mtop = mf.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"\n",
"//display(h0f.Take(1));\n",
"//display(z9f.Take(1));"
]
},
{
"cell_type": "code",
"execution_count": 26,
"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 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": 27,
"metadata": {},
"outputs": [],
"source": [
"\n",
"var synth = create_synthetic_top( new []{ftop, jtop, mtop}, 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": 28,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>seq_num</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>77608908</td><td>2019-11-19 23:00:00.200092</td><td>2019-11-19 23:00:00.010916</td><td>0</td><td>140</td><td>9</td><td>1</td><td>77608433 1 69.00 |77608393 88 71.00 |77608908 4 141.00 |</td><td>77608433 1 77.00 |77608393 82 73.00 |77608908 0 0.00 |</td></tr><tr><td>1</td><td>77608909</td><td>2019-11-19 23:00:00.200105</td><td>2019-11-19 23:00:00.010918</td><td>0</td><td>140</td><td>9</td><td>1</td><td>77608433 1 69.00 |77608393 88 71.00 |77608909 4 141.00 |</td><td>77608433 1 77.00 |77608393 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>2</td><td>77609069</td><td>2019-11-19 23:00:00.202060</td><td>2019-11-19 23:00:00.016665</td><td>0</td><td>140</td><td>9</td><td>1</td><td>77608433 1 69.00 |77609069 88 71.00 |77608909 4 141.00 |</td><td>77608433 1 77.00 |77609069 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>3</td><td>77609070</td><td>2019-11-19 23:00:00.202068</td><td>2019-11-19 23:00:00.016666</td><td>0</td><td>140</td><td>9</td><td>1</td><td>77608433 1 69.00 |77609070 89 71.00 |77608909 4 141.00 |</td><td>77608433 1 77.00 |77609070 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>4</td><td>77609115</td><td>2019-11-19 23:00:00.202598</td><td>2019-11-19 23:00:00.017703</td><td>0</td><td>140</td><td>9</td><td>1</td><td>77608433 1 69.00 |77609115 89 71.00 |77608909 4 141.00 |</td><td>77608433 1 77.00 |77609115 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>5</td><td>77609123</td><td>2019-11-19 23:00:00.202678</td><td>2019-11-19 23:00:00.017813</td><td>0</td><td>141</td><td>9</td><td>1</td><td>77609123 2 70.00 |77609115 89 71.00 |77608909 4 141.00 |</td><td>77609123 1 77.00 |77609115 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>6</td><td>77609124</td><td>2019-11-19 23:00:00.202687</td><td>2019-11-19 23:00:00.017813</td><td>0</td><td>141</td><td>9</td><td>4</td><td>77609124 2 70.00 |77609115 89 71.00 |77608909 4 141.00 |</td><td>77609124 4 77.00 |77609115 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>7</td><td>77609369</td><td>2019-11-19 23:00:00.205493</td><td>2019-11-19 23:00:00.020957</td><td>0</td><td>142</td><td>9</td><td>4</td><td>77609369 3 71.00 |77609115 89 71.00 |77608909 4 141.00 |</td><td>77609369 4 77.00 |77609115 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>8</td><td>77609370</td><td>2019-11-19 23:00:00.205506</td><td>2019-11-19 23:00:00.020959</td><td>0</td><td>142</td><td>6</td><td>3</td><td>77609370 3 71.00 |77609115 89 71.00 |77608909 4 141.00 |</td><td>77609370 3 74.00 |77609115 82 73.00 |77608909 0 0.00 |</td></tr><tr><td>9</td><td>77609460</td><td>2019-11-19 23:00:00.206467</td><td>2019-11-19 23:00:00.021838</td><td>0</td><td>142</td><td>5</td><td>3</td><td>77609370 3 71.00 |77609115 89 71.00 |77609460 3 142.00 |</td><td>77609370 3 74.00 |77609115 82 73.00 |77609460 0 0.00 |</td></tr><tr><td>10</td><td>127750158</td><td>2019-11-20 22:47:47.470815</td><td>2019-11-20 22:47:47.470477</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750158 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750158 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>11</td><td>127750159</td><td>2019-11-20 22:47:47.470854</td><td>2019-11-20 22:47:47.470478</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750159 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750159 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>12</td><td>127750160</td><td>2019-11-20 22:47:47.470864</td><td>2019-11-20 22:47:47.470479</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750160 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750160 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>13</td><td>127750161</td><td>2019-11-20 22:47:47.470875</td><td>2019-11-20 22:47:47.470480</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750161 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750161 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>14</td><td>127750162</td><td>2019-11-20 22:47:47.470885</td><td>2019-11-20 22:47:47.470481</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750162 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750162 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>15</td><td>127750163</td><td>2019-11-20 22:47:47.470900</td><td>2019-11-20 22:47:47.470483</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750163 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750163 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>16</td><td>127750164</td><td>2019-11-20 22:47:47.470909</td><td>2019-11-20 22:47:47.470484</td><td>42</td><td>5</td><td>10</td><td>14</td><td>85514251 42 71.00 |127750164 85 82.00 |85514263 44 146.00 |</td><td>85514251 14 72.00 |127750164 45 84.00 |85514263 72 148.00 |</td></tr><tr><td>17</td><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.Take(5000).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
}
@@ -1,344 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"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": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"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": 3,
"metadata": {},
"outputs": [
{
"ename": "Unhandled Exception",
"evalue": "Could not load file or assembly 'protobuf-net, Version=2.3.2.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67'. The system cannot find the file specified.",
"output_type": "error",
"traceback": [
"Unhandled Exception",
"Could not load file or assembly 'protobuf-net, Version=2.3.2.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67'. The system cannot find the file specified.",
" at mbts.config.Configuration.get[T]()",
" at bts.history.Query..ctor(String database, String host, Int32 port, String user, String pass) in c:\\code\\bts\\spark\\src\\client\\spark_historical\\Query\\Query.cs:line 30",
" at Submission#4.<<Initialize>>d__0.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
" at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)"
]
}
],
"source": [
"var q = new Query(\"oil_11_20\", \"bigblue\");\n",
"//Timestamp ts = new Timestamp();\n",
"//ts.Seconds = 15;\n",
"//DateTime dt = ts.ToDateTime();\n",
"//display(dt.Kind);"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"ename": "Unhandled Exception",
"evalue": "Object reference not set to an instance of an object.",
"output_type": "error",
"traceback": [
"Unhandled Exception",
"Object reference not set to an instance of an object.",
" at Submission#5.<<Initialize>>d__0.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
" at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)"
]
}
],
"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": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"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": 6,
"metadata": {},
"outputs": [
{
"ename": "Unhandled Exception",
"evalue": "Object reference not set to an instance of an object.",
"output_type": "error",
"traceback": [
"Unhandled Exception",
"Object reference not set to an instance of an object.",
" at Submission#7.<<Initialize>>d__0.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
" at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)"
]
}
],
"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": 7,
"metadata": {},
"outputs": [
{
"ename": "Unhandled Exception",
"evalue": "Value cannot be null. (Parameter 'source')",
"output_type": "error",
"traceback": [
"Unhandled Exception",
"Value cannot be null. (Parameter 'source')",
" at System.Linq.Queryable.Count[TSource](IQueryable`1 source)",
" at Submission#8.<<Initialize>>d__0.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
" at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)"
]
}
],
"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": 8,
"metadata": {},
"outputs": [
{
"ename": "Unhandled Exception",
"evalue": "Value cannot be null. (Parameter 'source')",
"output_type": "error",
"traceback": [
"Unhandled Exception",
"Value cannot be null. (Parameter 'source')",
" at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)",
" at MongoDB.Driver.Linq.MongoQueryable.Where[TSource](IMongoQueryable`1 source, Expression`1 predicate)",
" at Submission#9.<<Initialize>>d__0.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
" at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)"
]
}
],
"source": [
"var c1f = c1t.Where(x => x.Book != null && x.Trade == null && (x.Book.Bids.Count > 0 || x.Book.Asks.Count > 0));\n",
"var c2f = c2t.Where(x => x.Book != null && x.Trade == null && (x.Book.Bids.Count > 0 || x.Book.Asks.Count > 0));\n",
"var c3f = c3t.Where(x => x.Book != null && x.Trade == 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": 9,
"metadata": {},
"outputs": [
{
"ename": "Unhandled Exception",
"evalue": "(10,34): error CS1061: 'T' does not contain a definition for 'MsgSeqNum' and no accessible extension method 'MsgSeqNum' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)\r\n(11,39): error CS1061: 'T' does not contain a definition for 'trade_date' and no accessible extension method 'trade_date' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)\r\n(12,41): error CS1061: 'T' does not contain a definition for 'sending_time' and no accessible extension method 'sending_time' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)\r\n(13,42): error CS1061: 'T' does not contain a definition for 'transact_time' and no accessible extension method 'transact_time' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)\r\n(19,51): error CS1061: 'T' does not contain a definition for 'MsgSeqNum' and no accessible extension method 'MsgSeqNum' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)\r\n(21,51): error CS1061: 'T' does not contain a definition for 'MsgSeqNum' and no accessible extension method 'MsgSeqNum' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)",
"output_type": "error",
"traceback": [
"(10,34): error CS1061: 'T' does not contain a definition for 'MsgSeqNum' and no accessible extension method 'MsgSeqNum' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)\r\n(11,39): error CS1061: 'T' does not contain a definition for 'trade_date' and no accessible extension method 'trade_date' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)\r\n(12,41): error CS1061: 'T' does not contain a definition for 'sending_time' and no accessible extension method 'sending_time' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)\r\n(13,42): error CS1061: 'T' does not contain a definition for 'transact_time' and no accessible extension method 'transact_time' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)\r\n(19,51): error CS1061: 'T' does not contain a definition for 'MsgSeqNum' and no accessible extension method 'MsgSeqNum' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)\r\n(21,51): error CS1061: 'T' does not contain a definition for 'MsgSeqNum' and no accessible extension method 'MsgSeqNum' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)"
]
}
],
"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": 10,
"metadata": {},
"outputs": [
{
"ename": "Unhandled Exception",
"evalue": "(4,55): error CS0246: The type or namespace name 'TopReport<>' could not be found (are you missing a using directive or an assembly reference?)",
"output_type": "error",
"traceback": [
"(4,55): error CS0246: The type or namespace name 'TopReport<>' could not be found (are you missing a using directive or an assembly reference?)"
]
}
],
"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": 11,
"metadata": {},
"outputs": [
{
"ename": "Unhandled Exception",
"evalue": "(1,9): error CS0103: The name 'synth' does not exist in the current context",
"output_type": "error",
"traceback": [
"(1,9): error CS0103: The name 'synth' does not exist in the current context"
]
}
],
"source": [
"display(synth.OrderBy(x => x.sending_time));\n"
]
},
{
"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
}
@@ -1,289 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"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": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"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": 3,
"metadata": {},
"outputs": [],
"source": [
"var q = new Query(\"oil_12_4_2019\", \"bigblue\");\n",
"//Timestamp ts = new Timestamp();\n",
"//ts.Seconds = 15;\n",
"//DateTime dt = ts.ToDateTime();\n",
"//display(dt.Kind);"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"var f = q.collection<HistoryRow>(\"CLH0-CLM0\");\n",
"var j = q.collection<HistoryRow>(\"CLM0-CLZ0\");\n",
"var m = q.collection<HistoryRow>(\"CLH0-CLZ0\");\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"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": 6,
"metadata": {},
"outputs": [],
"source": [
"var start = new DateTime(2019, 12, 4, 0, 0, 0);\n",
"var end = new DateTime(2019, 12, 5, 23, 59, 59);\n",
"var ft = q.timeseries<HistoryRow>(f, start, end);\n",
"var jt = q.timeseries<HistoryRow>(j, start, end);\n",
"var mt = q.timeseries<HistoryRow>(m,start, 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": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"545413"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"705878"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"548884"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(ft.Count());\n",
"display(jt.Count());\n",
"display(mt.Count());\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"var ff = ft.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"var jf = jt.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"var mf = mt.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"\n",
"var ftop = ff.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var jtop = jf.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var mtop = mf.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"\n",
"//display(h0f.Take(1));\n",
"//display(z9f.Take(1));"
]
},
{
"cell_type": "code",
"execution_count": 9,
"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 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": 10,
"metadata": {},
"outputs": [],
"source": [
"\n",
"var synth = create_synthetic_top( new []{ftop, jtop, mtop}, 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": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>seq_num</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>125079130</td><td>2019-12-04 16:38:53.314544</td><td>2019-12-04 16:38:53.313920</td><td>17</td><td>-3</td><td>-1</td><td>15</td><td>125078783 195 117.00 |125078780 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125078780 15 207.00 |125079130 17 326.00 |</td></tr><tr><td>1</td><td>125079130</td><td>2019-12-04 16:38:53.314544</td><td>2019-12-04 16:38:53.313920</td><td>17</td><td>-3</td><td>-1</td><td>15</td><td>125078783 195 117.00 |125078780 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125078780 15 207.00 |125079130 17 326.00 |</td></tr><tr><td>2</td><td>125079130</td><td>2019-12-04 16:38:53.314544</td><td>2019-12-04 16:38:53.313920</td><td>17</td><td>-3</td><td>-1</td><td>15</td><td>125078783 195 117.00 |125078780 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125078780 15 207.00 |125079130 17 326.00 |</td></tr><tr><td>3</td><td>125079130</td><td>2019-12-04 16:38:53.314544</td><td>2019-12-04 16:38:53.313920</td><td>24</td><td>-4</td><td>-1</td><td>15</td><td>125078783 195 117.00 |125078780 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125078780 15 207.00 |125079130 24 327.00 |</td></tr><tr><td>4</td><td>125079130</td><td>2019-12-04 16:38:53.314544</td><td>2019-12-04 16:38:53.313920</td><td>24</td><td>-4</td><td>-1</td><td>15</td><td>125078783 195 117.00 |125078780 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125078780 15 207.00 |125079130 24 327.00 |</td></tr><tr><td>5</td><td>125079133</td><td>2019-12-04 16:38:53.314690</td><td>2019-12-04 16:38:53.314367</td><td>24</td><td>-4</td><td>-1</td><td>15</td><td>125078783 195 117.00 |125079133 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125079133 15 207.00 |125079130 24 327.00 |</td></tr><tr><td>6</td><td>125079134</td><td>2019-12-04 16:38:53.314776</td><td>2019-12-04 16:38:53.314367</td><td>24</td><td>-4</td><td>-1</td><td>14</td><td>125078783 195 117.00 |125079134 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125079134 14 207.00 |125079130 24 327.00 |</td></tr><tr><td>7</td><td>125079134</td><td>2019-12-04 16:38:53.314776</td><td>2019-12-04 16:38:53.314401</td><td>24</td><td>-4</td><td>-1</td><td>14</td><td>125078783 195 117.00 |125079134 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125079134 14 207.00 |125079130 24 327.00 |</td></tr><tr><td>8</td><td>125079134</td><td>2019-12-04 16:38:53.314776</td><td>2019-12-04 16:38:53.314401</td><td>24</td><td>-4</td><td>-1</td><td>12</td><td>125078783 195 117.00 |125079134 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125079134 12 207.00 |125079130 24 327.00 |</td></tr><tr><td>9</td><td>125079135</td><td>2019-12-04 16:38:53.314875</td><td>2019-12-04 16:38:53.314410</td><td>24</td><td>-4</td><td>-1</td><td>12</td><td>125078783 195 117.00 |125079135 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125079135 12 207.00 |125079130 24 327.00 |</td></tr><tr><td>10</td><td>125079135</td><td>2019-12-04 16:38:53.314875</td><td>2019-12-04 16:38:53.314410</td><td>24</td><td>-4</td><td>-1</td><td>11</td><td>125078783 195 117.00 |125079135 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125079135 11 207.00 |125079130 24 327.00 |</td></tr><tr><td>11</td><td>125079155</td><td>2019-12-04 16:38:53.315284</td><td>2019-12-04 16:38:53.314515</td><td>24</td><td>-4</td><td>-1</td><td>11</td><td>125078783 195 117.00 |125079155 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125079155 11 207.00 |125079130 24 327.00 |</td></tr><tr><td>12</td><td>125079156</td><td>2019-12-04 16:38:53.315308</td><td>2019-12-04 16:38:53.314515</td><td>24</td><td>-4</td><td>-1</td><td>6</td><td>125078783 195 117.00 |125079156 71 206.00 |125079130 35 326.00 |</td><td>125078783 47 118.00 |125079156 6 207.00 |125079130 24 327.00 |</td></tr><tr><td>13</td><td>125079164</td><td>2019-12-04 16:38:53.315434</td><td>2019-12-04 16:38:53.314520</td><td>24</td><td>-4</td><td>-1</td><td>6</td><td>125079164 195 117.00 |125079156 71 206.00 |125079130 35 326.00 |</td><td>125079164 47 118.00 |125079156 6 207.00 |125079130 24 327.00 |</td></tr><tr><td>14</td><td>125079165</td><td>2019-12-04 16:38:53.315444</td><td>2019-12-04 16:38:53.314520</td><td>24</td><td>-4</td><td>-1</td><td>6</td><td>125079165 195 117.00 |125079156 71 206.00 |125079130 35 326.00 |</td><td>125079165 42 118.00 |125079156 6 207.00 |125079130 24 327.00 |</td></tr><tr><td>15</td><td>125079200</td><td>2019-12-04 16:38:53.315936</td><td>2019-12-04 16:38:53.314590</td><td>24</td><td>-4</td><td>-1</td><td>6</td><td>125079165 195 117.00 |125079156 71 206.00 |125079200 35 326.00 |</td><td>125079165 42 118.00 |125079156 6 207.00 |125079200 24 327.00 |</td></tr><tr><td>16</td><td>125079201</td><td>2019-12-04 16: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.Take(15000).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,475 @@
{
"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.dllInvalid: Command: #r C:/Users/darby/.nuget/packages/protobuf-net/2.3.2/lib/netstandard1.3/protobuf-net.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\"\n",
"//#r \"nuget:protobuf-net, 2.3.2.0\"\n",
"#r \"C:/Users/darby/.nuget/packages/protobuf-net/2.3.2/lib/netstandard1.3/protobuf-net.dll\" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"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 MathNet.Numerics.Statistics;\n",
"using mbts.co2;\n",
"\n",
"bts.BTS.init();\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var q = new Query(\"ZN_201911_W4\", \"bigblue\");"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"var z9 = q.collection<HistoryRow>(\"ZNZ9\");\n",
"var h0 = q.collection<HistoryRow>(\"ZNH0\");\n",
"var spd = q.collection<HistoryRow>(\"ZNZ9-ZNH0\");\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 14, 0, 0), DateTimeKind.Utc); //9am east\n",
"var end = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 23, 0, 0), DateTimeKind.Utc); //6pm east\n",
"//var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 0, 0, 0), DateTimeKind.Utc);\n",
"//var end = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 23, 59, 59), DateTimeKind.Utc);\n",
"\n",
"var z9t = q.timeseries_cached<HistoryRow>(z9, begin, end);\n",
"var h0t = q.timeseries_cached<HistoryRow>(h0, begin, end);\n",
"var spdt = q.timeseries_cached<HistoryRow>(spd, begin, end);\n",
"\n",
"await Task.WhenAll(new[] {z9t, h0t, spdt} );\n",
"\n",
"//local copy so we don't beat up the database\n",
"var z9f = await z9t;\n",
"var h0f = await h0t;\n",
"var spdf = await spdt;"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"919548"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"479145"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"536630"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(z9f.Count()); display(h0f.Count()); display(spdf.Count());"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//quotes the last leg\n",
"var algo_type = typeof(PegCoverLean);\n",
"\n",
"var latency_in = 50_000u;\n",
"var latency_out = 50_000u;\n",
"var latency_iceberg = 60_000u;\n",
"var incoming_latency = new Bucket(latency_in, latency_in+1);\n",
"var outgoing_latency = new Bucket(latency_out, latency_out+1);\n",
"var sink = new LatencyOrderSink(incoming_latency, outgoing_latency);\n",
"var fill_model = new KFillModel(outgoing_latency, false, 0.20, 1u, true);\n",
"\n",
"var security_list = new [] {\"ZNZ9-ZNH0\"};\n",
"var algo_params = \"size=10;tick_size=0.015625,0.0078125,0.015625;hedge_factors=1,-1,-1;profit_ticks=0.0078125\";\n",
"var algo_orders = algo_results<HistoryRow>(sink, fill_model, \n",
" algo_type, algo_params, \n",
" bts.api.Side.Undefined, 0.0, 10, \n",
" security_list, //must match below\n",
" new[] {spdf}, latency_iceberg);"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"ename": "Unhandled Exception",
"evalue": "An item with the same key has already been added. Key: 846782689978",
"output_type": "error",
"traceback": [
"Unhandled Exception",
"An item with the same key has already been added. Key: 846782689978",
" at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)",
" at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](List`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)",
" at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)",
" at bts.history.KFillModel.validate_matches(IEnumerable`1 orders, List`1 matches) in c:\\code\\bts\\spark\\src\\client\\spark_historical\\FillModel\\KFillModel.cs:line 244",
" at bts.history.KFillModel.process_trade(Timestamp transact_time, String security_desc, TradeMessage trade_summary, IEnumerable`1 orders) in c:\\code\\bts\\spark\\src\\client\\spark_historical\\FillModel\\KFillModel.cs:line 169",
" at bts.history.Query.<>c__DisplayClass16_0`1.<algo_results>b__3(T[] valcache, Int32 min) in c:\\code\\bts\\spark\\src\\client\\spark_historical\\Query\\Query.cs:line 280",
" at bts.history.Query.stream_data[T,U](IEnumerable`1[] datastream, Func`3 function)+MoveNext() in c:\\code\\bts\\spark\\src\\client\\spark_historical\\Query\\Query.cs:line 133",
" at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)",
" at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)",
" at Submission#10.<<Initialize>>d__0.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
" at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)"
]
}
],
"source": [
"var algo_orders_cached = algo_orders.ToArray().OrderBy(x => x.order?.TransactTime ?? x.fill.TransactTime, \n",
" HistoricalExtensions.timestamp_comparer);\n",
"//var first_pass_fills = algo_orders.Where(x => x.fill != null).Select(x => x.fill);"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"100"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"35"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>order</th><th>fill</th></tr></thead><tbody><tr><td>0</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.777871200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.777821200Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.777871200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.777821200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>2</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.787706300Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.787656300Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.788590500Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.788540500Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>4</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789026900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.788976900Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789026900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.788976900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>6</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789093800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.789043800Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789321200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.789271200Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>8</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.790255800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.790205800Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.790255800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.790205800Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>10</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773164900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773114900Z&quot;, order_side: Sell, order_status: Working, order_price: 129.5, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>11</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773164900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773114900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.453125, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773510Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773460Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>13</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773715700Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773665700Z&quot;, order_side: Buy, order_status: Working, order_price: 129.453125, order_size: 10, order_filled: 0 }</td><td>&lt;nullLine truncated
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\n",
"display(algo_orders_cached.Where(x => x.fill != null).Sum(x => (int)x.fill.size) / 3.0);\n",
"display(algo_orders_cached.Where(x => x.fill != null).Count() / 3.0);\n",
"display(algo_orders_cached.Select(x => new Display(x)).Take(1000));"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"var exchange_orders = exchange_orders<HistoryRow>(h0f);"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>OrderUpdateAction</th><th>OrderId</th><th>SecurityDesc</th><th>MdOrderPriority</th><th>MdEntryPx</th><th>MdPriceLevel</th><th>MdDisplayQty</th><th>LastQty</th><th>MdEntryType</th><th>TradeDate</th><th>MsgSeqNum</th><th>SendingTime</th><th>TransactTime</th><th>MdEntry</th><th>OrderEntry</th></tr></thead><tbody><tr><td>0</td><td>New</td><td>846784119686</td><td>ZNH0</td><td>12365190692</td><td>129.359375</td><td>2</td><td>8</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4361037</td><td>&quot;2019-11-25T13:30:20.470246800Z&quot;</td><td>&quot;2019-11-25T13:30:20.470147Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 463670, MdEntryPx: 129.359375, MdEntrySize: 1590, NumberOfOrders: 105, MdPriceLevel: 2, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784119686, MdOrderPriority: 12365190692, MdDisplayQty: 8 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784119686, MdDisplayQty: 8, MdOrderPriority: 12365190692, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 48 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>1</td><td>Delete</td><td>846784119686</td><td>ZNH0</td><td>12365190692</td><td>129.359375</td><td>2</td><td>8</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4374305</td><td>&quot;2019-11-25T13:31:08.565352Z&quot;</td><td>&quot;2019-11-25T13:31:08.553691900Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 464774, MdEntryPx: 129.359375, MdEntrySize: 1816, NumberOfOrders: 105, MdPriceLevel: 2, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784119686, MdOrderPriority: 12365190692, MdDisplayQty: 8 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784119686, MdDisplayQty: 8, MdOrderPriority: 12365190692, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 50 }, ReferenceId: 1, LastQty: 0 }</td></tr></tbody></table>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\n",
"//display(exchange_orders.Skip(20000).Take(100));\n",
"display(exchange_orders.Where(x => x.OrderId == 846784119686).Select(x => new Display.MBODisplay(x)));"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//display(fill_model.my_orders.Count());\n",
"//display(fill_model.my_orders.Skip(0).Take(300).Select(x => new Display.OrderDisplay(x)));"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"\n",
"//var passive_fills = compute_fills<HistoryRow>(fill_model, h0f, 50_000);"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"//var passive_fills_local = passive_fills.ToArray();"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"//var qty = passive_fills_local.Sum( x=> (int)x.size);\n",
"//display(qty);\n",
"//display(passive_fills_local.Take(500).Select(x => new Display.FillDisplay(x)));"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"var h0trades = h0f.Where(x => x.Trade != null && x.sending_time > new DateTime(2019, 11, 25, 13, 30, 0 , 0));\n",
"var spdtrades = spdf.Where(x => x.Trade != null && x.sending_time > new DateTime(2019, 11, 25, 13, 30, 0 , 0));"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//display(h0trades.Take(1000));\n",
"var buy_spread = spdtrades.Where(x => (int)x.Trade.AggressorSide == 1).Sum(x => x.Trade.Size);\n",
"var sell_spread = spdtrades.Where(x => (int)x.Trade.AggressorSide == 2).Sum(x => x.Trade.Size);\n",
"var neither_spread = spdtrades.Where(x => (int)x.Trade.AggressorSide == 0).Sum(x => x.Trade.Size);"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"808923"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"544367"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"0"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(buy_spread);\n",
"display(sell_spread);\n",
"display(neither_spread);"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"544367"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": []
},
{
"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
}
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {
"scrolled": true
},
@@ -44,7 +44,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {
"scrolled": true
},
@@ -72,7 +72,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"metadata": {
"scrolled": true
},
@@ -83,7 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@@ -96,16 +96,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 13, 30, 0), DateTimeKind.Utc);\n",
"//var end = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 14, 0, 0), DateTimeKind.Utc);\n",
"var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 0, 0, 0), DateTimeKind.Utc);\n",
"var end = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 23, 59, 59), DateTimeKind.Utc);\n",
"var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 14, 0, 0), DateTimeKind.Utc); //9am east\n",
"var end = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 23, 0, 0), DateTimeKind.Utc); //6pm east\n",
"//var begin = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 0, 0, 0), DateTimeKind.Utc);\n",
"//var end = DateTime.SpecifyKind(new DateTime(2019, 11, 25, 23, 59, 59), DateTimeKind.Utc);\n",
"\n",
"var z9t = q.timeseries_cached<HistoryRow>(z9, begin, end);\n",
"var h0t = q.timeseries_cached<HistoryRow>(h0, begin, end);\n",
@@ -121,11 +121,39 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {
"scrolled": true
},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"1736137"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"955981"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"823320"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(z9f.Count()); display(h0f.Count()); display(spdf.Count());"
]
@@ -153,7 +181,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {
"scrolled": true
},
@@ -185,7 +213,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
@@ -196,98 +224,44 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 31,
"metadata": {
"scrolled": true
},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"100"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"35"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>order</th><th>fill</th></tr></thead><tbody><tr><td>0</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.777871200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.777821200Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.777871200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.777821200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>2</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.787706300Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.787656300Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.788590500Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.788540500Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>4</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789026900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.788976900Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789026900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.788976900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>6</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789093800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.789043800Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.789321200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.789271200Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>8</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.790255800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.790205800Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:01:10.790255800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:01:10.790205800Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>10</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000012, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773164900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773114900Z&quot;, order_side: Sell, order_status: Working, order_price: 129.5, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>11</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773164900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773114900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.453125, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773510Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773460Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 10, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>13</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000013, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T00:03:09.773715700Z&quot;, order_TRANSACT_time: &quot;2019-11-25T00:03:09.773665700Z&quot;, order_side: Buy, order_status: Working, order_price: 129.453125, order_size: 10, order_filled: 0 }</td><td>&lt;nullLine truncated
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
" public class Display2\n",
" {\n",
" OrderOrFill _res;\n",
" public OrderDisplay order;\n",
" public FillDisplay fill;\n",
" public Display2(OrderOrFill res)\n",
" {\n",
" _res = res;\n",
" if (res.order != null)\n",
" order = new OrderDisplay(res);\n",
" else if (res.fill != null)\n",
" fill = new FillDisplay(res);\n",
" }\n",
" public Display2(OrderStatus res)\n",
" {\n",
" order = new OrderDisplay(res);\n",
" }\n",
" public Display2(FillEntry res)\n",
" {\n",
" fill = new FillDisplay(res);\n",
" }\n",
" public class OrderDisplay\n",
" {\n",
" OrderOrFill _res;\n",
" public OrderDisplay(OrderOrFill res) { _res = res; }\n",
" public OrderDisplay(OrderStatus res) { _res = new OrderOrFill(res); }\n",
" public ulong? order_id => _res.order?.order.order_id;\n",
" public string security_desc => _res.order?.order.security_desc;\n",
" public string our_order_sendingtime => _res.order?.SendingTime.ToString();\n",
" public string our_order_transacttime => _res.order?.TransactTime.ToString();\n",
" public string our_order_side => _res.order?.side.ToString();\n",
" public string our_order_status => _res.order?.state.Status.ToString();\n",
" public double? our_order_price => _res.order?.state.Price;\n",
" public uint? our_order_size => _res.order?.state.Quantity;\n",
" public uint? our_order_filled => _res.order?.state.FilledQuantity;\n",
" }\n",
" public class FillDisplay\n",
" {\n",
" OrderOrFill _res;\n",
" public FillDisplay(OrderOrFill res) { _res = res; }\n",
" public FillDisplay(FillEntry res) { _res = new OrderOrFill(res); }\n",
" public string our_fill_sending_time => _res.fill?.SendingTime.ToString();\n",
" public string our_fill_transact_time => _res.fill?.TransactTime.ToString(); \n",
" public ulong? order_id => _res.fill?.order.order_id;\n",
" public string security_desc => _res.fill?.order.security_desc;\n",
" public string our_fill_side => _res.fill?.side.ToString();\n",
" public double? our_fill_price => _res.fill?.price;\n",
" public ulong? our_fill_size => _res.fill?.size;\n",
" public ulong? fill_id => _res.fill?.fill_id;\n",
" public uint? total_traded => _res.fill?.total_traded;\n",
" public uint? num_orders => _res.fill?.num_orders;\n",
" public string tag => _res.fill?.tag;\n",
"\n",
" public double? best_bid => _res.fill?.bid;\n",
" public double? best_ask => _res.fill?.ask;\n",
" }\n",
" public class MBODisplay\n",
" {\n",
" MBOMessage _res;\n",
" public MBODisplay(MBOMessage res)\n",
" {\n",
" _res = res;\n",
" }\n",
" public string OrderUpdateAction => _res.OrderUpdateAction.ToString();\n",
" public ulong OrderId => _res.OrderId;\n",
" public string SecurityDesc => _res.SecurityDesc;\n",
" public ulong MdOrderPriority => _res.MdOrderPriority;\n",
" public double MdEntryPx => _res.MdEntryPx;\n",
" public uint MdPriceLevel => _res.MdPriceLevel;\n",
" public ulong MdDisplayQty => _res.MdDisplayQty;\n",
" public uint LastQty => _res.LastQty;\n",
" public string MdEntryType => _res.MdEntryType.ToString();\n",
" public string TradeDate => _res.TradeDate.ToString();\n",
" public uint MsgSeqNum => _res.MsgSeqNum;\n",
" public string SendingTime => _res.SendingTime.ToString();\n",
" public string TransactTime => _res.TransactTime.ToString();\n",
"\n",
" public MDEntry MdEntry => _res.MdEntry;\n",
" public OrderIDEntry OrderEntry => _res.OrderEntry;\n",
"\n",
" } \n",
" }\n",
"\n",
"display(algo_orders_cached.Where(x => x.fill != null).Sum(x => (int)x.fill.size) / 3.0);\n",
"display(algo_orders_cached.Where(x => x.fill != null).Count() / 3.0);\n",
"display(algo_orders_cached.Select(x => new Display2(x)).Take(1000));"
"display(algo_orders_cached.Select(x => new Display(x)).Take(1000));"
]
},
{
@@ -299,7 +273,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
@@ -308,9 +282,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>OrderUpdateAction</th><th>OrderId</th><th>SecurityDesc</th><th>MdOrderPriority</th><th>MdEntryPx</th><th>MdPriceLevel</th><th>MdDisplayQty</th><th>LastQty</th><th>MdEntryType</th><th>TradeDate</th><th>MsgSeqNum</th><th>SendingTime</th><th>TransactTime</th><th>MdEntry</th><th>OrderEntry</th></tr></thead><tbody><tr><td>0</td><td>New</td><td>846784119686</td><td>ZNH0</td><td>12365190692</td><td>129.359375</td><td>2</td><td>8</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4361037</td><td>&quot;2019-11-25T13:30:20.470246800Z&quot;</td><td>&quot;2019-11-25T13:30:20.470147Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 463670, MdEntryPx: 129.359375, MdEntrySize: 1590, NumberOfOrders: 105, MdPriceLevel: 2, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784119686, MdOrderPriority: 12365190692, MdDisplayQty: 8 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784119686, MdDisplayQty: 8, MdOrderPriority: 12365190692, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 48 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>1</td><td>Delete</td><td>846784119686</td><td>ZNH0</td><td>12365190692</td><td>129.359375</td><td>2</td><td>8</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4374305</td><td>&quot;2019-11-25T13:31:08.565352Z&quot;</td><td>&quot;2019-11-25T13:31:08.553691900Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 464774, MdEntryPx: 129.359375, MdEntrySize: 1816, NumberOfOrders: 105, MdPriceLevel: 2, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784119686, MdOrderPriority: 12365190692, MdDisplayQty: 8 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784119686, MdDisplayQty: 8, MdOrderPriority: 12365190692, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 50 }, ReferenceId: 1, LastQty: 0 }</td></tr></tbody></table>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\n",
"//display(exchange_orders.Skip(20000).Take(100));\n",
@@ -319,7 +303,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {
"scrolled": true
},
@@ -338,7 +322,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
@@ -348,7 +332,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
@@ -357,7 +341,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
@@ -368,30 +352,64 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"var h0trades = h0f.Where(x => x.Trade != null && x.sending_time > new DateTime(2019, 11, 25, 13, 30, 0 , 0));"
"var h0trades = h0f.Where(x => x.Trade != null && x.sending_time > new DateTime(2019, 11, 25, 13, 30, 0 , 0));\n",
"var spdtrades = spdf.Where(x => x.Trade != null && x.sending_time > new DateTime(2019, 11, 25, 13, 30, 0 , 0));"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"//display(h0trades.Take(1000));"
"//display(h0trades.Take(1000));\n",
"var buy_spread = spdtrades.Where(x => (int)x.Trade.AggressorSide == 1).Sum(x => x.Trade.Size);\n",
"var sell_spread = spdtrades.Where(x => (int)x.Trade.AggressorSide == 2).Sum(x => x.Trade.Size);"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"text/html": [
"808923"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(buy_spread);"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"544367"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(sell_spread);"
]
},
{
"cell_type": "code",