CME gen open time config and TimeFilter RadioButton item
This commit is contained in:
1 parent
70e264e693
commit
3ea77974d4
5 files changed
+59
-10
No files matched your search
@@ -14,6 +14,7 @@ namespace mbts.spark.filters {
|
||||
TimeFilterMode _mode;
|
||||
TimeTextTuple _begin, _end;
|
||||
DateTime? _begin_dt, _end_dt;
|
||||
readonly DateTime _cme_open = MarketSchedule.get_cme_gen_open();
|
||||
|
||||
public TimeFilterVM(Func<TRow, DateTime> get_row_val, string prop_name) : base(get_row_val, prop_name) =>
|
||||
_set_default_values();
|
||||
@@ -53,14 +54,20 @@ namespace mbts.spark.filters {
|
||||
protected override bool _filter(DateTime value) {
|
||||
switch (mode) {
|
||||
case TimeFilterMode.Today: return value.Date == DateTime.Today.Date;
|
||||
case TimeFilterMode.CMEOpen: return value >= _cme_open;
|
||||
case TimeFilterMode.Period: return (!_begin_dt.HasValue || value >= _begin_dt.Value) && (!_end_dt.HasValue || value <= _end_dt.Value);
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool _get_active() =>
|
||||
mode == TimeFilterMode.Today ||
|
||||
(mode == TimeFilterMode.Period && (_begin_dt.HasValue || _end_dt.HasValue));
|
||||
protected override bool _get_active() {
|
||||
switch (mode) {
|
||||
case TimeFilterMode.Today:
|
||||
case TimeFilterMode.CMEOpen: return true;
|
||||
case TimeFilterMode.Period: return _begin_dt.HasValue || _end_dt.HasValue;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override TimeFilterTuple get_state() =>
|
||||
new TimeFilterTuple(mode, _begin, _end);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls">
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Resources/Buttons.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
@@ -21,7 +22,8 @@
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<c:RadioButtonsControl
|
||||
ItemsSource="{u:EnumBindingSource c:TimeFilterMode}"
|
||||
ItemsSource="{x:Static c:TimeFilterControl.ModeItems}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding Mode, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
/>
|
||||
<Grid x:Name="PeriodRoot" Grid.Row="1" Margin="0,6,0,0" IsEnabled="False">
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using mbts.spark.filters;
|
||||
using mbts.ui.adorners;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -18,6 +20,15 @@ namespace mbts.ui.controls {
|
||||
public TimeFilterControl() =>
|
||||
new TimeFilterErrorAdorner(this);
|
||||
|
||||
public static IEnumerable<TimeFilterMode> ModeItems {
|
||||
get {
|
||||
yield return TimeFilterMode.Anytime;
|
||||
yield return TimeFilterMode.Today;
|
||||
yield return TimeFilterMode.CMEOpen;
|
||||
yield return TimeFilterMode.Period;
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ModeProperty = DependencyProperty.Register("Mode", typeof(TimeFilterMode), typeof(TimeFilterControl),
|
||||
new FrameworkPropertyMetadata(TimeFilterMode.Anytime, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
|
||||
public TimeFilterMode Mode { get => (TimeFilterMode)GetValue(ModeProperty); set => SetValue(ModeProperty, value); }
|
||||
@@ -60,6 +71,10 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
|
||||
public enum TimeFilterMode {
|
||||
Anytime, Today, Period
|
||||
Anytime,
|
||||
Today,
|
||||
Period,
|
||||
[Description("Glbx Open")]
|
||||
CMEOpen
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,11 @@ namespace mbts.spark {
|
||||
// trade date FIX 75 vs (FIX 336, FIX 341)
|
||||
public Dictionary<DateTime, List<(trading_session_state session_state, DateTime session_start_time)>> sessions;
|
||||
|
||||
static readonly double _cme_gen_open_hrs;
|
||||
static MarketSchedule() {
|
||||
var cme_schedule = config.Configuration.get<bts.md.CMETradingSchedule>();
|
||||
_cme_gen_open_hrs = cme_schedule?.gen_open_hour ?? 8.5;
|
||||
}
|
||||
// for object initializers
|
||||
public MarketSchedule() { }
|
||||
|
||||
@@ -47,6 +52,22 @@ namespace mbts.spark {
|
||||
} // get
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the CME general open time of the most recent trading date (i.e today, or last Friday if today is not a weekday).
|
||||
/// </summary>
|
||||
public static DateTime get_cme_gen_open() {
|
||||
var now = DateTime.Now;
|
||||
DateTime last_open = now.Date.AddHours(
|
||||
now.TimeOfDay.TotalHours > _cme_gen_open_hrs ?
|
||||
_cme_gen_open_hrs :
|
||||
_cme_gen_open_hrs - 24);
|
||||
switch (last_open.DayOfWeek) {
|
||||
case DayOfWeek.Saturday: last_open = last_open.AddDays(-1); break;
|
||||
case DayOfWeek.Sunday: last_open = last_open.AddDays(-2); break;
|
||||
}
|
||||
return last_open;
|
||||
}
|
||||
|
||||
public static DateTime get_utctimestamp_as_localtime(string s) {
|
||||
return DateTimeOffset.ParseExact(s, "yyyyMMddHHmmssffffff", null, System.Globalization.DateTimeStyles.AssumeUniversal).ToLocalTime().LocalDateTime;
|
||||
}
|
||||
|
||||
@@ -134,4 +134,8 @@ message RelayOptions {
|
||||
optional uint32 recovery_interval = 3 [default = 30000];
|
||||
}
|
||||
|
||||
|
||||
message CMETradingSchedule {
|
||||
// we can elaborate later, but for now it's very simple:
|
||||
// this is "hours after midnight, in Central Time"
|
||||
optional double gen_open_hour = 1 [default = 8.5]; // 8:30 am CT
|
||||
}
|
||||
Reference in new issue
Block a user