Merge branch 'SP-247-order-entry-sounds'
This commit is contained in:
commit
4f308faba2
4 files changed
+107
-7
No files matched your search
@@ -0,0 +1,80 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.shell;
|
||||
using bts.utils;
|
||||
using mbts.spark;
|
||||
using mbts.ui.settings;
|
||||
using ProtoBuf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace mbts {
|
||||
static class OrderSentEventPredicateVMFactory {
|
||||
public static Dictionary<OrderSentEventPredicate.PredicateTypeOneofCase, ITemplatedPropertyWrapperVM<OrderSentEventPredicate>> get_oneofs(IBus bus) =>
|
||||
new Dictionary<OrderSentEventPredicate.PredicateTypeOneofCase, ITemplatedPropertyWrapperVM<OrderSentEventPredicate>> {
|
||||
{ OrderSentEventPredicate.PredicateTypeOneofCase.AnyOrder, PredicateVMWrapper.create<OrderSentEventPredicate>(p => p.security = null) },
|
||||
{ OrderSentEventPredicate.PredicateTypeOneofCase.SecurityOrder, SecurityCriteriaVMFactory.create<OrderSentEventPredicate>(bus, o => o.security?.is_value ?? new SecurityCriteria(),
|
||||
(p, s) => {
|
||||
if (p.security == null) {
|
||||
p.security = new SecurityPredicate();
|
||||
}
|
||||
p.security.is_value = s;
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
class OrderSentEventPredicate : IEquatable<OrderSentEventPredicate> {
|
||||
static readonly int _type_hash = typeof(OrderSentEventPredicate).GetHashCode();
|
||||
// arbitrary short time period (can override in config)
|
||||
static readonly TimeSpan _stale_order_threshold = TimeSpan.FromSeconds(config.Configuration.get<bts.config.OrderAlerts>().stale_order_threshold_seconds);
|
||||
|
||||
public enum PredicateTypeOneofCase {
|
||||
[Description("(any order)")]
|
||||
AnyOrder,
|
||||
[Description("choose securities")]
|
||||
SecurityOrder
|
||||
}
|
||||
|
||||
[ProtoMember(1)]
|
||||
public SecurityPredicate security { get; set; }
|
||||
|
||||
public PredicateTypeOneofCase predicate_type_case {
|
||||
get {
|
||||
if (security != null)
|
||||
return PredicateTypeOneofCase.SecurityOrder;
|
||||
return PredicateTypeOneofCase.AnyOrder;
|
||||
}
|
||||
}
|
||||
|
||||
public IPredicate<OrderSecurity> create(object obj) =>
|
||||
create_predicate((INotificationServiceDataCache)obj);
|
||||
|
||||
public IPredicate<OrderSecurity> create_predicate(INotificationServiceDataCache data_cache) {
|
||||
var sec_pred = security?.create();
|
||||
return PredicateBuilder.create<OrderSecurity>(os =>
|
||||
// verify security
|
||||
(sec_pred == null || (os.security.HasValue && sec_pred.trigger(os.security.Value))) &&
|
||||
// verify not stale
|
||||
((DateTime.Now - os.order.created()) < _stale_order_threshold) &&
|
||||
// verify order hasn't been added yet
|
||||
// Note: the notification service should offer a way to connect predicates so that they only receive items in TableUpdate.added,
|
||||
// however, the notification service predated TableUpdate.Changes, so for now, just check that the history.Count == 1)
|
||||
(data_cache.order_history.TryGetValue(os.order.Key, out var hist) && hist.Count == 1));
|
||||
}
|
||||
|
||||
public INotificationPredicate<OrderSecurity> create_toast(INotificationServiceDataCache data_cache) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
public bool Equals(OrderSentEventPredicate other) =>
|
||||
other != null && other.security.safe_equals(other.security);
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
Equals(obj as OrderSentEventPredicate);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
EqualityComparer.auto_phase(_type_hash, security?.GetHashCode() ?? 0);
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,9 @@ using bts.utils;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using ProtoBuf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using OrderType = bts.api.orderman.CustomOrderDefinition.CustomOneofCase;
|
||||
using PTOC = mbts.OrderRecordTuplePredicate.PredicateTypeOneofCase;
|
||||
|
||||
namespace mbts {
|
||||
@@ -20,6 +15,7 @@ namespace mbts {
|
||||
// TODO: uncomment the remaining cases when ready
|
||||
public static Dictionary<PTOC, ITemplatedPropertyWrapperVM<OrderRecordTuplePredicate>> get_oneofs(IBus bus, OrdersModel orders_model) {
|
||||
return new Dictionary<PTOC, ITemplatedPropertyWrapperVM<OrderRecordTuplePredicate>> {
|
||||
{ PTOC.SentEvent, wrap(rp => rp.sent_event, (rp, p) => rp.sent_event = p, p => p.predicate_type_case, OrderSentEventPredicateVMFactory.get_oneofs(bus)) },
|
||||
{ PTOC.FilledEvent, wrap(rp => rp.filled_event, (rp, p) => rp.filled_event = p, p => p.predicate_type_case, OrderFilledEventPredicateVMFactory.get_oneofs(bus)) },
|
||||
{ PTOC.CompletedEvent, wrap(rp => rp.completed_event, (rp, p) => rp.completed_event = p, p => p.predicate_type_case, OrderCompletedEventPredicateVMFactory.get_oneofs(bus)) },
|
||||
{ PTOC.CanceledEvent, wrap(rp => rp.canceled_event, (rp, p) => rp.canceled_event = p, p => p.predicate_type_case, OrderCanceledEventPredicateVMFactory.get_oneofs(bus)) },
|
||||
@@ -77,6 +73,7 @@ namespace mbts {
|
||||
OrderFilledEventPredicate _filled_event;
|
||||
OrderCompletedEventPredicate _completed_event;
|
||||
OrderCanceledEventPredicate _canceled_event;
|
||||
OrderSentEventPredicate _sent_event;
|
||||
|
||||
public enum PredicateTypeOneofCase {
|
||||
None,
|
||||
@@ -120,6 +117,8 @@ namespace mbts {
|
||||
OrderKey,
|
||||
[PredicateCase(is_toastable:false)]
|
||||
ParentKey,
|
||||
[PredicateCase("When order is sent", PredicateCategory.Event)]
|
||||
SentEvent,
|
||||
[PredicateCase("When order gets a fill", PredicateCategory.Event)]
|
||||
FilledEvent,
|
||||
[PredicateCase("When order is completed", PredicateCategory.Event)]
|
||||
@@ -176,6 +175,8 @@ namespace mbts {
|
||||
public OrderCompletedEventPredicate completed_event { get => _completed_event; set => _set(ref _completed_event, value); }
|
||||
[ProtoMember(23)]
|
||||
public OrderCanceledEventPredicate canceled_event { get => _canceled_event; set => _set(ref _canceled_event, value); }
|
||||
[ProtoMember(26)]
|
||||
public OrderSentEventPredicate sent_event { get => _sent_event; set => _set(ref _sent_event, value); }
|
||||
[ProtoMember(24)]
|
||||
public bool is_toast_enabled { get; set; }
|
||||
[ProtoMember(25)]
|
||||
@@ -206,6 +207,7 @@ namespace mbts {
|
||||
if (_filled_event != null) return PTOC.FilledEvent;
|
||||
if (_completed_event != null) return PTOC.CompletedEvent;
|
||||
if (_canceled_event != null) return PTOC.CanceledEvent;
|
||||
if (_sent_event != null) return PTOC.SentEvent;
|
||||
if (_attached_target_order_key != null) return PTOC.AttachedTargetOrderKey;
|
||||
return PTOC.None;
|
||||
}
|
||||
@@ -236,6 +238,7 @@ namespace mbts {
|
||||
case PTOC.FilledEvent: return _filled_event.create_predicate(data_cache);
|
||||
case PTOC.CompletedEvent: return _completed_event.create_predicate(data_cache);
|
||||
case PTOC.CanceledEvent: return _canceled_event.create(data_cache);
|
||||
case PTOC.SentEvent: return _sent_event.create(data_cache);
|
||||
case PTOC.AttachedTargetOrderKey: return wrap(_attached_target_order_key.create(), r => r.order.attached_target_order_key());
|
||||
default: return null;
|
||||
}
|
||||
@@ -285,6 +288,7 @@ namespace mbts {
|
||||
case PTOC.FilledEvent: return _filled_event.Equals(other._filled_event);
|
||||
case PTOC.CompletedEvent: return _completed_event.Equals(other._completed_event);
|
||||
case PTOC.CanceledEvent: return _canceled_event.Equals(other._canceled_event);
|
||||
case PTOC.SentEvent: return _sent_event.Equals(other._sent_event);
|
||||
case PTOC.AttachedTargetOrderKey: return _attached_target_order_key.Equals(other._attached_target_order_key);
|
||||
case PTOC.None: return true;
|
||||
default: throw ExceptionHelper.unexpected_oneof_case(ptoc);
|
||||
@@ -320,6 +324,7 @@ namespace mbts {
|
||||
case PTOC.FilledEvent: raw_hash = _filled_event.GetHashCode(); break;
|
||||
case PTOC.CompletedEvent: raw_hash = _completed_event.GetHashCode(); break;
|
||||
case PTOC.CanceledEvent: raw_hash = _canceled_event.GetHashCode(); break;
|
||||
case PTOC.SentEvent: raw_hash = _sent_event.GetHashCode(); break;
|
||||
case PTOC.AttachedTargetOrderKey: raw_hash = _attached_target_order_key.GetHashCode(); break;
|
||||
case PTOC.None: raw_hash = 0; break;
|
||||
default: throw ExceptionHelper.unexpected_oneof_case(ptoc);
|
||||
@@ -355,6 +360,7 @@ namespace mbts {
|
||||
_filled_event = null;
|
||||
_completed_event = null;
|
||||
_canceled_event = null;
|
||||
_sent_event = null;
|
||||
_attached_target_order_key = null;
|
||||
}
|
||||
field = value;
|
||||
|
||||
@@ -78,6 +78,13 @@ message OrderBookOptions {
|
||||
optional double status_color_opacity_when_selected = 2 [default = 0.35];
|
||||
}
|
||||
|
||||
message OrderAlerts {
|
||||
// when the client sees an order for the first time,
|
||||
// this time period is used to determine if the order is actually new,
|
||||
// or [presumably]just arrived bc shell is still initializing, or the server restarted.
|
||||
optional int32 stale_order_threshold_seconds = 1 [default = 60];
|
||||
}
|
||||
|
||||
message ShellPingOptions {
|
||||
optional bool shell_ping_is_enabled = 1 [default = true];
|
||||
optional int32 workloop_milliseconds_interval = 2 [default = 5000];
|
||||
|
||||
@@ -82,8 +82,15 @@ Prepare: open a ladder for a security that has steady market data activity (in t
|
||||
- enter a limit order ACROSS the market to trigger an immediate fill.
|
||||
- this time, the "When order is filled" sound should play; the "When order is canceled" sound should not be heard.
|
||||
|
||||
7) "Any Order" sent sounds:
|
||||
Description:
|
||||
You will be verifying that the order sent sound trigger works
|
||||
|
||||
- in the settings dialog, change "When order is filled" to "When order is sent", then click apply
|
||||
- in the ladder, enter a limit order away from the market, so it is NOT liable to get filled.
|
||||
- you should hear the sound you selected for "When order is sent"
|
||||
|
||||
7) Saved with workspace:
|
||||
8) Saved with workspace:
|
||||
----Note----------------------------------------------------------------------------------------------------------------------
|
||||
- you have completed the sound-functionality testing, don't be alarmed by the 4 sound triggers you are about to add.
|
||||
- this step just requires comparing 2 images of the settings dialog to confirm that they were retained with the workspace.
|
||||
@@ -99,7 +106,7 @@ Prepare: open a ladder for a security that has steady market data activity (in t
|
||||
- close the shell, then restart it with the "Where I left off on" workspace.
|
||||
- open the OWSD to verify that the sound triggers were saved with the workspace.
|
||||
|
||||
8) Test shell does not crash when no sound card present
|
||||
9) Test shell does not crash when no sound card present
|
||||
- use a machine that does not have a sound card, such as eh-2 (check with Eric first)
|
||||
- update config to turn off sounds
|
||||
|
||||
|
||||
Reference in new issue
Block a user