diff --git a/src/app_sparkd/sparkd/position/PositionServiceServer.cpp b/src/app_sparkd/sparkd/position/PositionServiceServer.cpp index da9694058..8b4cc6f14 100644 --- a/src/app_sparkd/sparkd/position/PositionServiceServer.cpp +++ b/src/app_sparkd/sparkd/position/PositionServiceServer.cpp @@ -231,10 +231,16 @@ void PositionServiceServer::create_manual_fill( for (auto mf : batch.manual_fill()) { auto id = utils::gen_id("manual_fills"); mf.set_record_id(id); - struct timeval tv; - gettimeofday(&tv, NULL); - mf.mutable_timestamp()->set_seconds(tv.tv_sec); - mf.mutable_timestamp()->set_nanos(tv.tv_usec * 1000); + // Older clients do not send a timestamp. Retain their existing behavior, + // but preserve a timestamp supplied by newer clients so a manual fill can + // be assigned to its intended trading day. + if (!mf.has_timestamp() || + (mf.timestamp().seconds() == 0 && mf.timestamp().nanos() == 0)) { + struct timeval tv; + gettimeofday(&tv, NULL); + mf.mutable_timestamp()->set_seconds(tv.tv_sec); + mf.mutable_timestamp()->set_nanos(tv.tv_usec * 1000); + } me->manual_fills_store->insert( manual_fills_ns, std::to_string(id), utils::pb::to_string(mf)); @@ -296,6 +302,16 @@ void PositionServiceServer::update_manual_fill( this_resp->set_ok(false); this_resp->set_msg("Could not find record"); } else { + // Legacy clients omit timestamps when editing. Do not let that erase + // the trading date that was assigned when the fill was created. + if (!mf.has_timestamp() || + (mf.timestamp().seconds() == 0 && mf.timestamp().nanos() == 0)) { + ManualFill existing; + if (utils::pb::from_string(val, &existing) && + existing.has_timestamp()) { + mf.mutable_timestamp()->CopyFrom(existing.timestamp()); + } + } me->manual_fills_store->update( manual_fills_ns, id, utils::pb::to_string(mf)); this_resp->set_ok(true); diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillRow.cs b/src/client/spark/Modules/Trading/ManualFills/ManualFillRow.cs index 04345f90b..86c156bec 100644 --- a/src/client/spark/Modules/Trading/ManualFills/ManualFillRow.cs +++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillRow.cs @@ -28,7 +28,8 @@ namespace bts.shell.manual_fills { nameof(user), nameof(side), nameof(quantity), - nameof(price) + nameof(price), + nameof(fill_date) }, typeof(ManualFillRow).GetProperty); readonly ISecurityMetadataStore _sec_meta_store; @@ -43,6 +44,7 @@ namespace bts.shell.manual_fills { UserTuple? _user; Side _side; double _price; + DateTime _timestamp; bool _is_selected; ManualFillData? _data; IDisposable _committed_snapshot; @@ -68,6 +70,9 @@ namespace bts.shell.manual_fills { // TickDisplaySettingsImmutable for qty, obtained via ISecurityMetadataStore. _quantity.conversion_data = new(1, QuantityConversionOpType.DivideActual); _price = data.value.manual_fill.Price; + _timestamp = data.value.manual_fill.HasTimestamp + ? data.value.manual_fill.Timestamp.to_local_time() + : DateTime.Now; if (placeholder_key.HasValue) { _is_dirty = backing(nameof(is_dirty), false); _editable_item_state = backing(nameof(editable_item_state), EditableItemState.Uncommitted); @@ -113,6 +118,22 @@ namespace bts.shell.manual_fills { public TickDisplaySettingsImmutable quantity_display => _quantity_display.Value; public double price { get => _price; set => _set(ref _price, value); } + /// + /// The trading date assigned to this fill. The time of day is retained so + /// that a fill entered for today continues to be classified as a day fill. + /// + public DateTime fill_date { + get => _timestamp.Date; + set { + var timestamp = value.Date + _timestamp.TimeOfDay; + if (_timestamp != timestamp) { + _timestamp = timestamp; + RaisePropertyChanged(nameof(fill_date)); + _data = null; + } + } + } + public DateTime? time_entered => data.value.manual_fill.HasTimestamp ? data.value.manual_fill.Timestamp.to_local_time() @@ -157,7 +178,8 @@ namespace bts.shell.manual_fills { Price = price, Side = side, Quantity = quantity, - SecurityKey = security?.Id ?? 0 + SecurityKey = security?.Id ?? 0, + Timestamp = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(_timestamp.ToUniversalTime()) }; public ManualFillTuple to_tuple() => diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillRowEditor.xaml b/src/client/spark/Modules/Trading/ManualFills/ManualFillRowEditor.xaml index a8687d8c9..b89b6d83f 100644 --- a/src/client/spark/Modules/Trading/ManualFills/ManualFillRowEditor.xaml +++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillRowEditor.xaml @@ -39,6 +39,8 @@ + + @@ -46,7 +48,7 @@ @@ -56,6 +58,7 @@ + + diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsView.xaml b/src/client/spark/Modules/Trading/ManualFills/ManualFillsView.xaml index 0a5bc7f22..f006f04cc 100644 --- a/src/client/spark/Modules/Trading/ManualFills/ManualFillsView.xaml +++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsView.xaml @@ -272,6 +272,23 @@ + + + + + + + + + + + + + +