honing in

This commit is contained in:
Kevin Darby committed 2019-12-18 23:41:31 -05:00
1 parent 5ba8440877
commit 297093f9ce
8 files changed
+73 -238

No files matched your search

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using Google.Protobuf;
using Google.Protobuf.Collections;
using Google.Protobuf.WellKnownTypes;
using mbts.co2;
namespace bts.history
{
@@ -129,9 +130,12 @@ namespace bts.co2
uint Key { get; }
ulong OrderId { get; set; }
uint Size { get; set; }
AggressorSide AggressorSide { get; }
double price { get; }
}
public sealed partial class TradeMessage : ITradeWithOrderIDAndSize
{
public double price => NativePriceHelpers.to_double(this.Mantissa, (sbyte)this.Exponent);
}
}
@@ -35,10 +35,8 @@ namespace bts.history
public SpreaderAlgo(IOrderSink sink, string[] security_list) : base(sink, security_list) { }
//algo parameters
public double lean_factor { get; set; } = 1.0;
public int profit_ticks { get; set; } = 1;
public double profit_ticks { get; set; } = 0.0;
public double[] tick_size { get; set; }
public bool[] should_quote { get; set; }
public double[] hedge_factors { get; set; }
SortedList<string, double> _tick_size = new SortedList<string, double>();
@@ -195,13 +193,13 @@ namespace bts.history
double tick = _tick_size[sec];
if(quoteside == api.Side.Sell)
{
qt += profit_ticks*tick;
qt += profit_ticks;
qt = round_tick_up(qt,tick);
//qt = Math.Max(qt, current_book.ask_at(0));
}
else
{
qt -= profit_ticks*tick;
qt -= profit_ticks;
qt = round_tick_dn(qt,tick);
//qt = Math.Min(qt, current_book.bid_at(0));
}
@@ -110,11 +110,10 @@ namespace bts.history
return ;
string market_secdesc = curr_market_operation.SecurityDesc;
double market_price = curr_market_operation.MdEntryPx;
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>();
Dictionary<ulong, OrderStatus> latest_state = new Dictionary<ulong, OrderStatus>();
for(int i = our_operation_index - 1; i >= 0; i--)
{
//the closest operation to this trade time
@@ -132,12 +131,13 @@ namespace bts.history
}
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;
latest_state[curr_operation.order.order_id] = curr_operation;
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) )
if (( market_side == api.Side.Buy && curr_operation.state.Price >= trade.price || //fill us if we are better?
market_side == api.Side.Sell && curr_operation.state.Price <= trade.price) )
//this has to be be trade price, not mdentryprx because cme will report orders down in the book that suddenly aggress
{
uint size = Math.Min(fill_qty, curr_operation.state.Quantity);
if (size > 0)
@@ -145,13 +145,16 @@ namespace bts.history
FillEntry f = generate_fill(transact_time, curr_operation, curr_operation.state.Price, size);
f.fill_id = trade.OrderId;
if(market_side == Side.Buy)
f.bid = market_price;
f.bid = trade.price;
else
f.ask = market_price;
f.ask = trade.price;
bool same = curr_operation.order.side == Utils.same_side(trade.AggressorSide);
if(same)
f.tag = "agg side same";
if(f.fully_filled)
{
if (string.IsNullOrEmpty(f.tag))
f.tag = $"{f.order.order_id} FULLFILL {trade.Size} traded";
f.tag = $"{f.order.order_id} FULLFILL {trade.Size} traded " + (same ? "agg side same" : "");
}
fills.Add(f);
fill_qty -= size;
@@ -179,7 +179,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 55,
"metadata": {
"scrolled": true
},
@@ -188,7 +188,7 @@
"//quotes the last leg\n",
"var algo_type = typeof(Spreader);\n",
"\n",
"var latency_in = 100_000u;\n",
"var latency_in = 50_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",
@@ -199,19 +199,19 @@
"//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.Undefined, 0.0, 10, \n",
"// bts.api.Side.Sell, -0.046875, 10, \n",
" security_list, //must match below\n",
" new[] {z9f, spdf, h0f}, latency_iceberg);\n",
"// new[] {z9f, h0f}, latency_iceberg);"
"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",
"// bts.api.Side.Sell, -0.046875, 10, \n",
" security_list, //must match below\n",
" new[] {z9f, spdf, h0f}, latency_iceberg);\n",
"// new[] {z9f, h0f}, latency_iceberg);"
]
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 56,
"metadata": {},
"outputs": [],
"source": [
@@ -222,13 +222,13 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 57,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"60"
"2"
]
},
"metadata": {},
@@ -237,7 +237,7 @@
{
"data": {
"text/html": [
"10"
"2"
]
},
"metadata": {},
@@ -246,7 +246,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>{ bts.history.Display+OrderDisplay: order_id: 1000060, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:00.654608700Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:00.654558700Z&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>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000061, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:00.654608700Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:00.654558700Z&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>{ bts.history.Display+OrderDisplay: order_id: 1000060, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:15.423457500Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:15.423407500Z&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>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000061, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:15.423457500Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:15.423407500Z&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>{ bts.history.Display+OrderDisplay: order_id: 1000060, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:15.432931500Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:15.432881500Z&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>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000061, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:15.432931500Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:15.432881500Z&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>{ bts.history.Display+OrderDisplay: order_id: 1000060, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.553495200Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.553445200Z&quot;, our_order_side: Sell, our_order_status: Working, our_order_price: 129.4375, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000061, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.553741900Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.553691900Z&quot;, our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 2, our_order_filled: 8 }</td><td>&lt;null&gt;</td></tr><tr><td>8</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: our_fill_transact_time: &quot;2019-11-25T13:31:08.553691900Z&quot;, our_fill_sending_time: &quot;2019-11-25T13:31:08.553741900Z&quot;, order_id: 1000061, security_desc: ZNH0, our_fill_side: Buy, our_fill_price: 129.359375, our_fill_size: 8, fill_id: 846784119686, tag: &lt;null&gt;, best_bid: 129.359375, best_ask: 0 }</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000063, security_desc: ZNZ9, our_order_sendingtime: &quot;2019-11-25T13:31:08.553841900Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.553791900Z&quot;, our_order_side: Sell, our_order_status: Working, our_order_price: 129.34375, our_order_size: 8, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>10</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000063, security_desc: ZNZ9, our_order_sendingtime: &quot;2019-11-25T13:31:08.553841900Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.553791900Z&quot;, our_order_side: Sell, our_order_status: Completed, our_order_price: 129.34375, our_order_size: 0, our_order_filled: 8 }</td><td>&lt;null&gt;</td></tr><tr><td>11</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: our_fill_transact_time: &quot;2019-11-25T13:31:08.553791900Z&quot;, our_fill_sending_time: &quot;2019-11-25T13:31:08.553841900Z&quot;, order_id: 1000063, security_desc: ZNZ9, our_fill_side: Sell, our_fill_price: 129.34375, our_fill_size: 8, fill_id: 35, tag: CROSS, best_bid: 129.34375, best_ask: 129.359375 }</td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000065, security_desc: ZNZ9-ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.553841900Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.553791900Z&quot;, our_order_side: Buy, our_order_status: Working, our_order_price: -0.046875, our_order_size: 8,Line 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: 1000265, 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>{ bts.history.Display+OrderDisplay: order_id: 1000266, 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>{ bts.history.Display+OrderDisplay: order_id: 1000265, 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>{ bts.history.Display+OrderDisplay: order_id: 1000266, 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>{ bts.history.Display+OrderDisplay: order_id: 1000265, 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>{ bts.history.Display+OrderDisplay: order_id: 1000266, 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>{ bts.history.Display+OrderDisplay: order_id: 1000265, 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>{ bts.history.Display+OrderDisplay: order_id: 1000266, 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>{ bts.history.Display+OrderDisplay: order_id: 1000265, 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>{ bts.history.Display+OrderDisplay: order_id: 1000266, 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>{ bts.history.Display+OrderDisplay: order_id: 1000265, 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>{ bts.history.Display+OrderDisplay: order_id: 1000266, 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>{ bts.history.Display+OrderDisplay: order_id: 1000265, 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_order_filled: 0 }</td><td>&lt;null&gt;</Line truncated
]
},
"metadata": {},
@@ -277,13 +277,13 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 11,
"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>846784171906</td><td>ZNH0</td><td>12365281715</td><td>129.375</td><td>2</td><td>10</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4484645</td><td>&quot;2019-11-25T13:36:16.433542Z&quot;</td><td>&quot;2019-11-25T13:36:16.414112800Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 476988, MdEntryPx: 129.375, MdEntrySize: 1657, NumberOfOrders: 129, MdPriceLevel: 2, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784171906, MdOrderPriority: 12365281715, MdDisplayQty: 10 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784171906, MdDisplayQty: 10, MdOrderPriority: 12365281715, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 48 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>1</td><td>Change</td><td>846784171906</td><td>ZNH0</td><td>12365361621</td><td>129.34375</td><td>3</td><td>10</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4591721</td><td>&quot;2019-11-25T13:42:24.561693800Z&quot;</td><td>&quot;2019-11-25T13:42:24.551702300Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 487290, MdEntryPx: 129.34375, MdEntrySize: 1952, NumberOfOrders: 107, MdPriceLevel: 3, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 0, MdOrderPriority: 0, MdDisplayQty: 0 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784171906, MdDisplayQty: 10, MdOrderPriority: 12365361621, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 2, LastQty: 0 }</td></tr><tr><td>2</td><td>Change</td><td>846784171906</td><td>ZNH0</td><td>12365362002</td><td>129.375</td><td>1</td><td>10</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4592230</td><td>&quot;2019-11-25T13:42:24.568919Z&quot;</td><td>&quot;2019-11-25T13:42:24.559867800Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 487309, MdEntryPx: 129.375, MdEntrySize: 456, NumberOfOrders: 52, MdPriceLevel: 1, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 0, MdOrderPriority: 0, MdDisplayQty: 0 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784171906, MdDisplayQty: 10, MdOrderPriority: 12365362002, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>3</td><td>Change</td><td>846784171906</td><td>ZNH0</td><td>12365364176</td><td>129.34375</td><td>3</td><td>10</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4595102</td><td>&quot;2019-11-25T13:42:25.057293500Z&quot;</td><td>&quot;2019-11-25T13:42:25.057182400Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 487840, MdEntryPx: 129.34375, MdEntrySize: 1965, NumberOfOrders: 108, MdPriceLevel: 3, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 0, MdOrderPriority: 0, MdDisplayQty: 0 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784171906, MdDisplayQty: 10, MdOrderPriority: 12365364176, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 2, LastQty: 0 }</td></tr><tr><td>4</td><td>Delete</td><td>846784171906</td><td>ZNH0</td><td>12365364176</td><td>129.34375</td><td>0</td><td>10</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4595621</td><td>&quot;2019-11-25T13:42:26.519933300Z&quot;</td><td>&quot;2019-11-25T13:42:26.519649500Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 50 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 0, MdEntryPx: 129.34375, MdEntrySize: 0, NumberOfOrders: 0, MdPriceLevel: 0, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 846784171906, MdOrderPriority: 12365364176, MdDisplayQty: 10 }</td><td>&lt;null&gt;</td></tr></tbody></table>"
"<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": {},
@@ -318,7 +318,7 @@
" \n",
" }\n",
"//display(exchange_orders.Skip(20000).Take(100));\n",
"display(exchange_orders.Where(x => x.OrderId == 846784171906).Select(x => new MBODisplay(x)));"
"display(exchange_orders.Where(x => x.OrderId == 846784119686).Select(x => new MBODisplay(x)));"
]
},
{
@@ -376,12 +376,12 @@
"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));"
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 58,
"metadata": {
"scrolled": true
},
@@ -179,7 +179,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 55,
"metadata": {
"scrolled": true
},
@@ -188,7 +188,7 @@
"//quotes the last leg\n",
"var algo_type = typeof(Spreader);\n",
"\n",
"var latency_in = 100_000u;\n",
"var latency_in = 50_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",
@@ -199,19 +199,19 @@
"//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.Undefined, 0.0, 10, \n",
"// bts.api.Side.Sell, -0.046875, 10, \n",
" security_list, //must match below\n",
" new[] {z9f, spdf, h0f}, latency_iceberg);\n",
"// new[] {z9f, h0f}, latency_iceberg);"
"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",
"// bts.api.Side.Sell, -0.046875, 10, \n",
" security_list, //must match below\n",
" new[] {z9f, spdf, h0f}, latency_iceberg);\n",
"// new[] {z9f, h0f}, latency_iceberg);"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 56,
"metadata": {},
"outputs": [],
"source": [
@@ -222,13 +222,13 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 57,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"60"
"2"
]
},
"metadata": {},
@@ -237,7 +237,7 @@
{
"data": {
"text/html": [
"10"
"2"
]
},
"metadata": {},
@@ -246,7 +246,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>{ bts.history.Display+OrderDisplay: order_id: 1000001, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:00.654608700Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:00.654558700Z&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>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000002, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:00.654608700Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:00.654558700Z&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>{ bts.history.Display+OrderDisplay: order_id: 1000001, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:15.423457500Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:15.423407500Z&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>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000002, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:15.423457500Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:15.423407500Z&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>{ bts.history.Display+OrderDisplay: order_id: 1000001, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:15.432931500Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:15.432881500Z&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>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000002, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:30:15.432931500Z&quot;, our_order_transacttime: &quot;2019-11-25T13:30:15.432881500Z&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>{ bts.history.Display+OrderDisplay: order_id: 1000001, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.553495200Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.553445200Z&quot;, our_order_side: Sell, our_order_status: Working, our_order_price: 129.4375, our_order_size: 10, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000002, security_desc: ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.553741900Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.553691900Z&quot;, our_order_side: Buy, our_order_status: Working, our_order_price: 129.359375, our_order_size: 2, our_order_filled: 8 }</td><td>&lt;null&gt;</td></tr><tr><td>8</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: our_fill_transact_time: &quot;2019-11-25T13:31:08.553691900Z&quot;, our_fill_sending_time: &quot;2019-11-25T13:31:08.553741900Z&quot;, order_id: 1000002, security_desc: ZNH0, our_fill_side: Buy, our_fill_price: 129.359375, our_fill_size: 8, fill_id: 846784119686, tag: &lt;null&gt;, best_bid: 129.359375, best_ask: 0 }</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000004, security_desc: ZNZ9, our_order_sendingtime: &quot;2019-11-25T13:31:08.553841900Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.553791900Z&quot;, our_order_side: Sell, our_order_status: Working, our_order_price: 129.34375, our_order_size: 8, our_order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>10</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000004, security_desc: ZNZ9, our_order_sendingtime: &quot;2019-11-25T13:31:08.553841900Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.553791900Z&quot;, our_order_side: Sell, our_order_status: Completed, our_order_price: 129.34375, our_order_size: 0, our_order_filled: 8 }</td><td>&lt;null&gt;</td></tr><tr><td>11</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: our_fill_transact_time: &quot;2019-11-25T13:31:08.553791900Z&quot;, our_fill_sending_time: &quot;2019-11-25T13:31:08.553841900Z&quot;, order_id: 1000004, security_desc: ZNZ9, our_fill_side: Sell, our_fill_price: 129.34375, our_fill_size: 8, fill_id: 2, tag: CROSS, best_bid: 129.34375, best_ask: 129.359375 }</td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000006, security_desc: ZNZ9-ZNH0, our_order_sendingtime: &quot;2019-11-25T13:31:08.553841900Z&quot;, our_order_transacttime: &quot;2019-11-25T13:31:08.553791900Z&quot;, our_order_side: Buy, our_order_status: Working, our_order_price: -0.046875, our_order_size: 8, Line 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: 1000265, 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>{ bts.history.Display+OrderDisplay: order_id: 1000266, 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>{ bts.history.Display+OrderDisplay: order_id: 1000265, 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>{ bts.history.Display+OrderDisplay: order_id: 1000266, 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>{ bts.history.Display+OrderDisplay: order_id: 1000265, 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>{ bts.history.Display+OrderDisplay: order_id: 1000266, 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>{ bts.history.Display+OrderDisplay: order_id: 1000265, 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>{ bts.history.Display+OrderDisplay: order_id: 1000266, 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>{ bts.history.Display+OrderDisplay: order_id: 1000265, 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>{ bts.history.Display+OrderDisplay: order_id: 1000266, 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>{ bts.history.Display+OrderDisplay: order_id: 1000265, 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>{ bts.history.Display+OrderDisplay: order_id: 1000266, 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>{ bts.history.Display+OrderDisplay: order_id: 1000265, 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_order_filled: 0 }</td><td>&lt;null&gt;</Line truncated
]
},
"metadata": {},
@@ -277,13 +277,13 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 11,
"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>846784162171</td><td>ZNH0</td><td>12365264217</td><td>129.375</td><td>2</td><td>10</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4461044</td><td>&quot;2019-11-25T13:35:09.684648Z&quot;</td><td>&quot;2019-11-25T13:35:09.684477800Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 475581, MdEntryPx: 129.375, MdEntrySize: 1861, NumberOfOrders: 115, MdPriceLevel: 2, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 1, LastQty: 0, OrderId: 846784162171, MdOrderPriority: 12365264217, MdDisplayQty: 10 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784162171, MdDisplayQty: 10, MdOrderPriority: 12365264217, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 48 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>1</td><td>Change</td><td>846784162171</td><td>ZNH0</td><td>12365361040</td><td>129.34375</td><td>3</td><td>10</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4591046</td><td>&quot;2019-11-25T13:42:24.552298500Z&quot;</td><td>&quot;2019-11-25T13:42:24.546128800Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 487078, MdEntryPx: 129.34375, MdEntrySize: 1971, NumberOfOrders: 103, MdPriceLevel: 3, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 0, MdOrderPriority: 0, MdDisplayQty: 0 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784162171, MdDisplayQty: 10, MdOrderPriority: 12365361040, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 2, LastQty: 0 }</td></tr><tr><td>2</td><td>Change</td><td>846784162171</td><td>ZNH0</td><td>12365362663</td><td>129.375</td><td>1</td><td>10</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4593036</td><td>&quot;2019-11-25T13:42:24.580867400Z&quot;</td><td>&quot;2019-11-25T13:42:24.576709100Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 487479, MdEntryPx: 129.375, MdEntrySize: 628, NumberOfOrders: 86, MdPriceLevel: 1, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 0, MdOrderPriority: 0, MdDisplayQty: 0 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784162171, MdDisplayQty: 10, MdOrderPriority: 12365362663, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 1, LastQty: 0 }</td></tr><tr><td>3</td><td>Change</td><td>846784162171</td><td>ZNH0</td><td>12365363102</td><td>129.34375</td><td>3</td><td>10</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4593610</td><td>&quot;2019-11-25T13:42:24.589225900Z&quot;</td><td>&quot;2019-11-25T13:42:24.586946300Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 487718, MdEntryPx: 129.34375, MdEntrySize: 1935, NumberOfOrders: 105, MdPriceLevel: 3, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 0, MdOrderPriority: 0, MdDisplayQty: 0 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784162171, MdDisplayQty: 10, MdOrderPriority: 12365363102, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, ReferenceId: 2, LastQty: 0 }</td></tr><tr><td>4</td><td>Change</td><td>846784162171</td><td>ZNH0</td><td>12365371968</td><td>129.375</td><td>1</td><td>10</td><td>0</td><td>Bid</td><td>&quot;2019-11-25T00:00:00Z&quot;</td><td>4605624</td><td>&quot;2019-11-25T13:42:40.810573Z&quot;</td><td>&quot;2019-11-25T13:42:40.805087200Z&quot;</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 49 }, MdEntryType: { bts.history.MDEntryType: value__: 48 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 489037, MdEntryPx: 129.375, MdEntrySize: 421, NumberOfOrders: 62, MdPriceLevel: 1, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 0, MdTradeEntryId: , ReferenceId: 0, LastQty: 0, OrderId: 0, MdOrderPriority: 0, MdDisplayQty: 0 }</td><td>{ bts.history.OrderIDEntry: OrderId: 846784162171, MdDisplayQty: 10, MdOrderPriority: 12365371968, OrderUpdateAction: { bts.history.MDUpLine 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>&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": {},
@@ -318,7 +318,7 @@
" \n",
" }\n",
"//display(exchange_orders.Skip(20000).Take(100));\n",
"display(exchange_orders.Where(x => x.OrderId == 846784162171).Select(x => new MBODisplay(x)));"
"display(exchange_orders.Where(x => x.OrderId == 846784119686).Select(x => new MBODisplay(x)));"
]
},
{
@@ -372,7 +372,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
@@ -381,23 +381,13 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 58,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>trade_date</th><th>sending_time</th><th>transact_time</th><th>TradeDate</th><th>MsgSeqNum</th><th>SendingTime</th><th>TransactTime</th><th>SecurityDesc</th><th>Book</th><th>TopBook</th><th>Trade</th><th>Md</th><th>MdEntry</th><th>EntryIndex</th><th>Orders</th></tr></thead><tbody><tr><td>0</td><td>2019-11-25 00:00:00Z</td><td>2019-11-25 13:30:02Z</td><td>2019-11-25 13:30:02Z</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574640000, Nanos: 0 }</td><td>4351537</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574688602, Nanos: 72092800 }</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574688602, Nanos: 71734300 }</td><td>ZNH0</td><td>&lt;null&gt;</td><td>&lt;null&gt;</td><td>{ bts.co2.TradeMessage: Key: 771691, Time: 1574688602, Mantissa: 129390625000, Exponent: -9, Size: 10, TotalVolume: 0, Gap: False, AggressorSide: { bts.co2.AggressorSide: value__: 1 }, FromSpread: False, OrderId: 846784115279 }</td><td>{ bts.history.MarketDataIncrementalRefresh: TradeDate: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574640000, Nanos: 0 }, MsgSeqNum: 4351537, SendingTime: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574688602, Nanos: 72092800 }, TransactTime: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574688602, Nanos: 71734300 }, MatchEventIndicator: 00000001, MdEntries: [ { bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 48 }, MdEntryType: { bts.history.MDEntryType: value__: 50 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 462847, MdEntryPx: 129.390625, MdEntrySize: 10, NumberOfOrders: 3, MdPriceLevel: 0, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 1, MdTradeEntryId: 788623, ReferenceId: 0, LastQty: 10, OrderId: 846784115279, MdOrderPriority: 0, MdDisplayQty: 0 } ], OrderIdEntries: [ { bts.history.OrderIDEntry: OrderId: 846784115279, MdDisplayQty: 0, MdOrderPriority: 0, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 0 }, ReferenceId: 0, LastQty: 10 }, { bts.history.OrderIDEntry: OrderId: 846784109121, MdDisplayQty: 0, MdOrderPriority: 0, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 0 }, ReferenceId: 0, LastQty: 3 }, { bts.history.OrderIDEntry: OrderId: 846784109208, MdDisplayQty: 0, MdOrderPriority: 0, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 0 }, ReferenceId: 0, LastQty: 7 } ] }</td><td>{ bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 48 }, MdEntryType: { bts.history.MDEntryType: value__: 50 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 462847, MdEntryPx: 129.390625, MdEntrySize: 10, NumberOfOrders: 3, MdPriceLevel: 0, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 1, MdTradeEntryId: 788623, ReferenceId: 0, LastQty: 10, OrderId: 846784115279, MdOrderPriority: 0, MdDisplayQty: 0 }</td><td>1</td><td>{ bts.history.OrderIDEntry: OrderId: 846784115279, MdDisplayQty: 0, MdOrderPriority: 0, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 0 }, ReferenceId: 0, LastQty: 10 }{ bts.history.OrderIDEntry: OrderId: 846784109121, MdDisplayQty: 0, MdOrderPriority: 0, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 0 }, ReferenceId: 0, LastQty: 3 }{ bts.history.OrderIDEntry: OrderId: 846784109208, MdDisplayQty: 0, MdOrderPriority: 0, OrderUpdateAction: { bts.history.MDUpdateAction: value__: 0 }, ReferenceId: 0, LastQty: 7 }</td></tr><tr><td>1</td><td>2019-11-25 00:00:00Z</td><td>2019-11-25 13:30:22Z</td><td>2019-11-25 13:30:22Z</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574640000, Nanos: 0 }</td><td>4362362</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574688622, Nanos: 393414100 }</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574688622, Nanos: 393152700 }</td><td>ZNH0</td><td>&lt;null&gt;</td><td>&lt;null&gt;</td><td>{ bts.co2.TradeMessage: Key: 771691, Time: 1574688622, Mantissa: 129390625000, Exponent: -9, Size: 8, TotalVolume: 0, Gap: False, AggressorSide: { bts.co2.AggressorSide: value__: 1 }, FromSpread: False, OrderId: 846784120236 }</td><td>{ bts.history.MarketDataIncrementalRefresh: TradeDate: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574640000, Nanos: 0 }, MsgSeqNum: 4362362, SendingTime: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574688622, Nanos: 393414100 }, TransactTime: { Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574688622, Nanos: 393152700 }, MatchEventIndicator: 00000001, MdEntries: [ { bts.history.MDEntry: MdUpdateAction: { bts.history.MDUpdateAction: value__: 48 }, MdEntryType: { bts.history.MDEntryType: value__: 50 }, SecurityId: 771691, Symbol: ZNH0, Rptseq: 463730, MdEntryPx: 129.390625, MdEntrySize: 8, NumberOfOrders: 4, MdPriceLevel: 0, OpenCloseSettleFlag: 0, SettlePriceType: , AggressorSide: 1, MdTradeEntryId: 789062, ReferenceId: 0, LastQty: 8, OrderId: 846784120236, MdOrderPriority: 0, MdDisplayQty: 0 } ], OrderIdEntries: [ { bts.history.OrderIDEntry: OrderId: 846784120Line truncated
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"display(h0trades.Take(1000));"
"//display(h0trades.Take(1000));"
]
},
{
@@ -1,116 +0,0 @@
#if false
using System;
using System.Collections.Generic;
using System.Linq;
using Google.Protobuf.WellKnownTypes;
using bts.co2;
using mbts.co2;
namespace bts.history
{
public class AlgoRunner
{
static public IEnumerable<U> run_algo<T, U>(System.Type algo_type, IOrderSink sink, string algo_params,
api.Side side, double price, uint size,
string[] security_list, IEnumerable<T>[] datastream,
Func<IEnumerable<AlgoResults>, IEnumerable<U>> selector = null,
int framelimit = int.MaxValue)
where T : class, IHasBook, IHasTrade, IHasMBO, IHasTimestamp, IHasDateTimeStamp
{
var q = new List<AlgoResults>();
Dictionary<string, TradeMessage> last_trade = new Dictionary<string, TradeMessage>();
Dictionary<string, BookMessage> last_book = new Dictionary<string, BookMessage>();
IAlgo algo = null;
int count = 0;
var ienum = Query.stream_data(datastream, (T[] valcache, int min) =>
{
q.Clear();
var secdesc = security_list[min];
var curr = valcache[min];
if (count == 0 || algo.is_completed())
{
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 AlgoResults(curr, f, last_trade.GetValueOrDefault(f.order.security_desc), last_book.GetValueOrDefault(f.order.security_desc))),
(h, s) => q.Add(new AlgoResults(curr, s, last_trade.GetValueOrDefault(s.order.security_desc), last_book.GetValueOrDefault(s.order.security_desc))));
}
if (count++ > framelimit)
throw new System.IO.EndOfStreamException();
var orders = MBOUtils.extract_mbo(curr.Md, curr.MdEntry, curr.EntryIndex, curr.Orders);
if (curr.MdEntry.MdEntryType == MDEntryType.Bid || curr.MdEntry.MdEntryType == MDEntryType.Offer)
{
foreach (var order in orders)
algo.sink.process_external_order(curr.Md.TransactTime, order);
}
if (curr.Book != null)
{
algo.sink.process_external_book(curr.Md.TransactTime, secdesc, curr.Book);
algo.process_book(secdesc, curr.MdEntry.SecurityId, curr.Book, curr.Book, curr.Md);
Log.assert(curr.Trade == null, "new schema");
last_book[secdesc] = curr.Book;
}
if (curr.Trade != null)
{
algo.sink.process_external_trade(curr.Md.TransactTime, secdesc, curr.Trade);
foreach (var order in orders)
{
if (curr.Trade.OrderId != order.OrderId)
{
var clone = curr.Trade.Clone();
clone.OrderId = order.OrderId;
clone.Key = order.SecurityId;
clone.AggressorSide = order.MdEntryType ==
MDEntryType.Bid ? AggressorSide.Buy : (order.MdEntryType == MDEntryType.Offer ? AggressorSide.Sell : AggressorSide.None);
var ip = IntPrice.from_double(order.MdEntryPx);
clone.Mantissa = ip.mantissa;
clone.Exponent = ip.exponent;
clone.Size = (uint)order.MdDisplayQty;
algo.sink.process_external_trade(curr.Md.TransactTime, secdesc, clone);
}
}
algo.process_trades(secdesc, curr.MdEntry.SecurityId, new[] { curr.Trade }, curr.Md);
last_trade[secdesc] = curr.Trade;
}
return q;
});
if (selector != null)
return selector(ienum);
else
return ienum.Select(xx => (U)(object)xx);
}
}
public class AlgoResults
{
public AlgoResults(IHasDateTimeStamp h, OrderStatus ord, TradeMessage trd, BookMessage book)
{
this.data = h;
this.order = ord;
this.trade = trd;
this.book = book;
}
public AlgoResults(IHasDateTimeStamp h, FillEntry fil, TradeMessage trd, BookMessage book)
{
this.data = h;
this.fill = fil;
this.trade = trd;
this.book = book;
}
public IHasDateTimeStamp data { get; }
public string security_desc { get; }
public OrderStatus order { get; }
public FillEntry fill { get; }
public co2.BookMessage book { get; }
public co2.TradeMessage trade { get; }
}
}
#endif
+6 -57
View File
@@ -202,62 +202,11 @@ namespace bts.history
});
}
// static public IEnumerable<FillEntry> compute_fills<T>(IFillModel fill_model, IEnumerable<T> tradestream,
// uint reup_nanoseconds = 0,
// int framelimit = int.MaxValue)
// where T : class, IHasMBO, IHasTrade, IHasTimestamp
// {
// return fill_model.compute_fills(tradestream, reup_nanoseconds, framelimit);
// }
// public IEnumerable<FillEntry> compute_fills<T>(IFillModel fill_model, IEnumerable<OrderStatus> my_orders, IEnumerable<T> datastream, int framelimit = int.MaxValue)
// where T : class, IHasMBO, IHasTrade, IHasTimestamp
// {
// var q = new List<FillEntry>();
// int count = 0;
// Dictionary<ulong, uint> spent_lots = new Dictionary<ulong, uint>();
// List<IEnumerable<IHasTimestamp>> ilist = new List<IEnumerable<IHasTimestamp>>();
// ilist.Add(my_orders); ilist.Add(datastream);
// var ienum = Query.stream_data(ilist, (IHasTimestamp[] valcache, int min) =>
// {
// q.Clear();
// if (count++ > framelimit)
// throw new System.IO.EndOfStreamException();
// if(valcache[min] is OrderStatus)
// {
// }
// else
// {
// T curr = (T)valcache[min];
// if (curr.Trade != null)
// {
// Log.assert(curr.MdEntry.MdEntryType == MDEntryType.Trade);
// //q.AddRange(this.get_fills_for_trade(curr.TransactTime, curr.Trade, reup_nanoseconds));
// var trades = MBOUtils.extract_mbo(curr.Md, curr.MdEntry, curr.EntryIndex, curr.Orders);
// foreach (var trade in trades)
// {
// if (curr.Trade.OrderId != trade.OrderId)
// {
// ITradeWithOrderIDAndSize clone = curr.Trade.Clone();
// clone.OrderId = trade.OrderId;
// //price is the same
// clone.Size = trade.LastQty;
// q.AddRange(this.get_fills_for_trade(curr.TransactTime, clone, reup_nanoseconds, spent_lots));
// }
// }
// }
// }
// return q;
// });
// return ienum;
// }
static public IEnumerable<OrderOrFill> algo_orders<T>(IOrderSink sink, IFillModel fill_model,
System.Type algo_type, string algo_params,
api.Side side, double price, uint size,
string[] security_list, IEnumerable<T>[] datastream,
uint iceberg_latency_ns, bool allow_fills = true, int framelimit = int.MaxValue)
static public IEnumerable<OrderOrFill> algo_results<T>(IOrderSink sink, IFillModel fill_model,
System.Type algo_type, string algo_params,
api.Side side, double price, uint size,
string[] security_list, IEnumerable<T>[] datastream,
uint iceberg_latency_ns, bool allow_fills = true, int framelimit = int.MaxValue)
where T : class, IHasBook, IHasTrade, IHasTimestamp, IHasMBO
{
var q = new List<OrderOrFill>();
@@ -319,7 +268,7 @@ namespace bts.history
{
if (curr.Trade.OrderId != trade.OrderId)
{
ITradeWithOrderIDAndSize clone = curr.Trade.Clone();
ITradeWithOrderIDAndSize clone = curr.Trade.Clone(); //same aggressor side
clone.OrderId = trade.OrderId;
//price is the same
clone.Size = trade.LastQty;
@@ -167,6 +167,13 @@ namespace bts.history
return side;
}
static internal api.Side same_side(AggressorSide agg)
{
var side = (agg == AggressorSide.Buy) ? api.Side.Buy :
(agg == AggressorSide.Sell ? api.Side.Sell : api.Side.Undefined);
return side;
}
static internal api.Side opposite_side(MDEntryType mdval)
{
var side = same_side(mdval);