add: date change for manual fills

This commit is contained in:
arham committed 2026-08-24 00:32:20 +00:00
1 parent eadd6a0706
commit 4d4b2cf967
5 files changed
+67 -7

No files matched your search

@@ -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<ManualFill>(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);
@@ -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); }
/// <summary>
/// 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.
/// </summary>
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() =>
@@ -39,6 +39,8 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush}}"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush}}"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
@@ -46,7 +48,7 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Rectangle
Grid.ColumnSpan="11"
Grid.ColumnSpan="13"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Fill="{u:BTSColor header}" />
@@ -56,6 +58,7 @@
<TextBlock Grid.Column="6" Text="Side" Style="{StaticResource HeaderText}"/>
<TextBlock Grid.Column="8" Text="Qty" Style="{StaticResource HeaderText}"/>
<TextBlock Grid.Column="10" Text="Price" Style="{StaticResource HeaderText}"/>
<TextBlock Grid.Column="12" Text="Date" Style="{StaticResource HeaderText}"/>
<c:ContractPickerPopup
Grid.Row="2"
@@ -88,6 +91,7 @@
TickDisplaySettings="{Binding quantity_display}"
Value="{Binding display_quantity}" />
<usp:PriceEntryControl Grid.Row="2" Grid.Column="10" MinWidth="55" Value="{Binding price}" ContractSpec="{Binding spec}"/>
<DatePicker Grid.Row="2" Grid.Column="12" SelectedDate="{Binding fill_date}" />
</Grid>
<c:DialogSkirt Grid.Row="1" Margin="0,6,0,0">
<c:DialogSkirt.RightItems>
@@ -272,6 +272,23 @@
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<!-- Trading Date -->
<DataGridTemplateColumn
c:DataGridEx.CellKey="{x:Static Date, MemberType={u:Nested usp:ManualFillsView.Columns}}"
Header="Date"
SortMemberPath="fill_date">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding fill_date, StringFormat={}{0:d}}" VerticalAlignment="Center" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding fill_date, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<!-- Time Entered -->
<DataGridTextColumn
c:DataGridEx.CellKey="{x:Static
@@ -31,6 +31,7 @@ namespace mbts.ui.spark {
Side,
Quantity,
Price,
Date,
TimeEntered
}