taking this home
This commit is contained in:
1 parent
a9e983a717
commit
228e49d152
4 files changed
+135
-77
No files matched your search
@@ -47,7 +47,7 @@ namespace bts.history
|
||||
{
|
||||
if(_disqual.ContainsKey(stat.order.order_id))
|
||||
{
|
||||
Log.Testing.error("new status for disqualified error, not recording");
|
||||
Log.Testing.error($"new status for disqualified error, not recording");
|
||||
}
|
||||
else if(!check_cross(stat))
|
||||
{
|
||||
@@ -89,11 +89,22 @@ namespace bts.history
|
||||
var market_operations = operations.OrderBy(x => x.TransactTime, HistoricalExtensions.timestamp_comparer).ToList();
|
||||
var market_operation_index = find_first_greater_or_equal(market_operations, transact_time, x=>x.TransactTime,
|
||||
HistoricalExtensions.timestamp_comparer);
|
||||
if(market_operation_index == 0) //transact_time is before first market operation on this order, they get filled not us
|
||||
if(market_operation_index == 0) //transact_time is before first market operation we saw, on this order, they get filled not us
|
||||
return ;
|
||||
//this is the latest market operation for the filled order at the time of fill
|
||||
var curr_market_operation = market_operations[market_operation_index-1];
|
||||
//now we slide backwards to find the first operation that kept priority at the time of fill
|
||||
for (int i = market_operation_index - 2; i >= 0; i--)
|
||||
{
|
||||
if(market_operations[i].MdOrderPriority == curr_market_operation.MdOrderPriority)
|
||||
{
|
||||
curr_market_operation = market_operations[i];
|
||||
}
|
||||
}
|
||||
|
||||
Log.assert(curr_market_operation.OrderUpdateAction != MDUpdateAction.Delete); //a deleted order should not get filled
|
||||
|
||||
//now we find the first operation for our order greater or equal to the earliest market operation
|
||||
int our_operation_index = find_first_greater_or_equal(_myorders, transact_time, HistoricalExtensions.timestamp_comparer);
|
||||
if(our_operation_index == 0) //transact_time before I'm in the market, they get filled not us
|
||||
return ;
|
||||
@@ -103,39 +114,37 @@ namespace bts.history
|
||||
api.Side market_side = Utils.same_side(curr_market_operation.MdEntryType);
|
||||
List<FillEntry> fills = new List<FillEntry>();
|
||||
uint fill_qty = trade.Size;
|
||||
Dictionary<ulong, int> latest_state = new Dictionary<ulong, int>();
|
||||
for(int i = our_operation_index - 1; i >= 0; i--)
|
||||
{
|
||||
//the closest operation to this trade time
|
||||
OrderStatus curr_operation = _myorders.Values[i];
|
||||
if(!curr_operation.TransactTime.less_or_equal(curr_market_operation.TransactTime))
|
||||
{
|
||||
Log.Testing.warn("should be sorted");
|
||||
break;
|
||||
}
|
||||
if(curr_operation.order.security_desc != market_secdesc)
|
||||
continue;
|
||||
if(curr_operation.order.side != market_side)
|
||||
continue;
|
||||
if(_disqual.TryGetValue(curr_operation.order.order_id, out uint spent_value))
|
||||
if(_disqual.ContainsKey(curr_operation.order.order_id))
|
||||
continue;
|
||||
if (curr_operation.is_terminal())
|
||||
{
|
||||
_disqual[curr_operation.order.order_id] = 0; //this order is completely spent
|
||||
continue;
|
||||
}
|
||||
if(latest_state.ContainsKey(curr_operation.order.order_id)) //we have seen the latest of this order before in this search
|
||||
continue;
|
||||
latest_state[curr_operation.order.order_id] = 0;
|
||||
if (!curr_operation.TransactTime.less_or_equal(curr_market_operation.TransactTime))
|
||||
continue;
|
||||
//here we have the latest status of an order on the right side of the market for the right security and the right price
|
||||
if (( market_side == api.Side.Buy && curr_operation.state.Price >= market_price || //fill us if we are better?
|
||||
market_side == api.Side.Sell && curr_operation.state.Price <= market_price) )
|
||||
{
|
||||
//here we have an order on the right side of the market for the right security and the right price
|
||||
//if the latest state of this order is terminal, disqualify the order
|
||||
if (curr_operation.is_terminal())
|
||||
{
|
||||
_disqual[curr_operation.order.order_id] = int.MaxValue; //this order is completely spent
|
||||
continue;
|
||||
}
|
||||
uint size = Math.Min(fill_qty, curr_operation.state.Quantity - spent_value);
|
||||
{
|
||||
uint size = Math.Min(fill_qty, curr_operation.state.Quantity);
|
||||
if (size > 0)
|
||||
{
|
||||
FillEntry f = generate_fill(transact_time, curr_operation, curr_operation.state.Price, size);
|
||||
f.fill_id = trade.OrderId;
|
||||
fills.Add(f);
|
||||
if(f.fully_filled)
|
||||
_disqual[curr_operation.order.order_id] = int.MaxValue; //this order is completely spent
|
||||
fill_qty -= size;
|
||||
}
|
||||
if (fill_qty <= 0)
|
||||
@@ -199,7 +208,7 @@ namespace bts.history
|
||||
{
|
||||
var fills = check_my_cross(status);
|
||||
if (fills.Count > 0)
|
||||
return fills.Last().fully_filled;
|
||||
return fills.Any( x => x.fully_filled);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -255,7 +264,8 @@ namespace bts.history
|
||||
f.ask = book?.ask_at(0) ?? 0;
|
||||
f.asksize = book?.asksize_at(0) ?? 0;
|
||||
f.tag = tag;
|
||||
Log.assert(qty <= status.order.size && qty <= status.state.Quantity);
|
||||
if(qty > status.state.Quantity)
|
||||
throw new InvalidOperationException($"too much fill {qty} working quantity {status.state.Quantity}");
|
||||
status.state.Quantity -= qty;
|
||||
if (status.state.Quantity == 0)
|
||||
{
|
||||
@@ -271,7 +281,12 @@ namespace bts.history
|
||||
status.state.FilledQuantity += (uint)f.size;
|
||||
status.state.AvgPrice /= status.state.FilledQuantity;
|
||||
if (f.fully_filled)
|
||||
{
|
||||
status.state.Status = api.orderman.OrderStatus.Completed;
|
||||
_disqual[status.order.order_id] = int.MaxValue;
|
||||
if(string.IsNullOrEmpty(f.tag))
|
||||
f.tag = $"{f.order.order_id} FULLFILL";
|
||||
}
|
||||
if (this.on_status_due_to_fill != null)
|
||||
this.on_status_due_to_fill(status.clone());
|
||||
if (this.on_fill != null)
|
||||
|
||||
+43
-22
@@ -165,7 +165,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
@@ -179,48 +179,56 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": 34,
|
||||
"metadata": {
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"var security_list = new [] {\"ZNZ9\",\"ZNH0\"};\n",
|
||||
"//quotes the last leg\n",
|
||||
"var algo_type = typeof(Spreader);\n",
|
||||
"var algo_params = \"size=10;tick_size=0.015625,0.015625;hedge_factors=1,-1;profit_ticks=0\";\n",
|
||||
"\n",
|
||||
"var latency_ns = 150_000u;\n",
|
||||
"var transact_latency = new Bucket(latency_ns, latency_ns+1);\n",
|
||||
"var transmit_latency = new Bucket(latency_ns, latency_ns+1);\n",
|
||||
"var sink = new LatencyOrderSink(transact_latency, transmit_latency);\n",
|
||||
"var fill_model = new FIFOFillModel(transmit_latency);\n",
|
||||
"var latency_in = 50_000u;\n",
|
||||
"var latency_out = 150_000u;\n",
|
||||
"var latency_iceberg = 6_000_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 FIFOFillModel(outgoing_latency);\n",
|
||||
"\n",
|
||||
"//var security_list = new [] {\"ZNZ9\",\"ZNH0\"};\n",
|
||||
"//var algo_params = \"size=10;tick_size=0.015625,0.015625;hedge_factors=1,-1;profit_ticks=0\";\n",
|
||||
"var security_list = new [] {\"ZNZ9\",\"ZNZ9-ZNH0\", \"ZNH0\"};\n",
|
||||
"var algo_params = \"size=10;tick_size=0.015625,0.0078125,0.015625;hedge_factors=1,-1,-1;profit_ticks=1\";\n",
|
||||
"var algo_orders = algo_orders<HistoryRow>(sink, fill_model, \n",
|
||||
" algo_type, algo_params, \n",
|
||||
" bts.api.Side.Sell, -0.046875, 10, \n",
|
||||
" bts.api.Side.Undefined, 0.0, 10, \n",
|
||||
"// bts.api.Side.Sell, -0.046875, 10, \n",
|
||||
" security_list, //must match below\n",
|
||||
" new[] {z9f, h0f});"
|
||||
" new[] {z9f, spdf, h0f}, latency_iceberg);\n",
|
||||
"// new[] {z9f, h0f}, latency_iceberg);"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"execution_count": 35,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"var algo_orders_cached = algo_orders.ToArray();\n",
|
||||
"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": 16,
|
||||
"execution_count": 38,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"254"
|
||||
"60"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
@@ -229,7 +237,16 @@
|
||||
{
|
||||
"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: 1000827, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:00.045321Z", our_order_transacttime: "2019-11-25T13:30:00.045171Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000827, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.423607500Z", our_order_transacttime: "2019-11-25T13:30:15.423457500Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>2</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000827, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.433081500Z", our_order_transacttime: "2019-11-25T13:30:15.432931500Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000827, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.433081500Z", our_order_transacttime: "2019-11-25T13:30:15.432931500Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.375, our_order_size: 9, our_order_filled: 1 }</td><td><null></td></tr><tr><td>4</td><td><null></td><td>{ bts.history.Display+FillDisplay: our_fill_time: "2019-11-25T13:31:08.549788300Z", order_id: 1000827, security_desc: ZNH0, our_fill_side: Buy, our_fill_price: 129.375, our_fill_size: 1, fill_id: 846783978493, tag: <null>, best_bid: 0, best_ask: 0 }</td></tr><tr><td>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000829, security_desc: ZNZ9, our_order_sendingtime: "2019-11-25T13:31:08.550088300Z", our_order_transacttime: "2019-11-25T13:31:08.549938300Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.328125, our_order_size: 1, our_order_filled: 0 }</td><td><null></td></tr><tr><td>6</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000829, security_desc: ZNZ9, our_order_sendingtime: "2019-11-25T13:31:08.550088300Z", our_order_transacttime: "2019-11-25T13:31:08.549938300Z", our_order_side: Sell, our_order_status: Completed, our_order_price: 129.328125, our_order_size: 0, our_order_filled: 1 }</td><td><null></td></tr><tr><td>7</td><td><null></td><td>{ bts.history.Display+FillDisplay: our_fill_time: "2019-11-25T13:31:08.549938300Z", order_id: 1000829, security_desc: ZNZ9, our_fill_side: Sell, our_fill_price: 129.328125, our_fill_size: 1, fill_id: 518, tag: CROSS, best_bid: 129.328125, best_ask: 129.34375 }</td></tr><tr><td>8</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000827, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:31:08.554532600Z", our_order_transacttime: "2019-11-25T13:31:08.554382600Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.390625, our_order_size: 10, our_order_filled: 1 }</td><td><null></td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000827, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:31:08.554532600Z", our_order_transacttime: "2019-11-25T13:31:08.554382600Z", our_order_side: Buy, our_order_status: Completed, our_order_price: 129.390625, our_order_size: 0, our_order_filled: 11 }</td><td><null></td></tr><tr><td>10</td><td><null></td><td>{ bts.history.Display+FillDisplay: our_fill_time: "2019-11-25T13:31:08.554382600Z", order_id: 1000827, security_desc: ZNH0, our_fill_side: Buy, our_fill_price: 129.390625, our_fill_size: 10, fill_id: 519, tag: CROSS, best_bid: 129.375, best_ask: 129.390625 }</td></tr><tr><td>11</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000831, security_desc: ZNZ9, our_order_sendingtime: "2019-11-25T13:31:08.554682600Z", our_order_transacttime: "2019-11-25T13:31:08.554532600Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.34375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000831, security_desc: ZNZ9, our_order_sendingtime: "2019-11-25T13:31:08.554682600Z", our_order_transacttime: "2019-11-25T13:31:08.554532600Z", our_order_side: Sell, our_order_status: Completed, our_order_price: 129.34375, our_order_size: 0, our_order_filled: 10 }</td><td><null></td></tr><tr><td>13</td><td><null></td><td>{ bts.history.Display+FillDisplay: our_fill_time: "2019-11-25T13:31:08.554532600Z", order_id: 1000831, security_desc: ZNZ9, our_fillLine truncated
|
||||
"10"
|
||||
]
|
||||
},
|
||||
"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: 1000343, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:00.654658700Z", our_order_transacttime: "2019-11-25T13:30:00.654508700Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.421875, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000344, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:00.654658700Z", our_order_transacttime: "2019-11-25T13:30:00.654508700Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>2</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000343, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.423507500Z", our_order_transacttime: "2019-11-25T13:30:15.423357500Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.40625, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000344, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.423507500Z", our_order_transacttime: "2019-11-25T13:30:15.423357500Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.34375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>4</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000343, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.432981500Z", our_order_transacttime: "2019-11-25T13:30:15.432831500Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.421875, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000344, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.432981500Z", our_order_transacttime: "2019-11-25T13:30:15.432831500Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>6</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000344, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.432981500Z", our_order_transacttime: "2019-11-25T13:30:15.432831501Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 2, our_order_filled: 8 }</td><td><null></td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000343, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:31:08.553545200Z", our_order_transacttime: "2019-11-25T13:31:08.553395200Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.4375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>8</td><td><null></td><td>{ bts.history.Display+FillDisplay: our_fill_transact_time: "2019-11-25T13:31:08.553691900Z", our_fill_sending_time: "2019-11-25T13:31:08.553841900Z", order_id: 1000344, security_desc: ZNH0, our_fill_side: Buy, our_fill_price: 129.359375, our_fill_size: 8, fill_id: 846784119686, tag: <null>, best_bid: 0, best_ask: 0 }</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000346, security_desc: ZNZ9, our_order_sendingtime: "2019-11-25T13:31:08.553891900Z", our_order_transacttime: "2019-11-25T13:31:08.553741900Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.34375, our_order_size: 8, our_order_filled: 0 }</td><td><null></td></tr><tr><td>10</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000346, security_desc: ZNZ9, our_order_sendingtime: "2019-11-25T13:31:08.553891900Z", our_order_transacttime: "2019-11-25T13:31:08.553741900Z", our_order_side: Sell, our_order_status: Completed, our_order_price: 129.34375, our_order_size: 0, our_order_filled: 8 }</td><td><null></td></tr><tr><td>11</td><td><null></td><td>{ bts.history.Display+FillDisplay: our_fill_transact_time: "2019-11-25T13:31:08.553741900Z", our_fill_sending_time: "2019-11-25T13:31:08.553891900Z", order_id: 1000346, security_desc: ZNZ9, our_fill_side: Sell, our_fill_price: 129.34375, our_fill_size: 8, fill_id: 191, tag: 1000346 FULLFILL, best_bid: 129.34375, best_ask: 129.359375 }</td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000348, security_desc: ZNZ9-ZNH0, our_order_sendingtime: "2019-11-25T13:31:08.553891900Z", our_order_transacttime: "2019-11-25T13:31:08.553741900Z", our_order_side: Buy, our_order_status: Working, our_order_price: -0.046875, our_order_size:Line truncated
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
@@ -237,7 +254,8 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"display(algo_orders.Where(x => x.fill != null).Count());\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));"
|
||||
]
|
||||
},
|
||||
@@ -250,7 +268,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -259,13 +277,13 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"execution_count": 18,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<table><thead><tr><th><i>index</i></th><th>OrderUpdateAction</th><th>OrderId</th><th>SecurityId</th><th>SecurityDesc</th><th>MdOrderPriority</th><th>MdEntryPx</th><th>MdPriceLevel</th><th>MdDisplayQty</th><th>LastQty</th><th>MdEntryType</th><th>ReferenceId</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>{ bts.history.MDUpdateAction: value__: 49 }</td><td>846784275060</td><td>771691</td><td>ZNH0</td><td>12365464626</td><td>129.375</td><td>1</td><td>10</td><td>0</td><td>{ bts.history.MDEntryType: value__: 48 }</td><td>1</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574640000, Nanos: 0 }</td><td>4730321</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574689722, Nanos: 406289900 }</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574689722, Nanos: 400046700 }</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 501661, MdEntryPx: 129.375, MdEntrySize: 247, NumberOfOrders: 41, MdPriceLevel: 1, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784275060, MdOrderPriority: 12365464626, MdDisplayQty: 10 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784275060, MdDisplayQty: 10, MdOrderPriority: 12365464626, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 48 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>1</td><td>{ bts.history.MDUpdateAction: value__: 49 }</td><td>846784275060</td><td>771691</td><td>ZNH0</td><td>12365464626</td><td>129.375</td><td>0</td><td>9</td><td>0</td><td>{ bts.history.MDEntryType: value__: 48 }</td><td>0</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574640000, Nanos: 0 }</td><td>4734764</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574689737, Nanos: 372592200 }</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574689737, Nanos: 372317400 }</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 0, MdEntryPx: 129.375, MdEntrySize: 0, NumberOfOrders: 0, MdPriceLevel: 0, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 846784275060, MdOrderPriority: 12365464626, MdDisplayQty: 9 }</td><td><null></td></tr><tr><td>2</td><td>{ bts.history.MDUpdateAction: value__: 49 }</td><td>846784275060</td><td>771691</td><td>ZNH0</td><td>12365464626</td><td>129.375</td><td>1</td><td>7</td><td>0</td><td>{ bts.history.MDEntryType: value__: 48 }</td><td>1</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574640000, Nanos: 0 }</td><td>4744325</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574689757, Nanos: 675288100 }</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574689757, Nanos: 675018600 }</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 502622, MdEntryPx: 129.375, MdEntrySize: 1183, NumberOfOrders: 97, MdPriceLevel: 1, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784275060, MdOrderPriority: 12365464626, MdDisplayQty: 7 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784275060, MdDisplayQty: 7, MdOrderPriority: 12365464626, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>3</td><td>{ bts.history.MDUpdateAction: value__: 49 }</td><td>846784275060</td><td>771691</td><td>ZNH0</td><td>12365464626</td><td>129.375</td><td>1</td><td>5</td><td>0</td><td>{ bts.history.MDEntryType: value__: 48 }</td><td>1</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574640000, Nanos: 0 }</td><td>4751448</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574689779, Nanos: 671983500 }</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574689779, Nanos: 671732500 }</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 503018, MdEntryPx: 129.375, MdEntrySize: 1169, NumberOfOrders: 95, MdPriceLevel: 1, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784275060, MdOrderPriority: 12365464626, MdDisplayQty: 5 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784275060, MdDisplayQty: 5, MdOrderPriority: 12365464626, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>4</td><td>{ bts.history.MDUpdateAction: value__: 49 }</td><Line truncated
|
||||
"<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>"2019-11-25T00:00:00Z"</td><td>4361037</td><td>"2019-11-25T13:30:20.470246800Z"</td><td>"2019-11-25T13:30:20.470147Z"</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>"2019-11-25T00:00:00Z"</td><td>4374305</td><td>"2019-11-25T13:31:08.565352Z"</td><td>"2019-11-25T13:31:08.553691900Z"</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": {},
|
||||
@@ -291,13 +309,16 @@
|
||||
" 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",
|
||||
"//display(exchange_orders.Skip(20000).Take(100));\n",
|
||||
"display(exchange_orders.Where(x => x.OrderId == 846784275060)) //.Select(x => new MBODisplay(x)));"
|
||||
"display(exchange_orders.Where(x => x.OrderId == 846784119686).Select(x => new MBODisplay(x)));"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -355,7 +376,7 @@
|
||||
"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));"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -165,7 +165,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
@@ -179,48 +179,56 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": 21,
|
||||
"metadata": {
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"var security_list = new [] {\"ZNZ9\",\"ZNH0\"};\n",
|
||||
"//quotes the last leg\n",
|
||||
"var algo_type = typeof(Spreader);\n",
|
||||
"var algo_params = \"size=10;tick_size=0.015625,0.015625;hedge_factors=1,-1;profit_ticks=0\";\n",
|
||||
"\n",
|
||||
"var latency_ns = 150_000u;\n",
|
||||
"var transact_latency = new Bucket(latency_ns, latency_ns+1);\n",
|
||||
"var transmit_latency = new Bucket(latency_ns, latency_ns+1);\n",
|
||||
"var sink = new LatencyOrderSink(transact_latency, transmit_latency);\n",
|
||||
"var fill_model = new FIFOFillModel(transmit_latency);\n",
|
||||
"var latency_in = 10_000u;\n",
|
||||
"var latency_out = 50_000u;\n",
|
||||
"var latency_iceberg = 6_000_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 FIFOFillModel(outgoing_latency);\n",
|
||||
"\n",
|
||||
"//var security_list = new [] {\"ZNZ9\",\"ZNH0\"};\n",
|
||||
"//var algo_params = \"size=10;tick_size=0.015625,0.015625;hedge_factors=1,-1;profit_ticks=0\";\n",
|
||||
"var security_list = new [] {\"ZNZ9\",\"ZNZ9-ZNH0\", \"ZNH0\"};\n",
|
||||
"var algo_params = \"size=10;tick_size=0.015625,0.0078125,0.015625;hedge_factors=1,-1,-1;profit_ticks=1\";\n",
|
||||
"var algo_orders = algo_orders<HistoryRow>(sink, fill_model, \n",
|
||||
" algo_type, algo_params, \n",
|
||||
" bts.api.Side.Sell, -0.046875, 10, \n",
|
||||
" bts.api.Side.Undefined, 0.0, 10, \n",
|
||||
"// bts.api.Side.Sell, -0.046875, 10, \n",
|
||||
" security_list, //must match below\n",
|
||||
" new[] {z9f, h0f});"
|
||||
" new[] {z9f, spdf, h0f}, latency_iceberg);\n",
|
||||
"// new[] {z9f, h0f}, latency_iceberg);"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"var algo_orders_cached = algo_orders.ToArray();\n",
|
||||
"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": 16,
|
||||
"execution_count": 23,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"254"
|
||||
"63"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
@@ -229,7 +237,16 @@
|
||||
{
|
||||
"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: 1000827, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:00.045321Z", our_order_transacttime: "2019-11-25T13:30:00.045171Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000827, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.423607500Z", our_order_transacttime: "2019-11-25T13:30:15.423457500Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>2</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000827, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.433081500Z", our_order_transacttime: "2019-11-25T13:30:15.432931500Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000827, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.433081500Z", our_order_transacttime: "2019-11-25T13:30:15.432931500Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.375, our_order_size: 9, our_order_filled: 1 }</td><td><null></td></tr><tr><td>4</td><td><null></td><td>{ bts.history.Display+FillDisplay: our_fill_time: "2019-11-25T13:31:08.549788300Z", order_id: 1000827, security_desc: ZNH0, our_fill_side: Buy, our_fill_price: 129.375, our_fill_size: 1, fill_id: 846783978493, tag: <null>, best_bid: 0, best_ask: 0 }</td></tr><tr><td>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000829, security_desc: ZNZ9, our_order_sendingtime: "2019-11-25T13:31:08.550088300Z", our_order_transacttime: "2019-11-25T13:31:08.549938300Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.328125, our_order_size: 1, our_order_filled: 0 }</td><td><null></td></tr><tr><td>6</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000829, security_desc: ZNZ9, our_order_sendingtime: "2019-11-25T13:31:08.550088300Z", our_order_transacttime: "2019-11-25T13:31:08.549938300Z", our_order_side: Sell, our_order_status: Completed, our_order_price: 129.328125, our_order_size: 0, our_order_filled: 1 }</td><td><null></td></tr><tr><td>7</td><td><null></td><td>{ bts.history.Display+FillDisplay: our_fill_time: "2019-11-25T13:31:08.549938300Z", order_id: 1000829, security_desc: ZNZ9, our_fill_side: Sell, our_fill_price: 129.328125, our_fill_size: 1, fill_id: 518, tag: CROSS, best_bid: 129.328125, best_ask: 129.34375 }</td></tr><tr><td>8</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000827, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:31:08.554532600Z", our_order_transacttime: "2019-11-25T13:31:08.554382600Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.390625, our_order_size: 10, our_order_filled: 1 }</td><td><null></td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000827, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:31:08.554532600Z", our_order_transacttime: "2019-11-25T13:31:08.554382600Z", our_order_side: Buy, our_order_status: Completed, our_order_price: 129.390625, our_order_size: 0, our_order_filled: 11 }</td><td><null></td></tr><tr><td>10</td><td><null></td><td>{ bts.history.Display+FillDisplay: our_fill_time: "2019-11-25T13:31:08.554382600Z", order_id: 1000827, security_desc: ZNH0, our_fill_side: Buy, our_fill_price: 129.390625, our_fill_size: 10, fill_id: 519, tag: CROSS, best_bid: 129.375, best_ask: 129.390625 }</td></tr><tr><td>11</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000831, security_desc: ZNZ9, our_order_sendingtime: "2019-11-25T13:31:08.554682600Z", our_order_transacttime: "2019-11-25T13:31:08.554532600Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.34375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000831, security_desc: ZNZ9, our_order_sendingtime: "2019-11-25T13:31:08.554682600Z", our_order_transacttime: "2019-11-25T13:31:08.554532600Z", our_order_side: Sell, our_order_status: Completed, our_order_price: 129.34375, our_order_size: 0, our_order_filled: 10 }</td><td><null></td></tr><tr><td>13</td><td><null></td><td>{ bts.history.Display+FillDisplay: our_fill_time: "2019-11-25T13:31:08.554532600Z", order_id: 1000831, security_desc: ZNZ9, our_fillLine truncated
|
||||
"11"
|
||||
]
|
||||
},
|
||||
"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: 1000111, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:00.654518700Z", our_order_transacttime: "2019-11-25T13:30:00.654468700Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.421875, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000112, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:00.654518700Z", our_order_transacttime: "2019-11-25T13:30:00.654468700Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>2</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000111, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.423367500Z", our_order_transacttime: "2019-11-25T13:30:15.423317500Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.40625, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000112, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.423367500Z", our_order_transacttime: "2019-11-25T13:30:15.423317500Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.34375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>4</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000111, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.432841500Z", our_order_transacttime: "2019-11-25T13:30:15.432791500Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.421875, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000112, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.432841500Z", our_order_transacttime: "2019-11-25T13:30:15.432791500Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>6</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000112, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:30:15.432841500Z", our_order_transacttime: "2019-11-25T13:30:15.432791501Z", our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 2, our_order_filled: 8 }</td><td><null></td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000111, security_desc: ZNH0, our_order_sendingtime: "2019-11-25T13:31:08.553405200Z", our_order_transacttime: "2019-11-25T13:31:08.553355200Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.4375, our_order_size: 10, our_order_filled: 0 }</td><td><null></td></tr><tr><td>8</td><td><null></td><td>{ bts.history.Display+FillDisplay: our_fill_transact_time: "2019-11-25T13:31:08.553691900Z", our_fill_sending_time: "2019-11-25T13:31:08.553741900Z", order_id: 1000112, security_desc: ZNH0, our_fill_side: Buy, our_fill_price: 129.359375, our_fill_size: 8, fill_id: 846784119686, tag: <null>, best_bid: 0, best_ask: 0 }</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000114, security_desc: ZNZ9, our_order_sendingtime: "2019-11-25T13:31:08.553751900Z", our_order_transacttime: "2019-11-25T13:31:08.553701900Z", our_order_side: Sell, our_order_status: Working, our_order_price: 129.34375, our_order_size: 8, our_order_filled: 0 }</td><td><null></td></tr><tr><td>10</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000114, security_desc: ZNZ9, our_order_sendingtime: "2019-11-25T13:31:08.553751900Z", our_order_transacttime: "2019-11-25T13:31:08.553701900Z", our_order_side: Sell, our_order_status: Completed, our_order_price: 129.34375, our_order_size: 0, our_order_filled: 8 }</td><td><null></td></tr><tr><td>11</td><td><null></td><td>{ bts.history.Display+FillDisplay: our_fill_transact_time: "2019-11-25T13:31:08.553701900Z", our_fill_sending_time: "2019-11-25T13:31:08.553751900Z", order_id: 1000114, security_desc: ZNZ9, our_fill_side: Sell, our_fill_price: 129.34375, our_fill_size: 8, fill_id: 62, tag: CROSS, best_bid: 129.34375, best_ask: 129.359375 }</td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000116, security_desc: ZNZ9-ZNH0, our_order_sendingtime: "2019-11-25T13:31:08.553751900Z", our_order_transacttime: "2019-11-25T13:31:08.553701900Z", our_order_side: Buy, our_order_status: Working, our_order_price: -0.046875, our_order_size: 8, our_ordeLine truncated
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
@@ -237,7 +254,8 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"display(algo_orders.Where(x => x.fill != null).Count());\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));"
|
||||
]
|
||||
},
|
||||
@@ -250,7 +268,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -259,13 +277,13 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"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>Change</td><td>846784275060</td><td>ZNH0</td><td>12365464626</td><td>129.375</td><td>1</td><td>10</td><td>0</td><td>Bid</td><td>"2019-11-25T00:00:00Z"</td><td>4730321</td><td>"2019-11-25T13:48:42.406289900Z"</td><td>"2019-11-25T13:48:42.400046700Z"</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 501661, MdEntryPx: 129.375, MdEntrySize: 247, NumberOfOrders: 41, MdPriceLevel: 1, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784275060, MdOrderPriority: 12365464626, MdDisplayQty: 10 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784275060, MdDisplayQty: 10, MdOrderPriority: 12365464626, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 48 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>1</td><td>Change</td><td>846784275060</td><td>ZNH0</td><td>12365464626</td><td>129.375</td><td>0</td><td>9</td><td>0</td><td>Bid</td><td>"2019-11-25T00:00:00Z"</td><td>4734764</td><td>"2019-11-25T13:48:57.372592200Z"</td><td>"2019-11-25T13:48:57.372317400Z"</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 0, MdEntryPx: 129.375, MdEntrySize: 0, NumberOfOrders: 0, MdPriceLevel: 0, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 846784275060, MdOrderPriority: 12365464626, MdDisplayQty: 9 }</td><td><null></td></tr><tr><td>2</td><td>Change</td><td>846784275060</td><td>ZNH0</td><td>12365464626</td><td>129.375</td><td>1</td><td>7</td><td>0</td><td>Bid</td><td>"2019-11-25T00:00:00Z"</td><td>4744325</td><td>"2019-11-25T13:49:17.675288100Z"</td><td>"2019-11-25T13:49:17.675018600Z"</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 502622, MdEntryPx: 129.375, MdEntrySize: 1183, NumberOfOrders: 97, MdPriceLevel: 1, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784275060, MdOrderPriority: 12365464626, MdDisplayQty: 7 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784275060, MdDisplayQty: 7, MdOrderPriority: 12365464626, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>3</td><td>Change</td><td>846784275060</td><td>ZNH0</td><td>12365464626</td><td>129.375</td><td>1</td><td>5</td><td>0</td><td>Bid</td><td>"2019-11-25T00:00:00Z"</td><td>4751448</td><td>"2019-11-25T13:49:39.671983500Z"</td><td>"2019-11-25T13:49:39.671732500Z"</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 503018, MdEntryPx: 129.375, MdEntrySize: 1169, NumberOfOrders: 95, MdPriceLevel: 1, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784275060, MdOrderPriority: 12365464626, MdDisplayQty: 5 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784275060, MdDisplayQty: 5, MdOrderPriority: 12365464626, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>4</td><td>Change</td><td>846784275060</td><td>ZNH0</td><td>12365464626</td><td>129.375</td><td>1</td><td>3</td><td>0</td><td>Bid</td><td>"2019-11-25T00:00:00Z"</td><td>4756115</td><td>"2019-11-25T13:50:00.378105200Z"</td><td>"2019-11-25T13:50:00.377818600Z"</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 503264, MdEntryPx: 129.375, MdEntrySize: 1169, NumberOfOrders: 97, MdPriceLevel: 1, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784275060, MdOrderPriority: 12365464626, MdDisplayQty: 3 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784275060, MdDisplayQty: 3, MdOrderPriority: 12365464626, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>5</td><td>Change</td><td>846784275060</Line truncated
|
||||
"<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>846784134213</td><td>ZNH0</td><td>12365219588</td><td>129.359375</td><td>2</td><td>4</td><td>0</td><td>Bid</td><td>"2019-11-25T00:00:00Z"</td><td>4398462</td><td>"2019-11-25T13:31:12.407490100Z"</td><td>"2019-11-25T13:31:12.407373900Z"</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 470121, MdEntryPx: 129.359375, MdEntrySize: 1868, NumberOfOrders: 107, MdPriceLevel: 2, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784134213, MdOrderPriority: 12365219588, MdDisplayQty: 4 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784134213, MdDisplayQty: 4, MdOrderPriority: 12365219588, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 48 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>1</td><td>Change</td><td>846784134213</td><td>ZNH0</td><td>12365260989</td><td>129.40625</td><td>1</td><td>4</td><td>0</td><td>Bid</td><td>"2019-11-25T00:00:00Z"</td><td>4456781</td><td>"2019-11-25T13:35:09.480072100Z"</td><td>"2019-11-25T13:35:09.477932900Z"</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 474892, MdEntryPx: 129.40625, MdEntrySize: 366, NumberOfOrders: 31, MdPriceLevel: 1, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 0, MdOrderPriority: 0, MdDisplayQty: 0 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784134213, MdDisplayQty: 4, MdOrderPriority: 12365260989, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>2</td><td>Change</td><td>846784134213</td><td>ZNH0</td><td>12365261294</td><td>129.359375</td><td>4</td><td>4</td><td>0</td><td>Bid</td><td>"2019-11-25T00:00:00Z"</td><td>4457227</td><td>"2019-11-25T13:35:09.486761100Z"</td><td>"2019-11-25T13:35:09.485128500Z"</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 474927, MdEntryPx: 129.359375, MdEntrySize: 1966, NumberOfOrders: 110, MdPriceLevel: 4, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 0, MdOrderPriority: 0, MdDisplayQty: 0 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784134213, MdDisplayQty: 4, MdOrderPriority: 12365261294, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 2, LastQty: 0 }</td></tr><tr><td>3</td><td>Change</td><td>846784134213</td><td>ZNH0</td><td>12365261314</td><td>129.40625</td><td>1</td><td>4</td><td>0</td><td>Bid</td><td>"2019-11-25T00:00:00Z"</td><td>4457255</td><td>"2019-11-25T13:35:09.487150800Z"</td><td>"2019-11-25T13:35:09.486093200Z"</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 474934, MdEntryPx: 129.40625, MdEntrySize: 297, NumberOfOrders: 26, MdPriceLevel: 1, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 0, MdOrderPriority: 0, MdDisplayQty: 0 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784134213, MdDisplayQty: 4, MdOrderPriority: 12365261314, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>4</td><td>Change</td><td>846784134213</td><td>ZNH0</td><td>12365261322</td><td>129.359375</td><td>4</td><td>4</td><td>0</td><td>Bid</td><td>"2019-11-25T00:00:00Z"</td><td>4457268</td><td>"2019-11-25T13:35:09.487368300Z"</td><td>"2019-11-25T13:35:09.486581600Z"</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 474940, MdEntryPx: 129.359375, MdEntrySize: 1966, NumberOfOrders: 110, MdPriceLevel: 4, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 0, MdOrderPriority: 0, MdDisplayQty: 0 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784134213, MdDisplayQty: 4, MdOrderPriority: 12365261322, OrderUpdateAction: { btsLine truncated
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
@@ -300,7 +318,7 @@
|
||||
" \n",
|
||||
" }\n",
|
||||
"//display(exchange_orders.Skip(20000).Take(100));\n",
|
||||
"display(exchange_orders.Where(x => x.OrderId == 846784275060).Select(x => new MBODisplay(x)));"
|
||||
"display(exchange_orders.Where(x => x.OrderId == 846784134213).Select(x => new MBODisplay(x)));"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -369,7 +387,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"display(h0trades.Take(1000));"
|
||||
"//display(h0trades.Take(1000));"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -257,7 +257,7 @@ namespace bts.history
|
||||
System.Type algo_type, string algo_params,
|
||||
api.Side side, double price, uint size,
|
||||
string[] security_list, IEnumerable<T>[] datastream,
|
||||
bool allow_fills = true, int framelimit = int.MaxValue)
|
||||
uint iceberg_latency_ns, bool allow_fills = true, int framelimit = int.MaxValue)
|
||||
where T : class, IHasBook, IHasTrade, IHasTimestamp, IHasMBO
|
||||
{
|
||||
var q = new List<OrderOrFill>();
|
||||
@@ -281,22 +281,26 @@ namespace bts.history
|
||||
fill_model.on_fill += (f => f.order.on_fill(f));
|
||||
}
|
||||
|
||||
Timestamp last_iceberg = null;
|
||||
var ienum = stream_data(datastream, (T[] valcache, int min) =>
|
||||
{
|
||||
q.Clear();
|
||||
if(count == 0 ||
|
||||
algo.is_completed()) //spreader case will never complete
|
||||
{
|
||||
algo = AlgoFactory.algo_factory(algo_type, sink, security_list, algo_params);
|
||||
var algobase = (AlgoBase)algo;
|
||||
AlgoBase.activate_self(algobase, side, price, size, Timestamp.FromDateTime(DateTime.UtcNow),
|
||||
(h, f) => q.Add(new OrderOrFill(f)),
|
||||
(h, s) => q.Add(new OrderOrFill(s)) );
|
||||
}
|
||||
if (count++ > framelimit)
|
||||
throw new System.IO.EndOfStreamException();
|
||||
throw new System.IO.EndOfStreamException();
|
||||
T curr = (T)valcache[min];
|
||||
if(algo == null || algo.is_completed())
|
||||
{
|
||||
if(last_iceberg == null || last_iceberg.add_nanos((int)iceberg_latency_ns).less(curr.SendingTime))
|
||||
{
|
||||
algo = AlgoFactory.algo_factory(algo_type, sink, security_list, algo_params);
|
||||
AlgoBase.activate_self((AlgoBase)algo, side, price, size, Timestamp.FromDateTime(DateTime.UtcNow),
|
||||
(h, f) => q.Add(new OrderOrFill(f)),
|
||||
(h, s) => q.Add(new OrderOrFill(s)) );
|
||||
last_iceberg = curr.SendingTime;
|
||||
}
|
||||
}
|
||||
|
||||
var secdesc = security_list[min];
|
||||
T curr = (T)valcache[min];
|
||||
List<MBOMessage> mbo = MBOUtils.extract_mbo(curr.Md, curr.MdEntry, curr.EntryIndex, curr.Orders);
|
||||
if(curr.MdEntry.MdEntryType == MDEntryType.Bid || curr.MdEntry.MdEntryType == MDEntryType.Offer)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user