delete more unused methods

This commit is contained in:
Eric Harding committed 2017-12-21 15:02:34 -05:00
1 parent a89fa7fc33
commit e085cf83e4
3 files changed
+6 -106

No files matched your search

@@ -13,14 +13,13 @@ namespace mbts.spark
static class OrderBookExtensions
{
public static IDictionary<uint, IEnumerable<OrderBookEntry>> get_order_sec_map(this IOrderBook ob) { return ob.get_all_orders().Map(e => e.sec_key()); }
public static IDictionary<uint, IEnumerable<OrderBookEntry>> get_order_sec_map(this IOrderBook ob) { return new Dictionary<uint, IEnumerable<OrderBookEntry>>(); }
public static IEnumerable<OrderBookEntry> get_active_orders_for_security(this IOrderBook ob, uint security) { return ob.get_all_orders().Where(e => e.sec_key() == security && e.is_active()); }
public static IEnumerable<OrderBookEntry> get_active_orders_for_security(this IOrderBook ob, uint security) { return Enumerable.Empty<OrderBookEntry>(); }
public static IEnumerable<DemoFill> get_all_fills(this IOrderBook ob) { return ob.get_all_orders().SelectMany(e => e.Fills); }
public static IDictionary<uint, IEnumerable<DemoFill>> get_fill_sec_map(this IOrderBook ob) { return ob.get_all_fills().Map(f => f.Order.Security.Id); }
public static IDictionary<uint, IEnumerable<DemoFill>> get_fill_sec_map(this IOrderBook ob) { return new Dictionary<uint, IEnumerable<DemoFill>>(); }
public static IDictionary<uint, IEnumerable<FillTuple>> get_fill_tuple_sec_map(this IOrderBook ob) { return ob.get_all_orders().Map(o => o.sec_key(), o => o.Fills.Select(f => new FillTuple(f, o))); }
public static IDictionary<uint, IEnumerable<FillTuple>> get_fill_tuple_sec_map(this IOrderBook ob) { return new Dictionary<uint, IEnumerable<FillTuple>>(); }
}
}
@@ -8,102 +8,15 @@ namespace mbts.spark
{
public class OrderBook : IOrderBook
{
private static OrderID _null_id = new OrderID() { Id = String.Empty };
private List<OrderBookEntry> _orderbook = new List<OrderBookEntry>();
public OrderBook() { }
#region Mutators
public void update_entry(OrderStatus order_status) {
OrderBookEntry curr = get_order(order_status.Order.Id);
if (curr == null) {
/// new order
curr = new OrderBookEntry() { OrderStatus = order_status };
if (curr.parent_id() == null) {
/// Does not have a parent => its a "Root" order
_orderbook.Add(curr);
}
else {
/// Add it to an existing Entry
OrderBookEntry parent_order = get_order(order_status.ParentId);
Logger.assert(parent_order != null);
parent_order.ChildOrders.Add(curr);
}
}
else {
/// order exists
if ((curr.parent_id() ?? _null_id).Equals(order_status.ParentId ?? _null_id)) {
/// just update the order, parent has not changed
curr.OrderStatus = order_status;
} else {
/// parents have changed
if (curr.parent_id() == null) _remove_top_level_entry(curr.ID());
else _remove_child_entry(curr.parent_id(), curr.ID());
curr.OrderStatus = order_status;
OrderBookEntry parent_order = get_order(order_status.ParentId);
mbts.Logger.assert(parent_order != null);
parent_order.ChildOrders.Add(curr);
}
}
}
public void update_fills(OrderID order_id, IEnumerable<bts.spark.DemoFill> fills) {
OrderBookEntry o = get_order(order_id);
Logger.assert(o != null);
o.Fills.AddRange(fills);
}
public void update_price(OrderID order_id, double new_price) {
OrderBookEntry o = get_order(order_id);
Logger.assert(o != null);
o.OrderStatus.Order.Price = new_price;
}
internal IOrderBook clone() { return new OrderBook() { _orderbook = _orderbook.Select(o => o.Clone()).ToList() }; }
#endregion
#region IOrderBook
public OrderBookEntry get_order(OrderID order_id) {
return _orderbook.FirstOrDefault(o => o.ID().Equals(order_id));
return null;
}
public IEnumerable<OrderBookEntry> get_all_orders() {
return _get_all_orders(_orderbook);
return Enumerable.Empty<OrderBookEntry>();
}
#endregion
private void _remove_child_entry(OrderID parent_order_id, OrderID child_order_id) {
OrderBookEntry parent_order = get_order(parent_order_id);
if (parent_order != null) {
int index = parent_order.ChildOrders.find_first_index(o => o.ID().Equals(child_order_id));
if (index != -1) parent_order.ChildOrders.RemoveAt(index);
}
}
private void _remove_top_level_entry(OrderID order_id) {
int index = _orderbook.FindLastIndex(o => o.ID().Equals(order_id));
if (index != -1) _orderbook.RemoveAt(index);
}
private static bool _contains_order(IEnumerable<OrderStatus> working_orders, OrderID order_id) {
HashSet<OrderID> order_id_map = new HashSet<OrderID>(working_orders.Select(o => o.Order.Id));
return order_id_map.Contains(order_id);
}
#region Stateless functions
private static IEnumerable<OrderBookEntry> _get_all_orders(IEnumerable<OrderBookEntry> curr) {
foreach (var o in curr) {
yield return o;
foreach (var co in _get_all_orders(o.ChildOrders)) yield return co;
}
}
#endregion
}
}
@@ -180,11 +180,6 @@ namespace mbts.spark
public void cancel_order(IEnumerable<OrderID> order_ids) { }
public void tick_up(IEnumerable<OrderID> order_ids) { }
public void tick_down(IEnumerable<OrderID> order_ids) { }
public void pause(IEnumerable<OrderID> order_ids) { }
public void unpause(IEnumerable<OrderID> orders) { }
public void cancel_security_orders (IEnumerable<uint> sec_keys, bool all_buys, bool all_sells)
{
}
@@ -194,12 +189,6 @@ namespace mbts.spark
return true;
}
public bool change_qty(OrderID order_id, UInt32 new_qty)
{
return true;
}
internal void change_price_and_quantity(OrderID id, double price, uint qty) { }
public bool modify_order(Order modified_order) {
return true;
}
@@ -208,7 +197,6 @@ namespace mbts.spark
public void show_order_ticket(Order order) { _bus.post(SparkTags.ShowNotImplemented, null); }
public void show_order_ticket(IReadOnlyCollection<Order> orders) { _bus.post(SparkTags.ShowNotImplemented, null); }
public void show_order_modify(Order order) { _bus.post(SparkTags.ShowOrderModifyTag, new SparkBusData.ShowOrderModifyMessage(order)); }
public void show_order_modify(IReadOnlyCollection<Order> orders) { _bus.post(SparkTags.ShowOrderModifyTag, new SparkBusData.ShowOrderModifyMessage(orders)); }
internal void show_order_details(OrderID order_id) {
_bus.post(SparkTags.ShowOrderDetailsTag, order_id);