Compare commits

..
51 Commits
Author SHA1 Message Date
Jake Norbut 8e535b0303 SPARK-1391 - audit script now requires output_file specified in command line; by default, will no longer print to console but this can be toggled on via -c 2018-06-19 13:11:56 -05:00
Eric Harding 44887d80e6 sparkd web help indentation 2018-06-19 11:47:26 -04:00
Eric Harding bd63c0798e Merge branch 'prod' of bitbucket.org:bluetradesys/spark 2018-06-19 11:46:43 -04:00
Eric Harding 6e06b3566a Add logging on synthetic security update 2018-06-19 11:43:03 -04:00
Eric Harding ebc7432995 Add market data gap metric. 2018-06-19 11:43:03 -04:00
Eric Harding 33a1762cb7 Add sparkd web command for getting the web UI up in an emergency 2018-06-19 11:40:03 -04:00
Taha Afzal 16e9d100d2 n legged tests 2018-06-19 09:45:19 -04:00
Jake Norbut 5009c4c29a SPARK-1388 - round OB prices to 9 fractional digits when the security is not known 2018-06-19 08:29:20 -05:00
Pedro Pinto f4f1bb7914 Fixed log msg. 2018-06-18 20:56:07 +00:00
Pedro Pinto 82d3e59024 Removed unused config values. 2018-06-18 20:44:25 +00:00
Pedro Pinto 6fe59386df SPARK-1137, We have server performance numbers and they are good. 2018-06-18 20:44:25 +00:00
Pedro Pinto 767cb36856 Ran clang-format. 2018-06-18 20:44:25 +00:00
John Colvin 908958ea3c SPARK-1386 format futures/future-spread-legs with exchange desc (if present) 2018-06-18 15:46:32 -04:00
Taha Afzal bbf961ed78 fixing build, .fs file 2018-06-18 08:40:20 -04:00
Taha Afzal f3b8ce8088 adding location to CME User Data 2018-06-17 22:44:37 -04:00
Pedro Pinto 026bda165e Added more data to server side performance tracing. 2018-06-17 15:22:56 +00:00
Pedro Pinto 9727f17edf Tweaks to pp custom build environment. 2018-06-17 15:21:47 +00:00
Pedro Pinto 61b2913a31 Fixed clang build. 2018-06-17 15:21:04 +00:00
Pedro Pinto 0a8bee2c31 Added a couple more digits to exchange price encoding. 2018-06-15 09:51:07 -04:00
Pedro Pinto 2dd8e64272 Perf analysis tools. 2018-06-15 09:51:07 -04:00
John Colvin aa704b8c96 timefilter - make text input filter more flexible 2018-06-14 20:56:19 -04:00
John Colvin 8673b857a7 timefilter - triple-click selects all time-text 2018-06-14 19:56:09 -04:00
John Colvin f83f2c7964 SPARK-1348 time-based period filter requires textbox to lose focus to accept new value 2018-06-14 19:13:18 -04:00
Eric Harding 86d8d7dafb Add seconds_to_recenter and max_open_ladders to UI.conf. Remove seconds and ticks from LadderSettings as it should not be stored per-ladder. 2018-06-14 18:35:15 -04:00
Eric Harding 5363fdd0db Reduce logging level for non-errors in PersistenceServiceServer 2018-06-14 18:08:52 -04:00
Eric Harding d3e7870b9a Fix build with the #ifdef stick 2018-06-14 18:08:32 -04:00
Eric Harding f05692e441 Merged Metrics into qa 2018-06-14 17:38:58 -04:00
Eric Harding 053c460ff6 Market data rate metrics reborn 2018-06-14 17:13:19 -04:00
Eric Harding af7e9dd3a8 Raise WebServer GET request logging to DIAG level 2018-06-14 17:11:57 -04:00
Eric Harding 3e3b6acfd7 Market data QueryServer response time/size. 2018-06-14 17:11:57 -04:00
Eric Harding b75496e665 Add sparkd memory use metric 2018-06-14 17:11:57 -04:00
Eric Harding 03864caa09 Add HistogramMetric type 2018-06-14 17:11:57 -04:00
Eric Harding 1558b79c16 Sparkd promethius metrics 2018-06-14 17:11:57 -04:00
Kevin Darby 57bfe5a85e added manual test cases for algos 2018-06-14 14:50:20 -04:00
John Colvin 3eaeaf0f35 fix LadderSettings equals method 2018-06-14 12:50:02 -04:00
Michael Harding ab3121cd5d Spark Admin: Admin user hack 2018-06-14 11:43:01 -04:00
Taha Afzal ec5bd4a164 SPARK-1332 2018-06-14 11:22:11 -04:00
John Colvin 3877aec09a SPARK-1354 Can't change bid, ask, or last colors in ladder 2018-06-14 10:37:29 -04:00
Jake Norbut fb17596304 updating test text 2018-06-14 08:32:48 -05:00
Michael Harding b36bcc66fb Update PnL manual test 2018-06-14 09:26:53 -04:00
Taha Afzal 73189fbbd8 2 admin limit tests changed slightly 2018-06-13 19:18:04 -04:00
John Colvin 484a9dba12 orderticket priceentrycontrol - update binding source in tickup/down command if has keyboard focus 2018-06-13 17:27:53 -04:00
John Colvin 83f2866604 SPARK-1349 Order Ticket Price Field - DoubleClick 2018-06-13 17:27:53 -04:00
Pedro Pinto 37f40046da Fixed typo in CTI code enum. 2018-06-13 15:48:17 -04:00
Pedro Pinto 2401b9db77 Typo in log msg. 2018-06-13 15:48:17 -04:00
John Colvin a45546690c SPARK-1352 ladder - auto-clear should only reset size to 0 2018-06-13 15:41:20 -04:00
John Colvin bc394ee3b5 SPARK-1350 Fill Window Comes Up Blank From Orders Window 2018-06-13 15:30:55 -04:00
Michael Harding b917fba19a Spark Admin: Assign correct default symbol to new productLimits rows 2018-06-13 14:58:54 -04:00
Michael Harding 63106eb866 SPARK-1245: Wrap Clip Limits help onto two lines 2018-06-13 14:28:27 -04:00
Eric Harding fa79bddb6b Make Spark webserver pipe down a bit 2018-06-13 13:49:34 -04:00
Pedro Pinto 83851c1494 QA assignments. 2018-06-13 10:35:02 -04:00
83 changed files with 1223 additions and 357 deletions

No files matched your search

@@ -130,7 +130,7 @@ namespace mbts.spark {
protected override IEnumerable<SortingCriteria> get_default_sorting() { yield return new SortingCriteria(nameof(Row.fill_time), false); }
static IObservable<IIncrementalUpdate<FillTuple, FillTupleKey>> _get_observable(IBus bus, OrdersModel model, StartupData state) {
if (state.orders != null && state.orders.Length == 0) {
if (!state.orders.is_null_or_empty()) {
var orders_hash = new HashSet<uint>(state.orders);
return model.on_fill_tuples.filter(f => orders_hash.Contains(f.fill.OrderKey));
} else return model.on_fill_tuples;
@@ -30,8 +30,7 @@ namespace bts.shell {
_wm = wm;
_settings_hub = settings_hub;
_orders_model = orders_model;
var window_props = Configuration.get<bts.config.IShellWindowProps>();
_max_ladders_open = (int)(window_props?.ladder?.max_total_open ?? 75);
_max_ladders_open = (int)(Configuration.get<bts.config.LadderKnobs>().max_open_ladders);
_dispose = Disposable.Create(
bus.subscribe(SparkTags.SecuritiesTag).Subscribe(s => _securities = s),
bus.subscribe(SparkTags.ShowLadderTag).OnDispatcher().Subscribe(s => show_windows(new[] { s })),
@@ -3,6 +3,8 @@ using System.Collections.Generic;
namespace mbts.utils {
public static class EqualityComparer {
const int _hash_seed = 63607, _hash_multiplier = 6451;
public static IEqualityComparer<T> Create<T>(Func<T, T, bool> equals) =>
new AnonymousEqualityComparer<T>(equals);
@@ -29,7 +31,7 @@ namespace mbts.utils {
non_null_equals(x, y);
public static int aggregate_hash(int item1_hash, int item2_hash, int item3_hash) {
int rv = 63607;
int rv = _hash_seed;
unchecked {
_accumulate_hash(ref rv, ref item1_hash);
_accumulate_hash(ref rv, ref item2_hash);
@@ -38,9 +40,20 @@ namespace mbts.utils {
return rv;
}
// Note: be wary of the performance cost this method may have, as frequently creating large arrays can be expensive.
// If you wish to avoid this cost, consider making an overload like the method above, with the appropriate number of item-hash arguments
public static int aggregate_hash(params int[] item_hashes) {
int hash = _hash_seed;
unchecked {
foreach (int item_hash in item_hashes)
hash = hash * _hash_multiplier + item_hash;
}
return hash;
}
// WARNING: be sure to call this within in an unchecked scope
static void _accumulate_hash(ref int aggregate_hash, ref int item_hash) =>
aggregate_hash = aggregate_hash * 6451 + item_hash;
aggregate_hash = aggregate_hash * _hash_multiplier + item_hash;
private class AnonymousEqualityComparer<T> : IEqualityComparer<T> {
readonly Func<T, T, bool> _equals;
@@ -54,8 +54,9 @@ namespace mbts.ui {
public static TimeTextTuple FromTicks(long ticks) =>
FromDateTime(new DateTime(ticks));
public static TimeTextTuple FromDateTime(DateTime date_time) =>
new TimeTextTuple(DateTimeFormatInfo.CurrentInfo.AbbreviatedMonthNames[date_time.Month - 1], date_time.Day.ToString(), date_time.Year.ToString(), date_time.ToString("t"));
public static TimeTextTuple FromDateTime(DateTime date_time) => FromDateTime(date_time, "t");
public static TimeTextTuple FromDateTime(DateTime date_time, string time_format) =>
new TimeTextTuple(DateTimeFormatInfo.CurrentInfo.AbbreviatedMonthNames[date_time.Month - 1], date_time.Day.ToString(), date_time.Year.ToString(), date_time.ToString(time_format));
public TimeTextTuple(string month_text, string day_text, string year_text, string time_text) {
_month_text = month_text;
@@ -107,14 +108,23 @@ namespace mbts.ui {
static DateTime? _parse(string month_text, string day_text, string year_text, string time_text) {
DateTime? t = _parse(time_text);
TimeSpan? t = _parse_time(time_text);
if (t.HasValue) {
DateTime? d = _parse($"{month_text}/{day_text}/{year_text}");
if (d.HasValue) return d.Value.Date.AddDays(t.Value.TimeOfDay.TotalDays);
if (d.HasValue) return d.Value.Date.Add(t.Value);
}
return null;
}
static TimeSpan? _parse_time(string text) {
DateTime? dt = _parse(text);
if (dt.HasValue) {
return dt.Value.TimeOfDay;
} else if (TimeSpan.TryParse(text, out TimeSpan result) && result < TimeSpan.FromDays(1)) {
return result;
} else return null;
}
static DateTime? _parse(string text) {
if (!string.IsNullOrEmpty(text) && DateTime.TryParse(text, out DateTime result))
return result;
@@ -28,7 +28,14 @@
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource TickDisplayTwoWayConverter}, Mode=TwoWay}"
/>
>
<TextBox.CommandBindings>
<CommandBinding Command="{x:Static u:TextBoxBehavior.SelectAllCommand}" Executed="{x:Static u:TextBoxBehavior.SelectAllCommandExecutedHandler}"/>
</TextBox.CommandBindings>
<TextBox.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick" Command="{x:Static u:TextBoxBehavior.SelectAllCommand}"/>
</TextBox.InputBindings>
</TextBox>
</c:TickUpDown>
</ControlTemplate>
<Style TargetType="usp:PriceEntryControl">
@@ -47,24 +47,30 @@ namespace mbts.ui.spark {
#endregion
TextBox _text;
IDisposable _text_input_hook;
public PriceEntryControl() {
TickUpCommand = new DelegateCommand(_tick_up);
TickDownCommand = new DelegateCommand(_tick_down);
}
IDisposable _keyboard_focus_sub;
bool _has_keyboard_focus;
public override void OnApplyTemplate() {
Disposable.dispose(ref _keyboard_focus_sub);
_text = this.assert_template_child<TextBox>("_text");
Disposable.dispose(ref _text_input_hook);
_text_input_hook = _text.SubscribePreviewTextInput((s, e) => e.Handled = !RegexFilters.PriceInput.IsMatch(_text.PeekText(e)));
_keyboard_focus_sub = _text.SubscribeKeyboardFocus(val => _has_keyboard_focus = val);
_update_text_binding();
}
void _tick_up() {
if (_has_keyboard_focus) {
_text.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
}
double v = Value;
if (double.IsNaN(v)) SetCurrentValue(ValueProperty, TickDefaultValue);
else {
if (double.IsNaN(v)) {
SetCurrentValue(ValueProperty, TickDefaultValue);
} else {
var spec = ContractSpec;
if (spec.HasValue) SetCurrentValue(ValueProperty, spec.Value.tickup(v));
else SetCurrentValue(ValueProperty, TickDefaultValue);
@@ -72,9 +78,13 @@ namespace mbts.ui.spark {
}
void _tick_down() {
if (_has_keyboard_focus) {
_text.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
}
double v = Value;
if (double.IsNaN(v)) SetCurrentValue(ValueProperty, TickDefaultValue);
else {
if (double.IsNaN(v)) {
SetCurrentValue(ValueProperty, TickDefaultValue);
} else {
var spec = ContractSpec;
if (spec.HasValue) SetCurrentValue(ValueProperty, spec.Value.tickdown(v));
else SetCurrentValue(ValueProperty, TickDefaultValue);
@@ -23,38 +23,42 @@ namespace mbts.ui.controls {
}
protected override void OnPreviewKeyDown(KeyEventArgs e) {
switch (Keyboard.Modifiers) {
case ModifierKeys.None: {
switch (e.Key) {
case Key.Up:
TickUpCommand.TryExecuteIfCan(TickUpParameter);
e.Handled = true;
break;
case Key.Down:
TickDownCommand.TryExecuteIfCan(TickDownParameter);
e.Handled = true;
break;
if (EnableArrowKeyTick) {
switch (Keyboard.Modifiers) {
case ModifierKeys.None: {
switch (e.Key) {
case Key.Up:
TickUpCommand.TryExecuteIfCan(TickUpParameter);
e.Handled = true;
break;
case Key.Down:
TickDownCommand.TryExecuteIfCan(TickDownParameter);
e.Handled = true;
break;
}
}
}
break;
case ModifierKeys.Alt: {
// see: https://stackoverflow.com/questions/3099472/previewkeydown-is-not-seeing-alt-modifiers
switch (e.SystemKey) {
case Key.Up:
TickUpCommand.TryExecuteIfCan(TickUpAltParameter);
e.Handled = true;
break;
case Key.Down:
TickDownCommand.TryExecuteIfCan(TickDownAltParameter);
e.Handled = true;
break;
break;
case ModifierKeys.Alt: {
// see: https://stackoverflow.com/questions/3099472/previewkeydown-is-not-seeing-alt-modifiers
switch (e.SystemKey) {
case Key.Up:
TickUpCommand.TryExecuteIfCan(TickUpAltParameter);
e.Handled = true;
break;
case Key.Down:
TickDownCommand.TryExecuteIfCan(TickDownAltParameter);
e.Handled = true;
break;
}
}
}
break;
break;
}
}
base.OnPreviewKeyDown(e);
}
public bool EnableArrowKeyTick { get; set; } = true;
#region TickCommand
public ICommand TickCommand {
get { return (ICommand)GetValue(TickCommandProperty); }
@@ -31,8 +31,14 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<c:TickUpDown x:Name="PART_time_tick" Grid.Column="0" MinWidth="85" HorizontalAlignment="Stretch">
<TextBox x:Name="PART_time_text" Height="20" u:TextBoxBehavior.EnableArrowKeyTraverse="True" u:Behavior.DisablePaste="True"/>
<c:TickUpDown x:Name="PART_time_tick" Grid.Column="0" MinWidth="85" HorizontalAlignment="Stretch" EnableArrowKeyTick="False">
<TextBox x:Name="PART_time_text" Height="20" u:TextBoxBehavior.EnableArrowKeyTraverse="True" u:Behavior.DisablePaste="True">
<TextBox.InputBindings>
<KeyBinding Key="Up" Command="{x:Static c:DateTimePicker.TickTimeComponentCommand}" CommandParameter="{u:Int 1}"/>
<KeyBinding Key="Down" Command="{x:Static c:DateTimePicker.TickTimeComponentCommand}" CommandParameter="{u:Int -1}"/>
<u:CustomInputBinding Gesture="{x:Static u:InputGestures.LeftTripleClick}" Command="{x:Static u:TextBoxBehavior.SelectAllCommand}"/>
</TextBox.InputBindings>
</TextBox>
</c:TickUpDown>
<c:TickUpDown x:Name="PART_month_tick" Grid.Column="2" Width="50">
<TextBox x:Name="PART_month_text" Height="20" u:TextBoxBehavior.EnableArrowKeyTraverse="True" u:Behavior.DisablePaste="True"/>
@@ -3,6 +3,7 @@ using mbts.ui.shell;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
@@ -14,7 +15,9 @@ namespace mbts.ui.controls {
/// Interaction logic for DateTimePicker.xaml
/// </summary>
public class DateTimePicker : Control {
TimeTupleVM _vm;
public static readonly RoutedCommand TickTimeComponentCommand = new RoutedCommand();
DTPController _controller;
bool _suspend_notify_vm;
static DateTimePicker() =>
@@ -24,8 +27,8 @@ namespace mbts.ui.controls {
new FrameworkPropertyMetadata(default(TimeTextTuple), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnTimeTupleChanged));
static void OnTimeTupleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
var dtp = (DateTimePicker)d;
if (!dtp._suspend_notify_vm && dtp._vm != null)
dtp._vm.result = (TimeTextTuple)e.NewValue;
if (!dtp._suspend_notify_vm && dtp._controller != null)
dtp._controller.result = (TimeTextTuple)e.NewValue;
}
public TimeTextTuple TimeTuple { get => (TimeTextTuple)GetValue(TimeTupleProperty); set => SetValue(TimeTupleProperty, value); }
@@ -41,59 +44,74 @@ namespace mbts.ui.controls {
var time = this.assert_template_child<TickUpDown>("PART_time_tick");
var time_text = this.assert_template_child<TextBox>("PART_time_text");
if (_vm != null) _vm.PropertyChanged -= _vm_PropertyChanged;
_vm = new TimeTupleVM();
_vm.result = TimeTuple;
_vm.PropertyChanged += _vm_PropertyChanged;
if (_controller != null) _controller.PropertyChanged -= _vm_PropertyChanged;
_controller = new DTPController(time_text);
_controller.result = TimeTuple;
_controller.PropertyChanged += _vm_PropertyChanged;
time.CommandBindings.Add(new CommandBinding(TickTimeComponentCommand, (s, e) => {
_controller.tick_time_component((int)e.Parameter);
}));
time.CommandBindings.Add(new CommandBinding(TextBoxBehavior.SelectAllCommand, TextBoxBehavior.SelectAllCommandExecutedHandler));
const int delay = 500;
time.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_time") { Source = _vm });
time.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_time") { Source = _controller });
time.TickUpParameter = 1;
time.TickDownParameter = -1;
time.TickUpAltParameter = 60;
time.TickDownAltParameter = -60;
time_text.SetBinding(TextBox.TextProperty, new Binding("time_text") { Source = _vm, Delay = delay, ValidatesOnExceptions = true });
_hooks.Add(time_text.SubscribePreviewTextInput((s, e) =>
e.Handled = !MatchAny(time_text.PeekText(e), RegexFilters.Time.StandardTime, RegexFilters.Time.MilitaryTime)
));
time_text.SetBinding(TextBox.TextProperty, new Binding("time_text") { Source = _controller, Delay = delay, ValidatesOnExceptions = true });
_hooks.Add(time_text.SubscribePreviewTextInput((s, e) => {
string preview = time_text.PeekText(e);
if (RegexFilters.Time.StandardTimeOptionalSeconds.IsMatch(preview)) {
_controller.use_military_time = false;
} else if (RegexFilters.Time.MilitaryTimeOptionalSeconds.IsMatch(preview)) {
_controller.use_military_time = true;
} else {
e.Handled = true;
}
}));
month.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_month") { Source = _vm });
month.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_month") { Source = _controller });
month.TickUpParameter = 1;
month.TickDownParameter = -1;
month_text.SetBinding(TextBox.TextProperty, new Binding("month_text") { Source = _vm, Delay = delay });
month_text.SetBinding(TextBox.TextProperty, new Binding("month_text") { Source = _controller, Delay = delay });
_hooks.Add(month_text.SubscribePreviewTextInput((s, e) =>
e.Handled = !RegexFilters.Time.MonthAbbrev.IsMatch(month_text.PeekText(e))
));
day.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_day") { Source = _vm });
day.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_day") { Source = _controller });
day.TickUpParameter = 1;
day.TickDownParameter = -1;
day_text.SetBinding(TextBox.TextProperty, new Binding("day_text") { Source = _vm, Delay = delay });
day_text.SetBinding(TextBox.TextProperty, new Binding("day_text") { Source = _controller, Delay = delay });
_hooks.Add(day_text.SubscribePreviewTextInput((s, e) =>
e.Handled = !RegexFilters.Time.DaysInMonth.IsMatch(day_text.PeekText(e))
));
year.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_year") { Source = _vm });
year.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_year") { Source = _controller });
year.TickUpParameter = 1;
year.TickDownParameter = -1;
year_text.SetBinding(TextBox.TextProperty, new Binding("year_text") { Source = _vm, Delay = delay });
year_text.SetBinding(TextBox.TextProperty, new Binding("year_text") { Source = _controller, Delay = delay });
_hooks.Add(year_text.SubscribePreviewTextInput((s, e) =>
e.Handled = !RegexFilters.Time.Year.IsMatch(year_text.PeekText(e))
));
}
void _vm_PropertyChanged(object sender, PropertyChangedEventArgs e) {
if (e.PropertyName == nameof(TimeTupleVM.result)) {
if (e.PropertyName == nameof(DTPController.result)) {
_suspend_notify_vm = true;
TimeTuple = _vm.result;
TimeTuple = _controller.result;
_suspend_notify_vm = false;
}
}
private class TimeTupleVM : ViewModelBase {
// This is not exactly a view-model, bc it accesses the time TextBox directly so it can get/set the CaretIndex,
// which is used to determine which time-componenet - hh:mm:ss AM/PM - should be incremented/decremented via the up/down arrow-keys.
class DTPController : ViewModelBase {
readonly TextBox _time_text_box;
TimeTextTuple _result;
public TimeTupleVM() {
public DTPController(TextBox time_text_box) {
_time_text_box = time_text_box;
tick_time = new DelegateCommand<int>(_tick_time);
tick_month = new DelegateCommand<int>(_tick_month);
tick_day = new DelegateCommand<int>(_tick_day);
@@ -135,12 +153,52 @@ namespace mbts.ui.controls {
RaisePropertyChanged(nameof(month_text), nameof(day_text), nameof(year_text), nameof(time_text));
}
}
public bool use_military_time { get; set; }
public ICommand tick_time { get; }
public ICommand tick_month { get; }
public ICommand tick_day { get; }
public ICommand tick_year { get; }
string _time_format => use_military_time ? StringFormats.Time.MilitaryWithSeconds : StringFormats.Time.StandardWithSeconds;
public void tick_time_component(int increment) {
_ensure_time_text_up_to_date();
var r = _result.result;
if (r.HasValue) {
int index = _time_text_box.CaretIndex;
using (detect_property_changes()) {
DateTime dt;
if (index <= 0) {
dt = r.Value.AddHours(increment);
} else {
int segment = _time_text_box.Text.Take(index).Count(c => c == ':');
switch (segment) {
case 0: dt = r.Value.AddHours(increment); break;
case 1: dt = r.Value.AddMinutes(increment); break;
case 2:
if (_time_text_box.Text.Take(index).Contains(' ')) {
// toggle AM/PM
dt = r.Value.AddHours(r.Value.Hour < 12 ? 12 : -12);
} else {
dt = r.Value.AddSeconds(increment);
}
break;
default:
dt = r.Value.AddSeconds(increment);
break;
}
}
_result = TimeTextTuple.FromDateTime(dt, _time_format);
}
_time_text_box.CaretIndex = index;
} else {
using (detect_property_changes())
_force_valid_inputs();
}
}
void _tick_time(int increment) {
_ensure_time_text_up_to_date();
using (detect_property_changes()) {
var r = _result.result;
if (r.HasValue) {
@@ -187,6 +245,11 @@ namespace mbts.ui.controls {
}
}
}
void _ensure_time_text_up_to_date() {
if (_time_text_box.IsKeyboardFocused)
_time_text_box.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
}
void _force_valid_inputs() {
var dt = DateTime.Today.Date;
@@ -0,0 +1,16 @@
using System.Windows.Input;
namespace mbts.ui {
class CustomInputBinding : InputBinding { }
static class InputGestures {
public static readonly InputGesture LeftTripleClick = new LeftTripleClickGesture();
class LeftTripleClickGesture : InputGesture {
public override bool Matches(object targetElement, InputEventArgs inputEventArgs) =>
inputEventArgs is MouseButtonEventArgs mouse_args &&
mouse_args.ChangedButton == MouseButton.Left &&
mouse_args.ClickCount == 3;
}
}
}
@@ -7,7 +7,14 @@ using System.Windows.Input;
namespace mbts.ui {
static class TextBoxBehavior {
public static readonly RoutedCommand ReleaseCaptureCommand = new RoutedCommand();
#region RoutedCommands/Handlers
public static readonly RoutedCommand
ReleaseCaptureCommand = new RoutedCommand(),
SelectAllCommand = new RoutedCommand();
public static readonly ExecutedRoutedEventHandler SelectAllCommandExecutedHandler =
new ExecutedRoutedEventHandler((s, e) => (e.OriginalSource as TextBox ?? e.Source as TextBox ?? s as TextBox)?.SelectAll());
#endregion
#region SelectAllOnFocus
@@ -168,7 +175,7 @@ namespace mbts.ui {
public static void SetInputFilter(DependencyObject d, TextBoxInputFilter value) => d.SetValue(InputFilterProperty, value);
#endregion
#region
#region IncrementDecrementOnMouseClick
public static readonly DependencyProperty IncrementDecrementOnMouseClickProperty = DependencyProperty.RegisterAttached(
"IncrementDecrementOnMouseClick", typeof(bool), typeof(TextBoxBehavior), new PropertyMetadata(false, IncrementDecrementOnMouseClickPropertyChanged)
);
@@ -2,11 +2,28 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
namespace mbts.ui {
static class TextElementHelper {
public static IDisposable SubscribeKeyboardFocus(this TextBox text_box, Action<bool> callback) {
text_box.GotKeyboardFocus += on_got_keyboard_focus;
text_box.LostKeyboardFocus += on_lost_keyboard_focus;
return Disposable.Create(() => {
text_box.GotKeyboardFocus -= on_got_keyboard_focus;
text_box.LostKeyboardFocus -= on_lost_keyboard_focus;
});
void on_got_keyboard_focus(object sender, KeyboardFocusChangedEventArgs e) {
if (e.NewFocus == text_box)
callback(true);
}
void on_lost_keyboard_focus(object sender, KeyboardFocusChangedEventArgs e) {
if (e.OldFocus == text_box)
callback(false);
}
}
namespace mbts.ui
{
public class TextElementHelper
{
public static void GetTargetProperty(DependencyObject d, out FrameworkElement text_element, out DependencyProperty text_property) {
text_element = (FrameworkElement)d;
if (text_element is TextBox) text_property = TextBox.TextProperty;
@@ -533,6 +533,7 @@ namespace mbts.spark {
_visualHost.AddVisualChild(_mid_mkt_break_vis);
_visualHost.AddVisualChild(_ask_mkt_break_vis);
_visualHost.AddVisualChild(_bid_mkt_break_vis);
_render_grid_background();
_init_tactile_adorner();
// this effectively sets the background of the "Last" column
if (_scrollViewer != null) {
@@ -1,5 +1,6 @@
using bts.api.orderman;
using mbts.ui;
using mbts.utils;
using ProtoBuf;
using System;
using System.Linq;
@@ -124,8 +125,6 @@ namespace mbts.spark {
last_column = last_column,
calculator_buttons = new[] { 1, 5, 10, 25, 50, 100 },
scroll_bar_visible = false,
ticks_to_recenter = 10,
seconds_to_recenter = 300,
default_order_type = CustomOrderDefinition.CustomOneofCase.Limit,
default_time_in_force = TimeInForce.Day,
animate_recenter = true,
@@ -163,10 +162,8 @@ namespace mbts.spark {
public int[] calculator_buttons { get; set; }
[ProtoMember(10)]
public bool scroll_bar_visible { get; set; }
[ProtoMember(11)]
public int ticks_to_recenter { get; set; }
[ProtoMember(12)]
public int seconds_to_recenter { get; set; }
// USED [ProtoMember(11)]
// USED [ProtoMember(12)]
[ProtoMember(13)]
public CustomOrderDefinition.CustomOneofCase default_order_type { get; set; }
[ProtoMember(14)]
@@ -197,11 +194,8 @@ namespace mbts.spark {
other.price_column.safe_equals(price_column) &&
other.calculator_buttons.safe_equals(calculator_buttons, (a, b) => a.SequenceEqual(b)) &&
other.scroll_bar_visible == scroll_bar_visible &&
other.ticks_to_recenter == ticks_to_recenter &&
other.seconds_to_recenter == seconds_to_recenter &&
other.default_order_type == default_order_type &&
other.default_time_in_force == default_time_in_force &&
other.seconds_to_recenter == seconds_to_recenter &&
other.size == size &&
other.animate_recenter == animate_recenter &&
other.badge_style == badge_style &&
@@ -213,26 +207,24 @@ namespace mbts.spark {
public override bool Equals(object obj) => Equals(obj as LadderSettings);
public override int GetHashCode() =>
row_height.GetHashCode() +
grid_line_color.GetHashCode() +
orders_column.GetHashCode() +
bid_column.GetHashCode() +
ask_column.GetHashCode() +
price_column.GetHashCode() +
last_column.GetHashCode() +
calculator_buttons.GetHashCode() +
scroll_bar_visible.GetHashCode() +
ticks_to_recenter.GetHashCode() +
seconds_to_recenter.GetHashCode() +
default_order_type.GetHashCode() +
default_time_in_force.GetHashCode() +
seconds_to_recenter.GetHashCode() +
size.GetHashCode() +
animate_recenter.GetHashCode() +
badge_style.GetHashCode() +
bid_break_line.GetHashCode() +
ask_break_line.GetHashCode() +
mid_break_line.GetHashCode() +
alternate_order_size.GetHashCode();
EqualityComparer.aggregate_hash(
row_height.GetHashCode(),
grid_line_color.GetHashCode(),
orders_column.GetHashCode(),
bid_column.GetHashCode(),
ask_column.GetHashCode(),
price_column.GetHashCode(),
last_column.GetHashCode(),
calculator_buttons.GetHashCode(),
scroll_bar_visible.GetHashCode(),
default_order_type.GetHashCode(),
default_time_in_force.GetHashCode(),
size.GetHashCode(),
animate_recenter.GetHashCode(),
badge_style.GetHashCode(),
bid_break_line.GetHashCode(),
ask_break_line.GetHashCode(),
mid_break_line.GetHashCode(),
alternate_order_size.GetHashCode());
}
}
+5 -15
View File
@@ -16,8 +16,6 @@ using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using mbts.utils;
using mbts.spark.utilities;
namespace mbts.spark {
class LadderVM : DisposableViewModelBase, IKeyListener {
@@ -25,7 +23,7 @@ namespace mbts.spark {
readonly LadderModel _model;
readonly Property<double> _high, _low, _change, _open, _settlement;
readonly Property<ulong> _volume;
readonly Property<bool> _revert;
readonly Property<bool> _auto_clear;
readonly Property<Brush> _bid_background, _bid_foreground, _ask_background, _ask_foreground;
IWindowSettingsManager<LadderSettings> _settings_manager;
ulong _misc_time = 0;
@@ -44,7 +42,7 @@ namespace mbts.spark {
_open = backing(nameof(open), double.NaN);
_settlement = backing(nameof(settlement), double.NaN);
_volume = backing(nameof(volume), 0ul);
_revert = backing(nameof(revert), false);
_auto_clear = backing(nameof(auto_clear), false);
_status = backing(nameof(status_message), "");
_status_brush = backing(nameof(status_background), (Brush)BTSColors.UI.spark_menu_background);
// brush props
@@ -176,7 +174,7 @@ namespace mbts.spark {
public double open => _open.Value;
public double settlement => _settlement.Value;
public ulong volume => _volume.Value;
public bool revert { get => _revert.Value; set => _revert.set(value); }
public bool auto_clear { get => _auto_clear.Value; set => _auto_clear.set(value); }
public CalculatorLogic size_calculator { get; }
public OrderPropertiesEditorVM order_properties_vm { get; }
public ObservableCollection<LadderOrderVM> orders { get; }
@@ -232,16 +230,8 @@ namespace mbts.spark {
uint size = args.size_from_alternate ? s.alternate_order_size : (uint)Math.Abs(size_calculator.value.Value);
await _model.order_gateway.send_order(order, args.price, size);
if (revert) {
size_calculator.value = s.size;
if (order_properties_vm.selected_time_in_force != s.default_time_in_force && order_properties_vm.time_in_forces.Contains(s.default_time_in_force))
order_properties_vm.selected_time_in_force = s.default_time_in_force;
foreach (var ot in order_properties_vm.order_types) {
ot.load_from(_model.order_gateway.factory.custom_order(ot.order_type));
if (ot.order_type == s.default_order_type)
order_properties_vm.selected_order_type = ot;
}
}
if (auto_clear)
size_calculator.value = 0;
}
}
@@ -394,7 +394,7 @@
</ItemsControl>
<Button Margin="2" HorizontalAlignment="Stretch" Command="{Binding size_calculator.clear}">Clear</Button>
<!-- reset to defaults after order -->
<CheckBox Margin="2" IsChecked="{Binding revert}">Auto Clear</CheckBox>
<CheckBox Margin="2" IsChecked="{Binding auto_clear}">Auto Clear</CheckBox>
</StackPanel>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
@@ -17,16 +17,17 @@ namespace mbts.spark {
};
SecurityImmutable? _security;
MDConsumerHandle _handle;
LadderSettings _settings;
DateTime _last_recenter = DateTime.MaxValue;
double _last_mid = 0.0;
IDisposable _dispose;
readonly TimeSpan _seconds_to_center;
public RecenterCountdown() {
DataContextChanged += RecenterCountdown_DataContextChanged;
Unloaded += (o,e) => on_unload(false);
_timer.Tick += _timer_Tick;
_timer.Start();
_seconds_to_center = TimeSpan.FromSeconds(config.Configuration.get<bts.config.LadderKnobs>().seconds_to_recenter);
}
static (double,double) tick_range(double price, int tick_count, ContractSpecificationImmutable spec) {
@@ -34,11 +35,10 @@ namespace mbts.spark {
}
private void _timer_Tick(object sender, EventArgs e) {
if (_settings != null && _security != null) {
if (_security != null) {
var mid = _handle.mid();
(double low, double high) = tick_range(_last_mid, _settings.ticks_to_recenter, _security.Value.ContractSpec);
if (//mid < low || mid > high ||
(_last_recenter + TimeSpan.FromSeconds(_settings.seconds_to_recenter) < DateTime.UtcNow)) {
(_last_recenter + _seconds_to_center < DateTime.UtcNow)) {
trigger_recenter(mid);
}
}
@@ -59,7 +59,6 @@ namespace mbts.spark {
vm.OnDisposed += on_unload;
_dispose =
Disposable.Create(
vm.settings.Subscribe(s => _settings = s),
Disposable.Create(() => vm.OnDisposed -= on_unload));
}
}
@@ -12,6 +12,8 @@ using OrderStatus = bts.api.orderman.OrderStatus;
namespace mbts.spark {
partial class CVOrderBookRowVM : DisposableViewModelBase, IEquatable<CVOrderBookRowVM>, ui.controls.DIYGrid.IRowVM, ui.controls.DIYGrid.IActionableRowVM {
const string _unknown_security_price_format_string = "0.#########";
const int _unknown_security_price_num_fractional_digits = 9;
readonly CVOrderBookVM _book_vm;
readonly OrdersModel _model;
readonly Property<bool> _visible, _expanded, _passes_filter;
@@ -74,7 +76,8 @@ namespace mbts.spark {
_status_store = CellFactory.create(this, _book_vm.columns.status_column, nameof(status), r => _order.status(), r => r._status_store);
_last_msg_store = CellFactory.create(this, _book_vm.columns.last_message_column, nameof(last_msg), r => _order.last_msg(), r => r._last_msg_store);
//
string format_price(double v) => _security.HasValue ? _security.Value.ContractSpec.format(v) : v.ToString();
string format_price(double v) => _security.HasValue ? _security.Value.ContractSpec.format(v) :
Math.Round(v, _unknown_security_price_num_fractional_digits, MidpointRounding.AwayFromZero).ToString(_unknown_security_price_format_string);
string format_date(DateTime v) => $"{v:M/d} {v:h:mm:ss.fff tt}";
string format_sub_type(OrderSubType v) {
switch (v) {
@@ -10,7 +10,7 @@ namespace mbts.spark {
static readonly TimeSpan default_interval;
static WorkLoop() {
var timer_params = config.Configuration.get<bts.config.LadderTimerParams>();
var timer_params = config.Configuration.get<bts.config.LadderKnobs>();
default_priority = Enum.TryParse(timer_params.priority, true, out DispatcherPriority p) ? p : DispatcherPriority.ApplicationIdle;
default_interval = TimeSpan.FromMilliseconds(timer_params.interval_ms);
}
@@ -130,12 +130,22 @@ namespace mbts.ui.utility.text {
public static class Time {
public static readonly Regex
StandardTime = new Regex(@"^((0?[0-9])|(1?[0-2]?))(:?|:([0-5]?|[0-5][0-9]?)) ?(?i)((a|p)m?)?$"),
StandardTimeOptionalSeconds = new Regex(@"^((\d?|0\d|1[0-2])|((\d|0\d|1[0-2])(:?|(:([0-5]?|[0-5]\d(( ?|( ([aApP]?|[aApP][mM])))(:?|(: ?)|(: [aApP]?[mM]?)|(:[0-5]?\d? ?[aApP]?[mM]?))|:([0-5]?|([0-5]\d( ?|( ([aApP]?|([aApP][mM]))))))))))))$"),
MilitaryTime = new Regex(@"^(([0-1]?[0-9])|(2?[0-3]?))(:?|:([0-5]?|[0-5][0-9]?))$"),
MilitaryTimeOptionalSeconds = new Regex(@"^((\d?|[0-1]\d|2[0-3])|((\d|[0-1]\d|2[0-3])(:?|(:([0-5]?|[0-5]\d(:?|:([0-5]?|[0-5]\d)))))))$"),
DaysInMonth = new Regex(@"^([0-9]?|[0-2][0-9]|3[0-1])?$"),
MonthAbbrev = new Regex(@"^(?i)(a(ug?|pr?)?|d(e|ec)?|f(e?b)?|j(an?|u[nl]?)?|m(a[ry]?)?|(o(ct?)?)|s(ep?)?|n(ov?)?)?$"),
Year = new Regex(@"^\d{0,4}$"),
TimeSpan = new Regex(@"^(\d+(:?|:([0-5]?|[0-5]\d(:?|:([0-5]?|[0-5]\d)))))?$");
}
}
public static class StringFormats {
public static class Time {
public const string
MilitaryWithSeconds = "HH:mm:ss",
StandardWithSeconds = "hh:mm:ss tt";
}
}
}
}
@@ -1,18 +1,18 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.Collections.Generic;
using static bts.api.Security;
namespace bts.api {
struct FutureLeg {
public readonly Venue exchange;
public readonly string symbol;
public readonly string symbol, exchange_desc;
public readonly FutureContractImmutable future;
public readonly int quantity;
public FutureLeg(Venue exchange, string symbol, FutureContractImmutable future, int quantity) {
public FutureLeg(Venue exchange, string symbol, string exchange_desc, FutureContractImmutable future, int quantity) {
this.exchange = exchange;
this.symbol = symbol;
this.exchange_desc = exchange_desc;
this.future = future;
this.quantity = quantity;
}
@@ -32,12 +32,14 @@ namespace bts.api {
return string.Join("", _format_future_legs(future_legs));
}
public static string format_future(string symbol, FutureContractImmutable future) =>
$"{symbol}{DateFormatter.Format(future.ExpirationYear, future.ExpirationMonth, future.ExpirationDay, DateFormat.MonthCodeLastDigitYear)}";
public static string format_future(string symbol, string exch_desc, FutureContractImmutable future) =>
string.IsNullOrEmpty(exch_desc) ?
$"{symbol}{DateFormatter.Format(future.ExpirationYear, future.ExpirationMonth, future.ExpirationDay, DateFormat.MonthCodeLastDigitYear)}" :
exch_desc;
static string _format(SecurityImmutable security) {
switch (security.ContractCase) {
case ContractOneofCase.Future: return format_future(security.Symbol, security.Future);
case ContractOneofCase.Future: return format_future(security.Symbol, security.glbx_desc(), security.Future);
case ContractOneofCase.Spread:
if (security.HasGlbx) {
// In case we ever bring it back, pretty printed spread names can be found here:
@@ -61,7 +63,7 @@ namespace bts.api {
}
static string _get_first_leg_name(FutureLeg fl) {
string sym_exp_name = format_future(fl.symbol, fl.future);
string sym_exp_name = format_future(fl.symbol, fl.exchange_desc, fl.future);
switch (fl.quantity) {
case 1: return sym_exp_name;
case -1: return $"-{sym_exp_name}";
@@ -70,7 +72,7 @@ namespace bts.api {
}
static string _get_subsequent_leg_name(FutureLeg fl) {
string sym_exp_name = format_future(fl.symbol, fl.future);
string sym_exp_name = format_future(fl.symbol, fl.exchange_desc, fl.future);
switch (fl.quantity) {
case 1: return $"+{sym_exp_name}";
case -1: return $"-{sym_exp_name}";
@@ -19,7 +19,7 @@ namespace bts.api {
foreach (var l in legs) {
switch (l.Security.ContractCase) {
case ContractOneofCase.Future:
yield return new FutureLeg(l.Security.Exchange, l.Security.Symbol, l.Security.Future, qty * l.SignedQuantity());
yield return new FutureLeg(l.Security.Exchange, l.Security.Symbol, l.Security.glbx_desc(), l.Security.Future, qty * l.SignedQuantity());
break;
case ContractOneofCase.Spread:
foreach (var fl in _get_flat_future_legs(l.Security.Spread.Legs, qty * l.SignedQuantity()))
@@ -56,6 +56,9 @@ namespace bts.api {
public static string DisplayExchange(this SecurityImmutable security) =>
security.ContractCase == ContractOneofCase.Synthetic ? $"[{string.Join(",", get_flat_future_legs(security).Select(flt => flt.exchange.ToString()).Distinct().OrderBy(e => e))}]" : security.Exchange.ToString();
public static string glbx_desc(this SecurityImmutable security) =>
security.HasGlbx ? security.Glbx.SecurityDesc ?? string.Empty : string.Empty;
#endregion
public static class Comparer {
@@ -901,7 +901,7 @@ bool AdminServiceUtils::match_security_scope (const bts::api::admin::SecuritySco
bool AdminServiceUtils::match_product_scope (const bts::api::admin::ProductScope& scope,
const bts::api::Product& product){
return product.exchange() == scope.exchange() &&
product.type() && scope.security_type() &&
product.type() == scope.security_type() &&
_match_limit_rule_symbol(product.symbol(), scope.security_symbol());
}
bool AdminServiceUtils::match_product(const api::Security& security,
+1
View File
@@ -263,6 +263,7 @@ message CMEUserData{
map<string, string> misc_tags = 60;
string smp_instruction = 70;
string max_order_rate_per_connection = 80;
string location = 90;
}
message CMEUserMarketDataEntitlementData{
+1 -1
View File
@@ -233,7 +233,7 @@ enum CTICode {
CTI_CODE_CTI_CODE1 = 49;
CTI_CODE_CTI_CODE2 = 50;
CTI_CODE_CTI_CODE3 = 51;
CTI_CODE_CTI4 = 52;
CTI_CODE_CTI_CODE4 = 52;
}
enum NativeOrderStatus
+5 -17
View File
@@ -28,20 +28,6 @@ message IShellModuleProps
repeated ModuleProps module = 1;
}
message IShellWindowProps {
// TODO: Maybe IWindowManager should be responsible for total-windows-open limits?
// To achieve that we would need to use a sort of type-windowprops map.
// However, that makes the problem more complicated, and at this point we are just aiming to limit n_ladders open.
// So for now, just let the LadderWindowFactory manage this.
message WindowProps {
// NOTE: 50 will be a dangerously high default for most other windows (than Ladder),
// so be careful if you add other WindowProps members.
optional uint32 max_total_open = 1 [default = 50];
}
optional WindowProps ladder = 1;
}
message GridSettings {
optional string font_family = 1 [default = "Calibri"];
optional float font_size = 2 [default = 10];
@@ -62,9 +48,11 @@ message ShellLimits {
optional uint64 limit_group_memory_mb = 3;
}
// priorities (ordered): SystemIdle, ApplicationIdle, ContextIdle, Background, Input, Loaded, Render, DataBind, Normal, Send
// It seems like all priorities higher than ApplicationIdle choke the main thread.
message LadderTimerParams {
message LadderKnobs {
// priorities (ordered): SystemIdle, ApplicationIdle, ContextIdle, Background, Input, Loaded, Render, DataBind, Normal, Send
// It seems like all priorities higher than ApplicationIdle choke the main thread.
optional string priority = 1 [default = "ApplicationIdle"];
optional double interval_ms = 2 [default = 100];
optional uint32 seconds_to_recenter = 3 [default = 300];
optional uint32 max_open_ladders = 4 [default = 75];
}
-2
View File
@@ -71,8 +71,6 @@ message JetFIX {
optional bool log_fix_stream = 260 [default=false];
optional bool use_persisted_quote_ids = 270 [default=true];
optional uint32 quote_id_reservation_size = 290 [default=100000];
optional uint32 poll_period_ms = 300 [default=100];
optional bool use_dedicated_core = 310 [default=false];
optional uint32 cme_market_segment_id = 320 [default=0];
optional string trading_session_id = 330 [default=""];
+2 -1
View File
@@ -52,7 +52,8 @@ string dump_header(const ColdHeader& header) {
res << "'coconut_status_count': " << header.coconut_status_count << ", ";
res << "'exchange_status_count': " << header.exchange_status_count << ", ";
res << "'rfq_count': " << header.rfq_count << ", ";
res << "'customer_bbo_count': " << header.customer_bbo_count;
res << "'gaps':" << header.gap_count << ", ";
// res << "'customer_bbo_count': " << header.customer_bbo_count;
res << "}";
return res.str();
}
+3
View File
@@ -930,6 +930,9 @@ size_t MDConsumerChannel::rfq_count() const {
size_t MDConsumerChannel::customer_bbo_count() const {
return _pimpl->cold_header().customer_bbo_count;
}
size_t MDConsumerChannel::gap_count() const {
return _pimpl->cold_header().gap_count;
}
bool is_heart_beat_ok(const ColdHeader &header ) {
uint32_t s_heartbeat_ms = header.heartbeat_ms;
+1
View File
@@ -92,6 +92,7 @@ public:
size_t trade_count() const;
size_t rfq_count() const;
size_t customer_bbo_count() const;
size_t gap_count() const;
};
+2
View File
@@ -84,6 +84,7 @@ public:
SecurityType type() const { return _type; }
Venue exchange() const { return _exchange; }
bool has_depth() { return _cold.header().has_depth; }
void gap() { _cold.header().gap_count++; }
private:
BTS_NO_COPY(MDProducerImpl);
@@ -168,6 +169,7 @@ MDProducerChannel::MDProducerChannel(MDProducerImpl& impl) : _me(&impl) {}
void MDProducerChannel::heartbeat() {_me->heartbeat();}
void MDProducerChannel::add_trade(const co2::TradeMessage& trade) {_me->add_trade(trade);}
void MDProducerChannel::add_rfq(const co2::QuoteRequestMessage& rfq) {_me->add_rfq(rfq);}
void MDProducerChannel::gap() { _me->gap(); }
}}//namespace
+1
View File
@@ -18,6 +18,7 @@ public:
void heartbeat();
void add_trade(const co2::TradeMessage& trade);
void add_rfq(const co2::QuoteRequestMessage& rfq);
void gap();
};
}}
+1
View File
@@ -114,6 +114,7 @@ struct ALIGNED_(CACHE_LINE) ColdHeader {
std::atomic<size_t> exchange_status_count;
std::atomic<size_t> rfq_count;
std::atomic<size_t> customer_bbo_count;
std::atomic<size_t> gap_count;
// Ring buffer for LastTrade for all securities in this list
uint8_t trade_buffer[1024*1024]; //1mb
+1
View File
@@ -172,6 +172,7 @@ void SyntheticSecurityService::update_security_metadata(
_me->on_metadata.publish(request);
_me->metadata_publisher.add_or_update(request);
_me->metadata_publisher.flush();
LOG(md, Info, "Update synthetic security key={} response={}", key, UpdateResult::Error_Name(result.error()));
reply(result);
}
+60 -21
View File
@@ -15,6 +15,9 @@
#include "lib/api/apicore.pb.h"
#include "lib/api/services/MarketDataRelay.server.pb.h"
#include "lib/api/public/ServiceContext.h"
#ifndef _WIN32
#include "server/sparkd/metrics/metrics.h"
#endif
#include <vector>
#include <list>
@@ -61,13 +64,31 @@ struct DatedHandle {
struct MDConsumerGroup {
// probably just have to send the consumer in from outside
MDConsumerGroup(const UserSymbol& symbol, const MDConsumer& consumer) :
MDConsumerGroup(const UserSymbol& symbol, const MDConsumer& consumer, metrics::MetricsContainer& stats) :
symbol(symbol),
platform(platform_for_exchange(symbol.exchange())),
channel(consumer.get_channel(symbol)),
handles()
{
set_consumer(consumer);
// create and publish a stat for this group
#ifndef _WIN32
if (symbol.type() != SecurityType::SECURITYTYPE_SYNTHETIC) {
std::vector<metrics::Label> labels;
labels.push_back({ "symbol", symbol.symbol() });
labels.push_back({ "type", SecurityType_Name(symbol.type()).substr(13) /*SECURITYTYPE_*/ });
labels.push_back({ "exch", Venue_Name(symbol.exchange()).substr(6) /*VENUE_*/ });
stats.publish(
std::make_shared<metrics::LazyCounterMetricL>("spark_md_book_updates", [=]() { return std::max(channel.bbo_count(), channel.depth_count()); }, labels));
stats.publish(
std::make_shared<metrics::LazyCounterMetricL>("spark_md_security_count", [=]() { return channel.security_count(); }, labels));
stats.publish(
std::make_shared<metrics::LazyCounterMetricL>("spark_md_trade_count", [=]() { return channel.trade_count(); }, labels));
stats.publish(
std::make_shared<metrics::LazyCounterMetricD>("spark_md_gap_count", [=]() { auto g = channel.gap_count(); return g == 0 ? os::nan() : g; }, labels));
}
#endif
}
MDConsumerGroup(const MDConsumerGroup& other) = delete;
@@ -109,6 +130,7 @@ void set_price(PriceSize ps, co2::TradeMessage* ptrade) {
ptrade->set_exponent(ps.exponent());
ptrade->set_size(ps.size());
}
void copy_misc(MiscData misc, co2::MiscMessage* pmisc) {
pmisc->set_settlement_price(misc.settlement_price);
pmisc->set_settlement_date(misc.settlement_date.to_short());
@@ -134,14 +156,14 @@ class QueryServerImpl : public IQueryServer {
boost::container::flat_map<UserSymbol,shared_ptr<MDConsumerGroup>> _groups;
public:
QueryServerImpl(const std::set<UserSymbol>& symbols, std::shared_ptr<api::ISyntheticSecurityService>& ss) :
QueryServerImpl(const std::set<UserSymbol>& symbols, std::shared_ptr<api::ISyntheticSecurityService>& ss, metrics::MetricsContainer& stats) :
_consumer(symbols, ss),
_symbols(symbols),
_ss(ss),
_groups()
{
for (const auto& sym : symbols) {
_groups.emplace(std::make_pair(sym, std::make_unique<MDConsumerGroup>(sym, _consumer)));
_groups.emplace(std::make_pair(sym, std::make_unique<MDConsumerGroup>(sym, _consumer, stats)));
}
_groups.shrink_to_fit();
@@ -336,24 +358,36 @@ public:
struct MDRelayServer : bts::co2::MarketDataRelayBase {
const QueryServerImpl& _db;
utils::Dispatcher& _threadpool;
MDRelayServer(const QueryServerImpl& db, utils::Dispatcher& threadpool, bts::api::ServiceContext ctx) :
#ifndef _WIN32
std::shared_ptr<metrics::HistogramMetric<5>> _time,_size;
#endif
MDRelayServer(const QueryServerImpl& db, utils::Dispatcher& threadpool, bts::api::ServiceContext ctx, metrics::MetricsContainer& stats) :
bts::co2::MarketDataRelayBase(ctx),
_db(db), _threadpool(threadpool)
{ }
#ifndef _WIN32
, _time(std::make_shared<metrics::HistogramMetric<5>>("spark_qserver_response_time_ms", std::array<double,5>({ 1.0, 10.0, 100.0, 500.0, 1000.0 }))),
_size(std::make_shared<metrics::HistogramMetric<5>>("spark_qserver_size_bytes", std::array<double,5>({ 1024 /*kb*/, 1024*1024 /*mb*/, (1024*1024)*4, (1024*1024)*16, (1024*1024)*32 })))
{
stats.publish(_time);
stats.publish(_size);
}
#else
{}
#endif
virtual void requestmd(const MDRequest & request, const std::function<void(const MDReply&)>& reply) override {
TimeStamp start = TimeStamp::now();
_threadpool.post([=]() {
google::protobuf::Arena arena;
MDReply* preply = google::protobuf::Arena::CreateMessage<MDReply>(&arena);
TimeStamp start = TimeStamp::now();
_db.query(request, preply);
auto elapsed = (TimeStamp::now() - start);
LOG(md, Diag,
"Request for: {} took {}us and returned {} bytes before compression",
request.host(),
elapsed.microseconds(),
preply->ByteSize());
reply(*preply);
auto elapsed = (TimeStamp::now() - start);
#ifndef _WIN32
_time->observe(elapsed.milliseconds());
_size->observe(preply->ByteSize());
#endif
});
}
@@ -382,11 +416,15 @@ struct MDRelayServer : bts::co2::MarketDataRelayBase {
};
struct QueryServer {
QueryServer(std::set<UserSymbol> symbols, utils::Dispatcher& threadpool, const bts::api::ServiceContext& ctx, std::shared_ptr<api::ISyntheticSecurityService>& ss):
db(symbols, ss),
relay(db, threadpool, ctx),
security_timer(),
health_timer()
QueryServer(std::set<UserSymbol> symbols,
utils::Dispatcher& threadpool,
const bts::api::ServiceContext& ctx,
std::shared_ptr<api::ISyntheticSecurityService>& ss,
metrics::MetricsContainer& stats):
db(symbols, ss, stats),
relay(db, threadpool, ctx, stats),
security_timer(),
health_timer()
{ }
QueryServerImpl db;
MDRelayServer relay;
@@ -394,7 +432,7 @@ struct QueryServer {
std::unique_ptr<utils::DispatcherTimer> health_timer;
};
QueryServerPtr run_query_server(const bts::api::ServiceContext& ctx, std::shared_ptr<api::ISyntheticSecurityService>& ss) {
QueryServerPtr run_query_server(const bts::api::ServiceContext& ctx, std::shared_ptr<api::ISyntheticSecurityService>& ss, metrics::MetricsContainer& stats) {
auto& threadpool = utils::Dispatcher::get_named("MDQuery");
std::set<UserSymbol> all_symbols;
@@ -403,7 +441,8 @@ QueryServerPtr run_query_server(const bts::api::ServiceContext& ctx, std::shared
SecurityType type;
bts_assert(api::SecurityType_Parse(config::get<PlatformConfig>().type(), &type));
get_system_md_symbols(venue, type, all_symbols);
QueryServerPtr container = std::make_shared<QueryServer>(all_symbols, threadpool, ctx, ss);
QueryServerPtr container = std::make_shared<QueryServer>(all_symbols, threadpool, ctx, ss, stats);
auto& db = container->db;
// Scan for new securities every half second
@@ -426,8 +465,8 @@ QueryServerPtr run_query_server(const bts::api::ServiceContext& ctx, std::shared
return container;
}
std::unique_ptr<IQueryServer> create_query_server(const std::set<UserSymbol>& symbols, std::shared_ptr<api::ISyntheticSecurityService>& ss) {
return std::make_unique<QueryServerImpl>(symbols, ss);
std::unique_ptr<IQueryServer> create_query_server(const std::set<UserSymbol>& symbols, std::shared_ptr<api::ISyntheticSecurityService>& ss, metrics::MetricsContainer& stats) {
return std::make_unique<QueryServerImpl>(symbols, ss, stats);
}
}}//namespace
+3 -2
View File
@@ -11,6 +11,7 @@
namespace bts {
namespace api { class ServiceContext; }
namespace metrics { class MetricsContainer; }
namespace md {
struct IQueryServer {
@@ -18,11 +19,11 @@ struct IQueryServer {
virtual void scan_securities() = 0;
virtual void query(const co2::MDRequest& request, co2::MDReply* reply) const = 0;
};
std::unique_ptr<IQueryServer> create_query_server(const std::set<UserSymbol>&, std::shared_ptr<api::ISyntheticSecurityService>&);
std::unique_ptr<IQueryServer> create_query_server(const std::set<UserSymbol>&, std::shared_ptr<api::ISyntheticSecurityService>&, metrics::MetricsContainer&);
struct QueryServer;
typedef std::shared_ptr<QueryServer> QueryServerPtr;
QueryServerPtr run_query_server(const bts::api::ServiceContext&, std::shared_ptr<api::ISyntheticSecurityService>&);
QueryServerPtr run_query_server(const bts::api::ServiceContext&, std::shared_ptr<api::ISyntheticSecurityService>&, metrics::MetricsContainer&);
}}//namespace
+12 -1
View File
@@ -10,6 +10,7 @@
#include "lib/utils/defer.h"
#include "lib/utils/warn_ctrl.h"
#include "lib/utils/bts_chrono.h"
#include "server/sparkd/metrics/metrics.h"
#include "lib/config/protos/MarketData.pb.h"
@@ -30,6 +31,15 @@
using namespace std;
namespace bts {
#ifdef _WIN32
namespace metrics {
struct MetricCollection{};
MetricsContainer::MetricsContainer() {}
MetricsContainer::~MetricsContainer() {}
}
#endif
int md_tests = 0;
namespace md {
// import this from RelayClient.cpp
@@ -1275,7 +1285,8 @@ struct Co2RelayTests {
set<UserSymbol> symbols;
symbols.insert(symbol);
shared_ptr<api::ISyntheticSecurityService> empty;
auto server = create_query_server(symbols, empty);
metrics::MetricsContainer stats;
auto server = create_query_server(symbols, empty, stats);
REQUIRE(server);
server->scan_securities();
+1 -1
View File
@@ -1 +1 @@
set(sources cmds/AutoCert.cpp;cmds/Benchmark.cpp;cmds/CmdRegistry.cpp;cmds/ConfigCheck.cpp;cmds/Help.cpp;cmds/Md.cpp;cmds/QuickTest.cpp;cmds/Run.cpp;cmds/RunSim.cpp;cmds/Span.cpp;cmds/Test.cpp;cmds/TestCeloxica.cpp;dspark/mirage.cpp;dspark/mirage/routing/Router.cpp;exchange_sim/ExchangeSim.cpp;exchange_sim/ExchangeSimApplication.cpp;exchange_sim/book/Book.cpp;exchange_sim/book/ExchangeSim.proto;exchange_sim/book/Order.cpp;exchange_sim/book/OrderMatcher.cpp;exchange_sim/book/book_transform.cpp;exchange_sim/tests/test_book_transform.cpp;http/ApiGateway.cpp;http/WebServer.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;main.cpp;md/platforms/celoxica/CXListener.cpp;md/platforms/celoxica/CXMain.cpp;md/platforms/celoxica/tests/cx_tests.cpp;md/platforms/mdp3_onixs/MDP3Listener.cpp;md/platforms/mdp3_onixs/MDP3Main.cpp;md/platforms/mdp3_onixs/MDP3Utils.cpp;md/platforms/mdp3_onixs/tests/mdp3_tests.cpp;md/run_md.cpp;mercury/actors/Actor.cpp;mercury/broker/AsyncEventBroker.cpp;mercury/broker/CoreEventBroker.cpp;mercury/broker/IEventBroker.cpp;mercury/events/TimerEvent.cpp;mercury/mercury_utils/Executor.cpp;mercury/mercury_utils/IPollableActor.cpp;mercury/mercury_utils/mercury_common.cpp;mercury/synopsis/SynopsisBuilder.cpp;mercury/topics/ITopic.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderManager.cpp;orderman/actors/order_manager/OrderServicesData.cpp;orderman/events/CancelRejectEvent.cpp;orderman/events/NewExecutionReportEvent.cpp;orderman/limiter/LimitStore.cpp;orderman/limiter/Limiter.cpp;orderman/limiter/ProductLimitNode.cpp;orderman/limiter/ProductLimitTree.cpp;orderman/limiter/SecurityLimitNode.cpp;orderman/limiter/SecurityLimitTree.cpp;orderman/limiter/tests/limit_tests.cpp;orderman/order_factory/OrderFactory.cpp;orderman/order_router/OrderRouter.cpp;orderman/orderman_utils/fix_order_codec.cpp;orderman/orders/IcebergOrder.cpp;orderman/orders/NativeOrder.cpp;orderman/orders/Order.cpp;orderman/orders/TimeBoxOrder.cpp;orderman/orders/book_algos/BookAlgo.cpp;orderman/orders/book_algos/JoinOrder.cpp;orderman/orders/book_algos/LeanOrder.cpp;orderman/orders/book_algos/TickOrder.cpp;orderman/orders/book_algos/TopOrder.cpp;orderman/orders/spreader_orders/SpreaderOrder.cpp;orderman/orders/spreader_orders/spreader/LegPropertyData.cpp;orderman/orders/spreader_orders/spreader/QuoteLegPriceQuantityState.cpp;orderman/orders/spreader_orders/spreader/SingleFillHedger.cpp;orderman/orders/spreader_orders/spreader/SingleLegQuoter.cpp;orderman/orders/spreader_orders/spreader/SpreaderBookkeepingData.cpp;orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.cpp;orderman/orders/spreader_orders/spreader/SpreaderLegData.cpp;orderman/orders/spreader_orders/spreader/SpreaderUtils.cpp;orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderOrderBuilder.cpp;orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderOrderServices.cpp;orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderPreActivationOrderServices.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerEndStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerStartStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForCancelAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForFirstAckCancelledStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForFirstAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWorkingStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterEndStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterStartStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForCancelAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForFirstAckCancelledWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForFirstAckWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForSizeStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWorkingStateWorker.cpp;orderman/Line truncated
set(sources cmds/AutoCert.cpp;cmds/Benchmark.cpp;cmds/CmdRegistry.cpp;cmds/ConfigCheck.cpp;cmds/Help.cpp;cmds/Md.cpp;cmds/QuickTest.cpp;cmds/Run.cpp;cmds/RunSim.cpp;cmds/Span.cpp;cmds/Test.cpp;cmds/TestCeloxica.cpp;dspark/mirage.cpp;dspark/mirage/routing/Router.cpp;exchange_sim/ExchangeSim.cpp;exchange_sim/ExchangeSimApplication.cpp;exchange_sim/book/Book.cpp;exchange_sim/book/ExchangeSim.proto;exchange_sim/book/Order.cpp;exchange_sim/book/OrderMatcher.cpp;exchange_sim/book/book_transform.cpp;exchange_sim/tests/test_book_transform.cpp;http/ApiGateway.cpp;http/WebServer.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;main.cpp;md/platforms/celoxica/CXListener.cpp;md/platforms/celoxica/CXMain.cpp;md/platforms/celoxica/tests/cx_tests.cpp;md/platforms/mdp3_onixs/MDP3Listener.cpp;md/platforms/mdp3_onixs/MDP3Main.cpp;md/platforms/mdp3_onixs/MDP3Utils.cpp;md/platforms/mdp3_onixs/tests/mdp3_tests.cpp;md/run_md.cpp;mercury/actors/Actor.cpp;mercury/broker/AsyncEventBroker.cpp;mercury/broker/CoreEventBroker.cpp;mercury/broker/IEventBroker.cpp;mercury/events/TimerEvent.cpp;mercury/mercury_utils/Executor.cpp;mercury/mercury_utils/IPollableActor.cpp;mercury/mercury_utils/mercury_common.cpp;mercury/synopsis/SynopsisBuilder.cpp;mercury/topics/ITopic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderManager.cpp;orderman/actors/order_manager/OrderServicesData.cpp;orderman/events/CancelRejectEvent.cpp;orderman/events/NewExecutionReportEvent.cpp;orderman/limiter/LimitStore.cpp;orderman/limiter/Limiter.cpp;orderman/limiter/ProductLimitNode.cpp;orderman/limiter/ProductLimitTree.cpp;orderman/limiter/SecurityLimitNode.cpp;orderman/limiter/SecurityLimitTree.cpp;orderman/limiter/tests/limit_tests.cpp;orderman/order_factory/OrderFactory.cpp;orderman/order_router/OrderRouter.cpp;orderman/orderman_utils/fix_order_codec.cpp;orderman/orders/IcebergOrder.cpp;orderman/orders/NativeOrder.cpp;orderman/orders/Order.cpp;orderman/orders/TimeBoxOrder.cpp;orderman/orders/book_algos/BookAlgo.cpp;orderman/orders/book_algos/JoinOrder.cpp;orderman/orders/book_algos/LeanOrder.cpp;orderman/orders/book_algos/TickOrder.cpp;orderman/orders/book_algos/TopOrder.cpp;orderman/orders/spreader_orders/SpreaderOrder.cpp;orderman/orders/spreader_orders/spreader/LegPropertyData.cpp;orderman/orders/spreader_orders/spreader/QuoteLegPriceQuantityState.cpp;orderman/orders/spreader_orders/spreader/SingleFillHedger.cpp;orderman/orders/spreader_orders/spreader/SingleLegQuoter.cpp;orderman/orders/spreader_orders/spreader/SpreaderBookkeepingData.cpp;orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.cpp;orderman/orders/spreader_orders/spreader/SpreaderLegData.cpp;orderman/orders/spreader_orders/spreader/SpreaderUtils.cpp;orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderOrderBuilder.cpp;orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderOrderServices.cpp;orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderPreActivationOrderServices.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerEndStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerStartStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForCancelAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForFirstAckCancelledStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForFirstAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWorkingStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterEndStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterStartStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForCancelAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForFirstAckCancelledWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForFirstAckWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForSizeStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoteLine truncated
+6 -2
View File
@@ -16,6 +16,8 @@
#include "server/sparkd/persistence/PersistenceServiceServer.h"
#include "server/sparkd/support/ErrorReportService.h"
#include "server/sparkd/http/WebServer.h"
#include "server/sparkd/metrics/metrics.h"
#include "server/sparkd/metrics/system_metrics.h"
#include "server/sparkd/user/AdminServiceServer.h"
#include "server/sparkd/user/UserServiceServer.h"
@@ -37,7 +39,9 @@ int Run::execute(std::vector<std::string> const &) {
qbus::Quickbus quickbus(qb_cfg);
api::ServiceContext sc(&quickbus);
http::SparkWebServer webserver(sc, ports.config_port());
metrics::MetricsContainer stats;
metrics::publish_system_metrics(stats);
http::SparkWebServer webserver(sc, stats, ports.config_port());
persistence::PersistenceServiceServer settings_saver(sc, "settings");
user::UserServiceServer login_server(sc);
@@ -45,7 +49,7 @@ int Run::execute(std::vector<std::string> const &) {
std::shared_ptr<api::ISyntheticSecurityService> synthetic_service =
std::make_shared<api::synthetic::SyntheticSecurityService>(sc);
md::QueryServerPtr md_query_server(
md::run_query_server(sc, synthetic_service));
md::run_query_server(sc, synthetic_service, stats));
orderman::OrderServiceServer order_service_server(sc, synthetic_service);
support::ErrorReportServer error_report_service(sc);
admin::AdminServiceServer admin_service(sc);
+58
View File
@@ -0,0 +1,58 @@
#include "Web.h"
#include "lib/config/config.h"
#include "lib/config/protos/quickbus_cfg.pb.h"
#include "lib/config/protos/Ports.pb.h"
#include "lib/quickbus/quickbus.h"
#include "lib/api/public/ServiceContext.h"
#include "server/sparkd/metrics/metrics.h"
#include "server/sparkd/metrics/system_metrics.h"
#include "server/sparkd/http/WebServer.h"
#include "lib/md/relay/QueryServer.h"
#include "lib/md/SyntheticSecurityService.h"
#include "server/sparkd/user/AdminServiceServer.h"
#include "server/sparkd/user/UserServiceServer.h"
#include "server/sparkd/md/run_md.h"
#include <vector>
#include <string>
namespace bts {
namespace cmd {
int Web::execute(const std::vector<std::string>& args) {
config::QuickbusNodeCfg qb_cfg;
auto& ports = config::get<config::Ports>();
qb_cfg.set_my_port(ports.qbus_port());
qbus::Quickbus quickbus(qb_cfg);
api::ServiceContext sc(&quickbus);
metrics::MetricsContainer stats;
metrics::publish_system_metrics(stats);
http::SparkWebServer webserver(sc, stats, ports.config_port());
user::UserServiceServer login_server(sc);
if (std::find(args.begin(), args.end(), "-md") != args.end()) {
md::run_market_datapublishers();
}
std::shared_ptr<api::ISyntheticSecurityService> synthetic_service =
std::make_shared<api::synthetic::SyntheticSecurityService>(sc);
md::QueryServerPtr md_query_server(
md::run_query_server(sc, synthetic_service, stats));
admin::AdminServiceServer admin_service(sc);
std::this_thread::sleep_until(
std::chrono::time_point<std::chrono::system_clock>::max());
return 0;
}
std::string Web::help() {
return "\t run only the services required for the web admin. This cannot be run concurrently with 'sparkd run'\n\tAdd -md to start market data too.";
}
}}//namespace
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include "ICmd.h"
namespace bts {
namespace cmd {
class Web : public ICmd
{
public:
int execute(std::vector<std::string> const &args);
std::string help ();
};
}}
+27 -5
View File
@@ -5,6 +5,7 @@
#include "lib/api/apigateway.pb.h"
#include "lib/logging/logging.h"
#include "lib/os/os.h"
#include "lib/utils/TimeStamp.h"
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
@@ -49,24 +50,33 @@ namespace http {
std::string _www;
std::string _conf;
const api::ServiceContext& _ctx;
metrics::MetricsContainer& _metrics;
std::shared_ptr<metrics::HistogramMetric<4>> _mtimer;
ServerState(const api::ServiceContext& ctx, int port) :
ServerState(const api::ServiceContext& ctx, metrics::MetricsContainer& metrics, int port) :
_m(),
_dispatcher(utils::Dispatcher::get_named("Webserver")),
_session(),
_server(),
_port(port),
_www(),
_ctx(ctx)
_ctx(ctx),
_metrics(metrics),
_mtimer(std::make_shared<metrics::HistogramMetric<4>>("spark_metrics_query_duration_ms",
std::array<double,4>({ 0.1, 0.5, 1.0, 5.0 })))
{
_www = os::sparkdata_path("www");
_conf = os::sparkdata_path("conf");
_metrics.publish(_mtimer);
_server.init_asio(_dispatcher.io_service());
_server.set_open_handler(bind(&ServerState::on_open, this, ::_1));
_server.set_close_handler(bind(&ServerState::on_close, this, ::_1));
_server.set_message_handler(bind(&ServerState::on_message, this, ::_1, ::_2));
_server.set_http_handler(bind(&ServerState::on_http, this, ::_1));
// Turn off logging
_server.clear_access_channels(websocketpp::log::alevel::all);
run();
}
@@ -137,6 +147,15 @@ namespace http {
con->set_status(websocketpp::http::status_code::ok);
}
void return_metrics(connection_ptr& con) {
utils::TimeStamp start = utils::TimeStamp::now();
std::stringstream ss;
_metrics.print(ss);
con->set_body(ss.str());
con->set_status(websocketpp::http::status_code::ok);
_mtimer->observe((utils::TimeStamp::now() - start).microseconds() / 1000.0);
}
void directory_index(connection_ptr& con, const std::string& resource, const boost::filesystem::path& path) {
// directory listing
std::string body = "<!doctype html>\n";
@@ -219,10 +238,13 @@ namespace http {
void on_http(connection_hdl hdl) {
auto con = _server.get_con_from_hdl(hdl);
auto resource = strip_query_str(con->get_resource());
LOG(Api,Info, "REQUEST: {}", resource);
LOG(Api,Diag, "HTTP GET: {}", resource);
if (boost::iequals(resource, "/config/.all")) {
return_dotall(con);
}
else if (boost::iequals(resource, "/metrics")) {
return_metrics(con);
}
else if (boost::iequals(resource, "/bts_installer.exe") && boost::filesystem::is_regular_file(_www+"/bts_installer.exe")) {
return_bts_installer(con);
}
@@ -256,8 +278,8 @@ namespace http {
SparkWebServer::SparkWebServer(const api::ServiceContext& ctx, int port) :
_me(std::make_shared<ServerState>(ctx, port))
SparkWebServer::SparkWebServer(const api::ServiceContext& ctx, metrics::MetricsContainer& metrics, int port) :
_me(std::make_shared<ServerState>(ctx, metrics, port))
{
}
+2 -1
View File
@@ -1,5 +1,6 @@
#pragma once
#include "lib/api/public/ServiceContext.h"
#include "server/sparkd/metrics/metrics.h"
#include <memory>
namespace bts {
@@ -10,7 +11,7 @@ namespace http {
class SparkWebServer {
std::shared_ptr<ServerState> _me;
public:
SparkWebServer(const api::ServiceContext& ctx, int port);
SparkWebServer(const api::ServiceContext& ctx, metrics::MetricsContainer& metrics, int port);
};
}}
@@ -112,9 +112,9 @@ int SocketConnection::write (WriteVec const&vec,size_t vec_size,size_t cid)
iv[i].iov_len = vec[i].second;
}
tracepoint (bts_trace,trace_order,(char*) "SocketConnection.pre_write", 0,cid);
tracepoint (bts_trace,trace_order,(char*) "SocketConnection.pre_write", 0,cid,0);
auto result = ::writev (_fd,iv,(int) vec_size);
tracepoint (bts_trace,trace_order,(char*) "SocketConnection.post_write", 0,cid);
tracepoint (bts_trace,trace_order,(char*) "SocketConnection.post_write", 0,cid,0);
if (_log && result >0) {
for (size_t i = 0; i < vec_size;i++)
_out_log.write (vec[i].first, vec[i].second);
@@ -139,7 +139,7 @@ CoreGateway::~CoreGateway() {
}
void CoreGateway::send(orderman::TickToTradeCorID cid, OutFIXPtr const &fix) {
tracepoint(bts_trace, trace_order, (char *)"CoreGateway.send", 0, cid);
tracepoint(bts_trace, trace_order, (char *)"CoreGateway.send", 0, cid,0);
me->event_queue.enqueue(EventData(&CoreGateway::sync_send, cid, fix));
}
@@ -257,7 +257,7 @@ void CoreGateway::sync_stop(EventData const &) {
void CoreGateway::sync_send(EventData const &ev) {
tracepoint(bts_trace, trace_order, (char *)"CoreGateway.sync_send", 0,
ev.cid);
ev.cid,0);
switch (me->state) {
case State::OFF:
bts_assert(false);
@@ -449,7 +449,7 @@ void CoreGateway::sync_time(EventData const &ev) {
me->session_info.reset();
me->start_of_pause = datetime::now();
LOG(Jetfix, Error,
"Failed to connect to exchange gateway {} too many"
"Failed to connect to exchange gateway {} too many "
"times. Giving up permanently. You must bounce "
"the server to recover.",
me->cfg.name());
+3 -3
View File
@@ -106,7 +106,7 @@ void Session::start() {
}
void Session::send(orderman::TickToTradeCorID cid, OutFIXPtr const &msgs) {
tracepoint (bts_trace,trace_order,(char*) "Session.send", 0,cid);
tracepoint (bts_trace,trace_order,(char*) "Session.send", 0,cid,0);
switch (me->state) {
case State::READY:
case State::CERT_MODE:
@@ -563,12 +563,12 @@ void Session::internal_send(orderman::TickToTradeCorID cid,
data_vec[i].first = s.data();
data_vec[i].second = s.size();
}
tracepoint (bts_trace,trace_order,(char*) "Session.internal_send.pre_write", 0,cid);
tracepoint (bts_trace,trace_order,(char*) "Session.internal_send.pre_write", 0,cid,0);
if (me->connection.write(data_vec, msgs->fix.size(), cid) < 0) {
terminate_session(JetFIXError::CONNECTION_ERROR);
return;
}
tracepoint (bts_trace,trace_order,(char*) "Session.internal_send.post_write", 0,cid);
tracepoint (bts_trace,trace_order,(char*) "Session.internal_send.post_write", 0,cid,0);
me->last_sent_msg_timestamp = me->now();
me->store.store(msgs);
msgs->set_ts(OutFIX::POST_STORE, utils::TimeStamp::now());
+2
View File
@@ -15,6 +15,7 @@
#include "server/sparkd/cmds/AutoCert.h"
#include "server/sparkd/cmds/QuickTest.h"
#include "server/sparkd/cmds/Span.h"
#include "server/sparkd/cmds/Web.h"
int main(int argc, char **argv) {
using namespace bts;
@@ -33,6 +34,7 @@ int main(int argc, char **argv) {
REGISTER(QuickTest);
REGISTER(AutoCert);
REGISTER(Span);
REGISTER(Web);
END_CMD;
utils::finit_spark_lib();
@@ -106,45 +106,42 @@ MDP3Listener::~MDP3Listener() {
//
// Warnings/Errors
void MDP3Listener::onError(onixs::Handler&, const onixs::ErrorArgs& error) {
tracepoint (bts_trace,trace_order,(char*) "onError", 0, _latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onError", _latest_sequence, (uint16_t) _latest_sequence, 0);
LOG(md,Warn, "OnixS Error: {} - {}", error.description(), error.source());
}
void MDP3Listener::onWarning(onixs::Handler&, const onixs::WarningArgs& warning) {
tracepoint (bts_trace,trace_order,(char*) "onWarning", 0, _latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onWarning", _latest_sequence, (uint16_t) _latest_sequence, 0);
LOG(md,Warn, "OnixS Warn: {} - {}", warning.description(), warning.source());
}
void MDP3Listener::onInstrumentRecovery(onixs::Handler& h) {
tracepoint (bts_trace,trace_order,(char*) "onInstrumentRecovery", 0, _latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onInstrumentRecovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
LOG(md,Info, "Beginning security definition recovery for channel {}", h.settings().channel());
}
void MDP3Listener::onEndOfInstrumentRecovery(onixs::Handler& h, const onixs::RecoveryCompletionArgs&) {
tracepoint (bts_trace,trace_order,(char*) "onEndOfInstrumentRecovery", 0, _latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onEndOfInstrumentRecovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
LOG(md,Info, "Finished Security definition recovery for channel {}", h.settings().channel());
}
// void MDP3Listener::onGap(onixs::Handler& h, const Security&, unsigned) {
// update_all_status(COCONUTSECURITYSTATUS_PACKET_LOSS);
// LOG(MarketData,Info, "Gap detected on channel {}", h.settings().channel());
// }
//
// Gap Recovery
void MDP3Listener::onMarketRecovery(onixs::Handler& h) {
tracepoint (bts_trace,trace_order,(char*) "onMarketRecovery", 0, _latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onMarketRecovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
update_all_status(COCONUTSECURITYSTATUS_PACKET_LOSS);
for (auto& c : _channels) { c.gap(); }
LOG(md,Info, "Beginning market recovery for channel {}", h.settings().channel());
}
void MDP3Listener::onEndOfMarketRecovery(onixs::Handler& h, const onixs::RecoveryCompletionArgs&) {
tracepoint (bts_trace,trace_order,(char*) "onEndOfMarketRecovery", 0, _latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onEndOfMarketRecovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
update_all_status(COCONUTSECURITYSTATUS_OK);
LOG(md,Info, "Finished market recovery for channel {}", h.settings().channel());
}
void MDP3Listener::onTcpRecovery(onixs::Handler& h) {
tracepoint (bts_trace,trace_order,(char*) "onTcpRecovery", 0, _latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onTcpRecovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
update_all_status(COCONUTSECURITYSTATUS_PACKET_LOSS);
LOG(md,Info, "Beginning tcp recovery for channel {}", h.settings().channel());
}
void MDP3Listener::onEndOfTcpRecovery(onixs::Handler& h, const onixs::RecoveryCompletionArgs&) {
tracepoint (bts_trace,trace_order,(char*) "onEndOfTcpRecovery", 0, _latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onEndOfTcpRecovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
update_all_status(COCONUTSECURITYSTATUS_OK);
LOG(md,Info, "Finished tcp recovery for channel {}", h.settings().channel());
}
@@ -171,12 +168,12 @@ void MDP3Listener::onPacket(onixs::Handler&, const onixs::PacketArgs& args) {
// was needed for clang compilation
tracepoint (bts_trace,trace_order,(char*) "onPacket",
_packet_arrived.to_uint64() - (onixs_now-onixs_zero),_latest_sequence);
_latest_sequence,(uint16_t) _latest_sequence, onixs_now-onixs_zero);
}
void MDP3Listener::onEndOfPacket(onixs::Handler&, const onixs::PacketArgs&) {
tracepoint (bts_trace,trace_order,(char*) "onEndOfPacket.begin", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onEndOfPacket.begin", _latest_sequence, (uint16_t) _latest_sequence, 0);
flush_books();
tracepoint (bts_trace,trace_order,(char*) "onEndOfPacket.end", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onEndOfPacket.end", _latest_sequence, (uint16_t) _latest_sequence, 0);
}
//
@@ -230,7 +227,7 @@ void set_security_common(const Definition& def, FixedSecurity& fsec) {
}
void MDP3Listener::onDefinition(onixs::Handler&, const onixs::Security& osec, const onixs::InstrumentDefinitionFutureArgs& def) {
tracepoint (bts_trace,trace_order,(char*) "onDefinition.future", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onDefinition.future", _latest_sequence, (uint16_t) _latest_sequence, 0);
const auto& sec = def.message();
auto exchange_id = sec.securityId();
// LOG(Info, MarketData) << "onDefinition future " << exchange_id;
@@ -255,7 +252,7 @@ void MDP3Listener::onDefinition(onixs::Handler&, const onixs::Security& osec, co
add_security(fsec);
}
void MDP3Listener::onDefinition(onixs::Handler&, const onixs::Security&, const onixs::InstrumentDefinitionOptionArgs& def) {
tracepoint (bts_trace,trace_order,(char*) "onDefinition.option", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onDefinition.option", _latest_sequence, (uint16_t) _latest_sequence, 0);
const auto& sec = def.message();
auto exchange_id = sec.securityId();
// LOG(Info, MarketData) << "onDefinition option " << exchange_id;
@@ -288,7 +285,7 @@ void MDP3Listener::onDefinition(onixs::Handler&, const onixs::Security&, const o
}
void MDP3Listener::onDefinition(onixs::Handler&, const onixs::Security&, const onixs::InstrumentDefinitionSpreadArgs& spread_args) {
tracepoint (bts_trace,trace_order,(char*) "onDefinition.spread", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onDefinition.spread", _latest_sequence, (uint16_t) _latest_sequence, 0);
const auto& sec = spread_args.message();
auto exchange_id = sec.securityId();
// LOG(Info, MarketData) << "onDefinition spread " << exchange_id;
@@ -339,7 +336,7 @@ void MDP3Listener::onDefinition(onixs::Handler&, const onixs::Security&, const o
//
// Book
void MDP3Listener::onBookUpdate(onixs::Handler&, const onixs::Security& sec, const onixs::ConsolidatedBook& book) {
tracepoint (bts_trace,trace_order,(char*) "onBookUpdate", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onBookUpdate", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto data = _index.get_security(sec.id());
if (data == nullptr) return;
@@ -389,7 +386,7 @@ void on_trade(SecurityData* data, const onixs::PRICE& price, int size, const oni
}
void MDP3Listener::onTrade(onixs::Handler&, const onixs::Security& sec, const onixs::RecoveryEntryArgs& arg) {
tracepoint (bts_trace,trace_order,(char*) "onTrade.recovery", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onTrade.recovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != NULL) {
int size = 0;
@@ -400,7 +397,7 @@ void MDP3Listener::onTrade(onixs::Handler&, const onixs::Security& sec, const on
}
}
void MDP3Listener::onTrade(onixs::Handler&, const onixs::Security& sec, const onixs::TradeSummaryArgs& arg) {
tracepoint (bts_trace,trace_order,(char*) "onTrade.summary", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onTrade.summary", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != NULL) {
auto size = arg.entry().entrySize();
@@ -409,7 +406,7 @@ void MDP3Listener::onTrade(onixs::Handler&, const onixs::Security& sec, const on
}
}
void MDP3Listener::onTrade(onixs::Handler&, const onixs::Security& sec, const onixs::TradeArgs& arg) {
tracepoint (bts_trace,trace_order,(char*) "onTrade.trade_args", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onTrade.trade_args", _latest_sequence, (uint16_t) _latest_sequence, 0);
if (arg.entry().updateAction() == onixs::UpdateAction::New) {
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
@@ -423,7 +420,7 @@ void MDP3Listener::onTrade(onixs::Handler&, const onixs::Security& sec, const on
//
// RFQ
void MDP3Listener::onQuoteRequest(onixs::Handler&, const onixs::Security& sec, const onixs::QuoteRequestRelatedSymArgs& arg) {
tracepoint (bts_trace,trace_order,(char*) "onQuoteRequest", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onQuoteRequest", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
auto ts = utils::TimeStamp::now();
@@ -472,7 +469,7 @@ void MDP3Listener::onQuoteRequest(onixs::Handler&, const onixs::Security& sec, c
//
// Volume
void MDP3Listener::onElectronicVolume(onixs::Handler&, const onixs::Security& sec, const onixs::VolumeArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onElectronicVolume.volume", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onElectronicVolume.volume", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
bts_assert_d( args.entry().entryType().value() == 'e');
@@ -482,7 +479,7 @@ void MDP3Listener::onElectronicVolume(onixs::Handler&, const onixs::Security& se
}
}
void MDP3Listener::onElectronicVolume(onixs::Handler&, const onixs::Security& sec, const onixs::RecoveryEntryArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onElectronicVolume.recovery", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onElectronicVolume.recovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data) {
int32_t size;
@@ -495,7 +492,7 @@ void MDP3Listener::onElectronicVolume(onixs::Handler&, const onixs::Security& se
//
// Misc
void MDP3Listener::onSettlementPrice(onixs::Handler&, const onixs::Security& sec, const onixs::DailyStatisticsArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onSettlementPrice.daily", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onSettlementPrice.daily", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
onixs::PRICE price;
@@ -510,7 +507,7 @@ void MDP3Listener::onSettlementPrice(onixs::Handler&, const onixs::Security& sec
}
}
void MDP3Listener::onSettlementPrice(onixs::Handler&, const onixs::Security& sec, const onixs::RecoveryEntryArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onSettlementPrice.recovery", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onSettlementPrice.recovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
onixs::PRICE price;
@@ -525,7 +522,7 @@ void MDP3Listener::onSettlementPrice(onixs::Handler&, const onixs::Security& sec
}
}
void MDP3Listener::onOpenInterest(onixs::Handler&, const onixs::Security& sec, const onixs::DailyStatisticsArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onOpenInterest.daily", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onOpenInterest.daily", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
onixs::PRICE price;
@@ -535,7 +532,7 @@ void MDP3Listener::onOpenInterest(onixs::Handler&, const onixs::Security& sec, c
}
}
void MDP3Listener::onOpenInterest(onixs::Handler&, const onixs::Security& sec, const onixs::RecoveryEntryArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onOpenInterest.recovery", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onOpenInterest.recovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
onixs::PRICE price;
@@ -545,7 +542,7 @@ void MDP3Listener::onOpenInterest(onixs::Handler&, const onixs::Security& sec, c
}
}
void MDP3Listener::onOpeningPrice(onixs::Handler&, const onixs::Security& sec, const onixs::SessionStatisticsArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onOpeningPrice.session", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onOpeningPrice.session", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
onixs::PRICE price = args.entry().entryPx();
@@ -558,7 +555,7 @@ void MDP3Listener::onOpeningPrice(onixs::Handler&, const onixs::Security& sec, c
}
}
void MDP3Listener::onOpeningPrice(onixs::Handler&, const onixs::Security& sec, const onixs::RecoveryEntryArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onOpeningPrice.recovery", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onOpeningPrice.recovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
onixs::PRICE price;
@@ -573,7 +570,7 @@ void MDP3Listener::onOpeningPrice(onixs::Handler&, const onixs::Security& sec, c
}
}
void MDP3Listener::onHighTradePrice(onixs::Handler&, const onixs::Security& sec, const onixs::SessionStatisticsArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onHighTradePrice.session", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onHighTradePrice.session", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
auto display_factor = data->handle.security().display_factor;
@@ -583,7 +580,7 @@ void MDP3Listener::onHighTradePrice(onixs::Handler&, const onixs::Security& sec,
}
}
void MDP3Listener::onHighTradePrice(onixs::Handler&, const onixs::Security& sec, const onixs::RecoveryEntryArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onHighTradePrice.recovery", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onHighTradePrice.recovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
auto display_factor = data->handle.security().display_factor;
@@ -595,7 +592,7 @@ void MDP3Listener::onHighTradePrice(onixs::Handler&, const onixs::Security& sec,
}
}
void MDP3Listener::onLowTradePrice(onixs::Handler&, const onixs::Security& sec, const onixs::SessionStatisticsArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onLowTradePrice.session", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onLowTradePrice.session", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
auto display_factor = data->handle.security().display_factor;
@@ -605,7 +602,7 @@ void MDP3Listener::onLowTradePrice(onixs::Handler&, const onixs::Security& sec,
}
}
void MDP3Listener::onLowTradePrice(onixs::Handler&, const onixs::Security& sec, const onixs::RecoveryEntryArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onLowTradePrice.recovery", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onLowTradePrice.recovery", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
auto display_factor = data->handle.security().display_factor;
@@ -617,7 +614,7 @@ void MDP3Listener::onLowTradePrice(onixs::Handler&, const onixs::Security& sec,
}
}
void MDP3Listener::onHighestBid(onixs::Handler&, const onixs::Security& sec, const onixs::SessionStatisticsArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onHighestBid.session", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onHighestBid.session", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
auto display_factor = data->handle.security().display_factor;
@@ -627,7 +624,7 @@ void MDP3Listener::onHighestBid(onixs::Handler&, const onixs::Security& sec, con
}
}
void MDP3Listener::onLowestOffer(onixs::Handler&, const onixs::Security& sec, const onixs::SessionStatisticsArgs& args) {
tracepoint (bts_trace,trace_order,(char*) "onLowestOffer.session", 0,_latest_sequence);
tracepoint (bts_trace,trace_order,(char*) "onLowestOffer.session", _latest_sequence, (uint16_t) _latest_sequence, 0);
auto* data = _index.get_security(sec.id());
if (data != nullptr) {
auto display_factor = data->handle.security().display_factor;
@@ -28,7 +28,6 @@ public:
void onWarning(onixs::Handler&, const onixs::WarningArgs&) override;
void onInstrumentRecovery(onixs::Handler&) override;
void onEndOfInstrumentRecovery(onixs::Handler&, const onixs::RecoveryCompletionArgs&) override;
// void onGap(onixs::Handler&, const Security&, unsigned) override;
//
// Gap Recovery
+69
View File
@@ -0,0 +1,69 @@
#include "metrics.h"
#include <sstream>
#include <tbb/concurrent_vector.h>
using std::vector;
using std::shared_ptr;
namespace bts {
namespace metrics {
Metric::Metric(const std::string& cname, const std::vector<Label>& clabels):
name(cname),
labels(clabels) {
}
std::string Metric::str() const {
std::stringstream ss;
print(ss);
return ss.str();
}
std::ostream& operator<<(std::ostream& os, const std::vector<Label>& labels) {
if (!labels.empty()) {
os << "{";
for (auto iter = labels.begin(); iter != labels.end(); ++iter) {
if (iter != labels.begin()) os << ",";
os << iter->name << "=\"" << iter->value << "\"";
}
os << "}";
}
return os;
}
const std::string double_to_string(double d) {
std::stringstream ss;
ss << d;
return ss.str();
}
const std::vector<Label> vector_concat(const std::vector<Label>& orig, const std::vector<Label>& extra) {
if (orig.empty()) return extra;
std::vector<Label> result;
result.reserve(orig.size() + extra.size());
result.insert(result.end(), orig.begin(), orig.end());
result.insert(result.end(), extra.begin(), extra.end());
return result;
}
//
// Histogram
// -- collection of CounterMetrics?
struct MetricCollection {
tbb::concurrent_vector<shared_ptr<Metric>> metrics;
};
MetricsContainer::MetricsContainer() : _me(std::make_unique<MetricCollection>()) {}
MetricsContainer::~MetricsContainer() {}
void MetricsContainer::print(std::ostream& out) const {
for (const auto& m : _me->metrics) {
m->print(out);
}
}
void MetricsContainer::publish(std::shared_ptr<Metric> m) {
_me->metrics.push_back(m);
}
}}//namespace
+155
View File
@@ -0,0 +1,155 @@
#pragma once
#include <iostream>
#include <string>
#include <memory>
#include <vector>
#include <functional>
#include <atomic>
#include <sstream>
namespace bts {
namespace metrics {
class MetricsContainer;
struct Label {
std::string name;
std::string value;
};
std::ostream& operator<<(std::ostream& os, const std::vector<Label>& l);
struct Metric {
const std::string name;
const std::vector<Label> labels;
Metric(const std::string&, const std::vector<Label>&);
virtual void print(std::ostream&) const = 0;
std::string str() const;
virtual ~Metric() {}
};
template <class T>
struct CounterMetric : public Metric {
T _val;
CounterMetric(const std::string& name) : Metric(name, {}), _val() {}
CounterMetric(const std::string& name, const std::vector<Label>& labels) : Metric(name, labels), _val() {}
~CounterMetric() {};
void print(std::ostream& out) const override {
out << name << labels << " " << _val << std::endl;
}
void increment() { _val++; }
void increment(T val) { _val += val; }
void decrement() { _val--; }
void decrement(T val) { _val -= val; }
void set(T val) { _val = val; }
};
template <class T>
class AtomicCounterMetric : public Metric {
std::atomic<T> _val;
public:
AtomicCounterMetric(const std::string& name) : Metric(name, {}), _val() {}
AtomicCounterMetric(const std::string& name, const std::vector<Label>& labels) : Metric(name, labels), _val() {}
AtomicCounterMetric(const AtomicCounterMetric& o) : Metric(o.name, o.labels), _val(o._val.load()) { }
~AtomicCounterMetric() {};
void print(std::ostream& out) const override {
out << name << labels << " " << _val << std::endl;
}
void increment() { _val++; }
void increment(T val) { _val += val; }
void decrement() { _val--; }
void decrement(T val) { _val -= val; }
void set(T val) { _val = val; }
};
template <class T>
class LazyCounterMetric : public Metric {
const std::function<T()> _get;
public:
LazyCounterMetric(
const std::string& name,
const std::function<T()>& fn) : Metric(name, {}), _get(fn) {}
LazyCounterMetric(
const std::string& name,
const std::function<T()>& fn,
const std::vector<Label>& labels) : Metric(name, labels), _get(fn) {}
void print(std::ostream& os) const override {
os << name << labels << " " << _get() << std::endl;
}
};
typedef LazyCounterMetric<long> LazyCounterMetricL;
typedef LazyCounterMetric<double> LazyCounterMetricD;
const std::string double_to_string(double d);
const std::vector<Label> vector_concat(const std::vector<Label>& orig, const std::vector<Label>& extra);
template <size_t N, size_t... Is>
std::array<CounterMetric<long>,N> mk_counters(const std::string& name,
const std::vector<Label>& labels,
const std::array<double,N>& in,
std::index_sequence<Is...>) {
return {{ CounterMetric<long>(name+"_bucket", vector_concat(labels, {{ "le", double_to_string(in[Is]) }}))... }};
}
template <size_t N, size_t... Is>
std::array<CounterMetric<long>,N> mk_counters(const std::string& name,
const std::vector<Label>& labels,
const std::array<double,N>& in) {
return mk_counters(name, labels, in, std::make_index_sequence<N>());
}
// Calculate the 90th percentile of response times
// histogram_quantile(0.9, sum(rate(spark_metrics_query_duration_us_bucket[5m])) by (le))
template <size_t N>
class HistogramMetric : public Metric {
std::array<CounterMetric<long>,N> _buckets;
std::array<double,N> _bucket_values;
CounterMetric<double> _sum;
CounterMetric<long> _count;
public:
HistogramMetric(
const std::string& name,
const std::array<double,N>& buckets)
: Metric(name,{}), _buckets(mk_counters(name, {}, buckets)), _bucket_values(buckets), _sum(name+"_sum"), _count(name+"_count") {}
HistogramMetric(
const std::string& name,
const std::array<double,N>& buckets,
const std::vector<Label>& labels)
: Metric(name,labels), _buckets(mk_counters(name, labels, buckets)), _bucket_values(buckets), _sum(name+"_sum"), _count(name+"_count") {}
void print(std::ostream& os) const override {
for (size_t x = 0; x < N; ++x) {
_buckets[x].print(os);
}
os << name << "_bucket{le=\"+Inf\"";
for (auto iter = labels.begin(); iter != labels.end(); ++iter) {
os << "," << iter->name << "=\"" << iter->value << "\"";
}
os << "} " << _count._val << std::endl;
_sum.print(os);
_count.print(os);
}
void observe(double v) {
for (size_t x = 0; x < N; ++x) {
if (v <= _bucket_values[x]) {
_buckets[x].increment();
}
}
_sum.increment(v);
_count.increment();
}
};
struct MetricCollection;
class MetricsContainer {
std::unique_ptr<MetricCollection> _me;
public:
MetricsContainer();
~MetricsContainer();
void print(std::ostream&) const;
void publish(std::shared_ptr<Metric>);
};
}}//namespace
@@ -0,0 +1,86 @@
#include "system_metrics.h"
#include "lib/config/config.h"
#include "lib/config/protos/system.pb.h"
#include <memory>
#include <functional>
#include <unistd.h>
#include <fstream>
namespace bts {
namespace metrics {
struct ProcessStats {
int pid;
std::string name, state, ppid, pgrp, session, tty_nr;
std::string tpgid, flags, minflt, cminflt, majflt, cmajflt;
// utime - user time
// stime - kernel time
// cutime - cumulative user time
// cstime - cumulative system time
long utime, stime, cutime, cstime, priority, nice;
std::string O, itrealvalue, starttime;
// virtual size
uint64_t vsize;
// resident set
int64_t rss;
};
void read_stats(ProcessStats& stats) {
std::ifstream stat_stream("/proc/self/stat", std::ios_base::in);
stat_stream
>> stats.pid >> stats.name >> stats.state >> stats.ppid >> stats.pgrp >> stats.session >> stats.tty_nr
>> stats.tpgid >> stats.flags >> stats.minflt >> stats.cminflt >> stats.majflt >> stats.cmajflt
>> stats.utime >> stats.stime >> stats.cutime >> stats.cstime >> stats.priority >> stats.nice
>> stats.O >> stats.itrealvalue >> stats.starttime >> stats.vsize >> stats.rss;
stat_stream.close();
}
void process_mem_usage(double& vm, double& resident) {
using std::ios_base;
using std::ifstream;
vm = resident = 0.0;
ProcessStats stats;
read_stats(stats);
long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024;
vm = stats.vsize / 1024.0;
resident = stats.rss * page_size_kb;
}
void publish_system_metrics(MetricsContainer& stats) {
auto version = std::make_shared<CounterMetric<int>>("spark_version", std::vector<Label> ({{"version", config::get<config::System>().version()}}));
version->set(1);
stats.publish(version);
// publish system cpu use
// publish sparkd cpu use and thread use (/proc/self/task/*)
//
// sparkd memory use
// Note: It would be nice to have 2 metrics work on the same 'read' call
stats.publish(
std::make_shared<LazyCounterMetricL>("spark_memory_res_kb", []() {
double vm,res;
process_mem_usage(vm,res);
return res;
}));
stats.publish(
std::make_shared<LazyCounterMetricL>("spark_memory_vm_kb", []() {
double vm,res;
process_mem_usage(vm,res);
return vm;
}));
}
}}
@@ -0,0 +1,9 @@
#pragma once
#include "metrics.h"
namespace bts {
namespace metrics {
void publish_system_metrics(MetricsContainer&);
}}
@@ -265,7 +265,7 @@ void ExecutionGateway::on_outgoing_fix(
mercury::Update<OutFIXMsgEvent> const &msg) {
if (msg.events)
for (auto const &ev : *(msg.events)) {
tracepoint (bts_trace,trace_order,(char*) "on_outgoing_fix", 0,ev.cid);
tracepoint (bts_trace,trace_order,(char*) "on_outgoing_fix", 0,ev.cid,0);
me->gw.send(ev.cid, ev.msg);
}
}
+1 -1
View File
@@ -65,7 +65,7 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
md::HandleReadResult::SUCCESS) {
book._security_key = SecurityKey(handle->key());
corid = handle->sequence();
tracepoint (bts_trace,trace_order,(char*) "MDSource", 0, corid);
tracepoint (bts_trace,trace_order,(char*) "MDSource", 0, corid,0);
publish(_book_update, book, corid);
}
}
@@ -64,8 +64,9 @@ void OrderManager::on_securities(
me->services_data.limiter.add_securities(secs);
if (me->state == State::WAIT_SEC) {
LOG(OrderMan, Info, "Order manager received initial set of {} "
"securities. Waiting for orders now",
LOG(OrderMan, Info,
"Order manager received initial set of {} "
"securities. Waiting for orders now",
update.events->size());
// obtain recovered orders
me->state = State::WAIT_ORDERS;
@@ -342,8 +343,9 @@ void OrderManager::on_admin_data(const mercury::Update<NewAdminDataEvent> &m) {
if (m.events) {
if (me->state == State::WAIT_ADMIN) {
LOG(OrderMan, Info, "Order manager received admin data. Subscribing "
"to security list now ");
LOG(OrderMan, Info,
"Order manager received admin data. Subscribing "
"to security list now ");
me->state = State::WAIT_SEC;
subscribe<NewSecuritiesEvent>([this](auto const &sec_update) {
this->on_securities(sec_update);
@@ -356,5 +358,5 @@ void OrderManager::on_admin_data(const mercury::Update<NewAdminDataEvent> &m) {
}
}
}
}
}
} // namespace orderman
} // namespace bts
@@ -502,10 +502,8 @@ def create_client_dict(exchange_dict, parsed_fix_record):
def write_output_csv():
session_name = os.path.splitext(os.path.basename(args.quickfix_log))[0]
# with statement guarantees file closure regardless of matter how the block exists
output_file_name = "{0}_{1}_audittrail_{2:%Y%m%d}.csv".format("CME", session_name, args.date)
with open(output_file_name, 'wb') as outfile:
with open(args.output_file, 'wb') as outfile:
writer = csv.DictWriter(outfile, fieldnames=header_cols)
writer.writeheader()
writer.writerows(audit_entries)
@@ -587,10 +585,13 @@ def valid_date(s):
parser = argparse.ArgumentParser()
parser.add_argument("quickfix_log", help="the quickfix log[.gz] you wish to process", type=valid_file)
parser.add_argument("output_file", help="the destination csv file you wish to write")
parser.add_argument("-d", "--date", help="the date you wish to parse from the log, specified as YYYYmmdd",
default=datetime.datetime.today().strftime("%Y%m%d"), type=valid_date)
parser.add_argument("-s", "--server_lines_only",
help="does not produce any TO/FROM CLIENT logs, useful for testing in CERT", action="store_true")
parser.add_argument("-c", "--console_output_enabled",
help="destination output is optionally written to console", action="store_true")
args = parser.parse_args()
input_as_datetime = args.date
@@ -619,4 +620,5 @@ with file_opener(args.quickfix_log) as input_file:
create_audit_line_from_fix_line()
write_output_csv()
write_csv_to_console()
if args.console_output_enabled:
write_csv_to_console()
@@ -14,7 +14,7 @@ namespace api {class Security;}
namespace orderman {
constexpr int clordid_sz() {return 20;}
constexpr int price_sz() {return 15;}
constexpr int price_sz() {return 17;}
constexpr int quantity_sz() {return 6;}
inline void encode_clorid(OrderKey ok, SecurityKey sk,std::string *out) {
@@ -268,7 +268,7 @@ NativeOrder::~NativeOrder() {}
void NativeOrder::on_activate(Price p, Quantity q,
bts::orderman::OrderServices &services,
TickToTradeCorID cid) {
tracepoint(bts_trace, trace_order, (char *)"on_activate", 0, cid);
tracepoint(bts_trace, trace_order, (char *)"on_activate", 0, cid,0);
bts_assert(!me->services);
me->services = &services;
@@ -282,7 +282,7 @@ void NativeOrder::on_activate(Price p, Quantity q,
me->state.set_filled_quantity(0);
me->state.set_last_price(0);
me->state.set_avg_price(0);
me->session_services = &me->services->get_session_services(
get_native_state(me->state).routing_record().session());
me->price_encoding_precision =
@@ -303,8 +303,7 @@ void NativeOrder::on_activate(Price p, Quantity q,
AccountID(me->definition.account_id()));
if (!lqr.ok) {
LOG(OrderMan, Warn, "Unauthorized order attempted. User: {} on "
"Account: {}. Msg: {} Order: {} "
"Dropping order {}",
"Account: {}. Msg: {} Order: {}. Dropping order",
me->definition.user(), me->definition.account(), lqr.error_msg,
key().value());
@@ -357,8 +356,8 @@ void NativeOrder::on_activate(Price p, Quantity q,
case CustomOrderDefinition::kStopLimit:
me->create_price_bm = encoding.overwrite(
me->create_price_bm,
securities::encode_exchange_price(*me->sec, p).value(), 7,
price_sz());
securities::encode_exchange_price(*me->sec, p).value(),
me->price_encoding_precision, price_sz());
break;
case CustomOrderDefinition::kStop:
case CustomOrderDefinition::kMarket:
@@ -445,7 +444,7 @@ void NativeOrder::on_activate(Price p, Quantity q,
}
void NativeOrder::on_update(Price p, Quantity q, TickToTradeCorID cid) {
tracepoint(bts_trace, trace_order, (char *)"on_update", 0, cid);
tracepoint(bts_trace, trace_order, (char *)"on_update", 0, cid,0);
switch (me->state.status()) {
@@ -484,11 +483,12 @@ void NativeOrder::on_update(Price p, Quantity q, TickToTradeCorID cid) {
// are we under the messaging threshold?
if (!me->session_services->governor().can_send()) {
LOG(OrderMan, Warn, "Cannot update order {} because of messaging limits. ",
LOG(OrderMan, Warn,
"Cannot update order {} because of messaging limits. ",
key().value());
auto msg = "Messaging threshold breached";
if (parent_key() == null_order_key())
transition(me->state.status(),msg);
transition(me->state.status(), msg);
else {
me->state.set_last_msg(msg);
on_cancel(cid);
@@ -500,8 +500,8 @@ void NativeOrder::on_update(Price p, Quantity q, TickToTradeCorID cid) {
auto &encoding = me->update_encoding;
me->update_price_bm = encoding.overwrite(
me->update_price_bm,
securities::encode_exchange_price(*me->sec, p).value(), 7,
price_sz());
securities::encode_exchange_price(*me->sec, p).value(),
me->price_encoding_precision, price_sz());
me->update_quantity_bm =
encoding.overwrite(me->update_quantity_bm, q.value(), quantity_sz());
@@ -829,8 +829,10 @@ void NativeOrder::init_fix() {
cancel_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
// price
me->create_price_bm = create_encoding.add<fix::Price>(0, 7, price_sz());
me->update_price_bm = update_encoding.add<fix::Price>(0, 7, price_sz());
me->create_price_bm = create_encoding.add<fix::Price>(
0, me->price_encoding_precision, price_sz());
me->update_price_bm = update_encoding.add<fix::Price>(
0, me->price_encoding_precision, price_sz());
break;
case CustomOrderDefinition::kStop: {
@@ -862,8 +864,10 @@ void NativeOrder::init_fix() {
update_encoding.add<fix::StopPx>(encoded_stop_px, -1, -1);
// price
me->create_price_bm = create_encoding.add<fix::Price>(0, 7, price_sz());
me->update_price_bm = update_encoding.add<fix::Price>(0, 7, price_sz());
me->create_price_bm = create_encoding.add<fix::Price>(
0, me->price_encoding_precision, price_sz());
me->update_price_bm = update_encoding.add<fix::Price>(
0, me->price_encoding_precision, price_sz());
break;
}
default:
@@ -87,7 +87,7 @@ void SpreaderOrder::_on_time(const bts::mercury::TimerEvent& t_event){
}
void SpreaderOrder::_on_book_update(const BookUpdateEvent& book_event){
if (!_active) return;
tracepoint (bts_trace,trace_order,(char*) "_on_book_update", 0,book_event.correlation_id);
tracepoint (bts_trace,trace_order,(char*) "_on_book_update", 0,book_event.correlation_id,0);
_state_worker->on_book (book_event.correlation_id, book_event.book);
}
void SpreaderOrder::_on_child_order_update(const OrderStateUpdateEvent& ord_ev){
@@ -329,4 +329,4 @@ void SpreaderOrder::_send_check_termination(bool force){
_state_worker->on_check_termination();
}
}
}}
}}
@@ -4,29 +4,29 @@
namespace bts {
namespace orderman {
// the concept of a "driver" is the size and price of a leg that
// can sustain a quote in the quoted leg
class QuoterLegDriverData
{
// the concept of a "driver" is the size and price
// of a hedging leg that can "drive"/sustain a quote
// in the quoted leg. This price is then used to hedge
// a fill on the quoting leg
class QuoterLegDriverData{
public:
// driver_price and driver_quantity are the price and quantity
// in the hedging (or driver) leg that can drive a quoter_leg_quantity
// sized order in the quoting leg
Price driver_price;
Quantity driver_quantity;
Quantity quoter_leg_quantity;
// this is the quoting leg quantity
// that the hedging leg can sustain
Quantity quoter_leg_quantity;
QuoterLegDriverData()
:
driver_price(0.0),
driver_quantity(0),
quoter_leg_quantity(0)
{}
void set(Price new_driver_price, Quantity new_driver_quantity, Quantity new_quoter_leg_quantity)
{
void set(Price new_driver_price,
Quantity new_driver_quantity,
Quantity new_quoter_leg_quantity){
driver_price = new_driver_price;
driver_quantity = new_driver_quantity;
quoter_leg_quantity = new_quoter_leg_quantity;
}
};
}}
}}
@@ -2341,6 +2341,61 @@ TEST_CASE ("prehedge_payup", "[spreader]"){
REQUIRE(bts::securities::test_price_equality(out_price.value(),21.10,0.05));
}
}
// n legged spreader price evaluation /////////////////////
///////////////////////////////////////////////////////////
TEST_CASE ("nlegs_compute_driver", "[spreader]"){
bts::orderman::OrderKey order_key(1);
ContractLeg leg_1, leg_2, leg_3, leg_4;
fill_future_contract_leg (leg_1, 1, "CL", bts::api::Venue::VENUE_GLBX, 2018, 1, 15, 1.0, 1.0, api::Side::SIDE_BUY, 1.0, 0.01);
fill_future_contract_leg (leg_2, 2, "CL", bts::api::Venue::VENUE_GLBX, 2018, 2, 15, 1.0, 1.0, api::Side::SIDE_BUY, 1.0, 0.01);
fill_future_contract_leg (leg_3, 3, "CL", bts::api::Venue::VENUE_GLBX, 2018, 3, 15, 1.0, 1.0, api::Side::SIDE_BUY, 1.0, 0.01);
fill_future_contract_leg (leg_4, 4, "CL", bts::api::Venue::VENUE_GLBX, 2018, 4, 15, -4.0, -4.0, api::Side::SIDE_SELL, 1.0, 0.01);
std::vector<ContractLeg> legs;
legs.push_back(leg_1);legs.push_back(leg_2);legs.push_back(leg_3);legs.push_back(leg_4);
Security sec;
fill_synthetic_security (sec, 2000, "4legs", legs);
// execution params/order def
LegSpreaderParams lsp_1, lsp_2, lsp_3, lsp_4;
fill_leg_spreader_params(lsp_1, 1.0, false, 1.0);fill_leg_spreader_params(lsp_2, 1.0, false, 1.0);
fill_leg_spreader_params(lsp_3, 1.0, false, 1.0);fill_leg_spreader_params(lsp_4, -4.0, true, 1.0);
// // post hedge time out here
std::vector<LegSpreaderParams> params;
params.push_back(lsp_1);params.push_back(lsp_2);
params.push_back(lsp_3);params.push_back(lsp_4);
bts::api::orderman::OrderDefinition order_def;
fill_spreader_order_definition(order_def, Side::SIDE_BUY, sec, params);
// putting it together in SpreaderBookkeepingData
SpreaderPreActivationOrderServices::TestOnlySpreaderPreActivationOrderServices
testonly_spreader_pao_services = _create_spreader_pao_services(sec);
SpreaderPreActivationOrderServices pao_services (&testonly_spreader_pao_services);
std::vector<LegPropertyData> leg_props;
SpreaderUtils::resolve_synthetic_spread(pao_services, order_def, leg_props);
SpreaderManagerForTest spreader_manager (order_key, order_def, pao_services, leg_props);
SpreaderBookkeepingData& bookkeeping_data = spreader_manager.bookkeeping_data();
SECTION("compute_1"){
Book book_1;
uint16_t sizes_1[] = {12,18,20,19,23};
double prices_1[] = {65.31,65.32,65.34,65.36, 65.40};
fill_book (book_1, prices_1, sizes_1, bts::api::Side::SIDE_SELL);
spreader_manager.set_book(book_1, 0);
Book book_2;
uint16_t sizes_2[] = {1,5,20,12,15};
double prices_2[] = {64.40,64.41,64.43,64.45,64.50};
fill_book (book_2, prices_2, sizes_2, bts::api::Side::SIDE_SELL);
spreader_manager.set_book(book_2, 0);
Book book_3;
uint16_t sizes_3[] = {10,43,17,50,15};
double prices_3[] = {64.10,64.18,64.19,64.20,64.21};
fill_book (book_3, prices_3, sizes_3, bts::api::Side::SIDE_SELL);
spreader_manager.set_book(book_3, 0);
}
//std::vector<QuoterLegDriverData> driver_vector;
}
////////////////////////////////////////////////////////////
class RV
{
public:
@@ -22,6 +22,8 @@ namespace orderman {
using namespace api;
using namespace spark;
void fill_book(bts::orderman::Book&, double*, uint16_t*, bts::api::Side);
class SpreaderManagerForTest : public ISpreaderManager
{
private:
@@ -38,8 +40,15 @@ public:
{}
SpreaderBookkeepingData& bookkeeping_data() {return _bookkeeping_data;}
void set_book (const bts::orderman::Book& book, size_t leg_index)
{
void set_book (const bts::orderman::Book& book, size_t leg_index){
_bookkeeping_data.get_leg_data(leg_index).update_book(book);
}
void set_book (double* prices,
uint16_t* sizes,
bts::api::Side side,
size_t leg_index){
Book book;
fill_book (book, prices, sizes, side);
_bookkeeping_data.get_leg_data(leg_index).update_book(book);
}
SpreaderLegData& get_leg_state(size_t index){
@@ -240,43 +249,44 @@ SpreaderPreActivationOrderServices::TestOnlySpreaderPreActivationOrderServices _
/**********************************************************************/
/******************************book************************************/
/**********************************************************************/
void fill_book(bts::orderman::Book& book, double* prices, uint16_t* sizes, bts::api::Side side)
{
void fill_book(bts::orderman::Book& book,
double* prices,
uint16_t* sizes,
bts::api::Side side){
bts::orderman::BookSide& bookside = book.side(side);
for (size_t i = 0; i < book.n_levels(); i++)
bookside[i] = md::PriceSize::from_double<6>(prices[i], sizes[i]);
}
void fill_book(bts::orderman::Book& book, double* bid_prices, uint16_t* bid_sizes,
double* ask_prices, uint16_t* ask_sizes)
{
void fill_book(bts::orderman::Book& book,
double* bid_prices,
uint16_t* bid_sizes,
double* ask_prices,
uint16_t* ask_sizes){
bts::orderman::BookSide& bidside = book.side(api::Side::SIDE_BUY);
bts::orderman::BookSide& askside = book.side(api::Side::SIDE_SELL);
for (size_t i = 0; i < book.n_levels(); i++)
{
for (size_t i = 0; i < book.n_levels(); i++){
bidside[i] = md::PriceSize::from_double<6>(bid_prices[i], bid_sizes[i]);
askside[i] = md::PriceSize::from_double<6>(ask_prices[i], ask_sizes[i]);
}
}
bts::orderman::Book get_book(SecurityKey key,
size_t n_bid_levels,
double* bid_prices, uint16_t* bid_sizes,
double* bid_prices,
uint16_t* bid_sizes,
size_t n_ask_levels,
double* ask_prices, uint16_t* ask_sizes,
bool delete_arrays)
{
double* ask_prices,
uint16_t* ask_sizes,
bool delete_arrays){
bts::orderman::BookSide bidside, askside;
for (size_t i = 0; i < n_bid_levels; i++)
{
for (size_t i = 0; i < n_bid_levels; i++){
md::PriceSize bid = md::PriceSize::from_double<6>(bid_prices[i], bid_sizes[i]);
bidside[i] = bid;
}
for (size_t i = 0; i < n_ask_levels; i++)
{
for (size_t i = 0; i < n_ask_levels; i++){
md::PriceSize ask = md::PriceSize::from_double<6>(ask_prices[i], ask_sizes[i]);
askside[i] = ask;
}
if (delete_arrays)
{
if (delete_arrays){
delete[] bid_prices;
delete[] bid_sizes;
delete[] ask_prices;
@@ -290,7 +300,9 @@ bts::orderman::Book get_book(SecurityKey key,
double* ask_prices, uint16_t* ask_sizes,
bool delete_arrays)
{
return get_book(key, n_levels, bid_prices, bid_sizes, n_levels, ask_prices, ask_sizes, delete_arrays);
return get_book(key, n_levels, bid_prices,
bid_sizes, n_levels, ask_prices,
ask_sizes, delete_arrays);
}
/**********************************************************************/
/******************************hedger**********************************/
@@ -4,7 +4,41 @@ sqlite3 trace_data/trace.sqlite <<EOF
.separator ","
create table trace (seq integer, ts integer, hts text, msg text, cpu integer, tid integer,arg1 integer);
create index trace_seq_idx on trace(seq);
create table trace (ts integer, hts text, msg text, cpu integer, tid integer,arg1 integer,arg2 interger, arg3 integer);
.import trace_data/parsed_trace.txt trace
create table shots as
select hts, ts,arg1 seq, arg2 seq16,arg3 offset from trace where msg='SocketConnection.pre_write';
create table packets as
select hts, ts,arg1 seq, arg2 seq16,arg3 offset from trace where msg='onPacket';
create table paired_all as
select
shots.ts shot_ts,
shots.hts shot_hts,
packets.ts packet_ts,
packets.hts packet_hts,
shots.seq16 seq16,
packets.seq seq,
packets.offset offset
from
shots, packets
where
shots.seq16 = packets.seq16 and shots.ts > packets.ts ;
create table shot_packet as
select
(shot_ts - max(packet_ts)) / 1000 t,
shot_ts,
max(packet_ts) packet_ts,
max(seq) seq
from
paired_all
group by
shot_ts;
create table tick_to_trade as
select
shot_packet.*,
(shot_packet.t + packets.offset/1000) total_t,
packets.offset,
packets.seq16
from
shot_packet, packets where shot_packet.packet_ts = packets.ts;
EOF
@@ -4,7 +4,7 @@ import re
import fileinput
import sys
sample = "[11:13:02.685629121] (+0.000001447) pp-12 bts_trace:quoter: { cpu_id = 2 }, { pthread_id = 140322906629888 }, { msg = \"handle_updated\", arg1 = 3893975869889250, arg2 = 0 }"
sample = "[11:13:02.685629121] (+0.000001447) pp-12 bts_trace:quoter: { cpu_id = 2 }, { pthread_id = 140322906629888 }, { msg = \"handle_updated\", arg1 = 3893975869889250, arg2 = 0 , arg3 = 0 }"
rx = '\\[(?P<ts_hour>\\d\\d)\\:(?P<ts_min>\\d\\d)\\:(?P<ts_sec>\\d\\d)\\.(?P<ts_ns>\\d*).*?\\{ (?P<ctx1>.*?)\\ }, ' '\\{ (?P<ctx2>.*?) \\}, ' '\\{ (?P<udata>.*?) \\}'
rcx = re.compile(rx)
@@ -29,9 +29,9 @@ for line in sys.stdin:
parse_group(g.group('ctx1'),row)
parse_group(g.group('ctx2'),row)
parse_group(g.group('udata'),row)
# seq, ts, hts,msg,cpu,tid,arg1
#ts, hts,msg,cpu,tid,arg1,arg2, arg3
#print row
print ("%s,%s,%s,%s,%s,%s,%s" % (row['arg2'],row['t'],row['ts'],row['msg'],row['cpu_id'],row['pthread_id'],row['arg1']))
print ("%s,%s,%s,%s,%s,%s,%s,%s" % (row['t'],row['ts'],row['msg'],row['cpu_id'],row['pthread_id'],row['arg1'],row['arg2'],row['arg3']))
@@ -88,7 +88,7 @@ void PersistenceServiceServer::retrieve(const RetrieveRequest& request,
auto it = me->data.find(request.ns());
if (it == me->data.end()) {
LOG(persist,Error, "Client tried to retrieve specific rows from unknown namespace {}/{}",
LOG(persist,Warn, "Client tried to retrieve specific rows from unknown namespace {}/{}",
me->db,request.ns());
response.set_result ( RetrieveResponse::NO_SUCH_NS);
reply(response);
@@ -108,7 +108,7 @@ void PersistenceServiceServer::retrieve(const RetrieveRequest& request,
}
auto it = known_rows.find(k);
if (it == known_rows.end()) {
LOG(persist,Error, "Client tried to retrieve unknown row with key {} in {}/{}", k,
LOG(persist,Warn, "Client tried to retrieve unknown row with key {} in {}/{}", k,
me->db,request.ns());
response.set_result ( RetrieveResponse::DUPLICATE_KEY);
reply(response);
@@ -132,7 +132,7 @@ void PersistenceServiceServer::retrieve_all(const RetrieveAllRequest& request,
RetrieveResponse response;
if (request.ns().empty()) {
LOG(persist,Error, "Client used empty namespace while trying to retrieve rows in database {}",
LOG(persist,Warn, "Client used empty namespace while trying to retrieve rows in database {}",
me->db);
response.set_result ( RetrieveResponse::EMPTY_NS);
reply(response);
@@ -171,7 +171,7 @@ void PersistenceServiceServer::remove(const RemoveRequest& request,
auto it = me->data.find(request.ns());
if (it == me->data.end()) {
LOG(persist,Error, "Client used unknown namespace {} while trying to remove rows in database {}",
LOG(persist,Warn, "Client used unknown namespace {} while trying to remove rows in database {}",
request.ns(),
me->db);
response.set_result ( RemoveResponse::NO_SUCH_NS);
@@ -184,7 +184,7 @@ void PersistenceServiceServer::remove(const RemoveRequest& request,
for (auto &k : request.key()) {
if (keys.count(k)) {
LOG(persist,Error, "Client used duplicate key {} while trying to remove rows in {}/{}",
LOG(persist,Warn, "Client used duplicate key {} while trying to remove rows in {}/{}",
k,me->db,request.ns());
response.set_result ( RemoveResponse::DUPLICATE_KEY);
reply(response);
@@ -194,7 +194,7 @@ void PersistenceServiceServer::remove(const RemoveRequest& request,
keys.insert(k);
if (k.empty()) {
LOG(persist,Error, "Client used empty key while trying to remove rows in {}/{}",
LOG(persist,Warn, "Client used empty key while trying to remove rows in {}/{}",
me->db,request.ns());
response.set_result ( RemoveResponse::EMPTY_KEY);
reply(response);
@@ -202,7 +202,7 @@ void PersistenceServiceServer::remove(const RemoveRequest& request,
}
if (ns_rec.data.find(k) == ns_rec.data.end()) {
LOG(persist,Error, "Client tried to remove unknown row with key {} in {}/{}",
LOG(persist,Info, "Client tried to remove unknown row with key {} in {}/{}",
k, me->db, request.ns());
response.set_result ( RemoveResponse::NO_SUCH_KEY);
reply(response);
+2 -1
View File
@@ -11,11 +11,12 @@
TRACEPOINT_EVENT(bts_trace, trace_order,
TP_ARGS(char *, text, long long, argument1, long long, argument2),
TP_ARGS(char *, text, long long, argument1, long long, argument2, long long, argument3),
TP_FIELDS(
ctf_string(msg, text)
ctf_integer(long long, arg1,argument1)
ctf_integer(long long, arg2,argument2)
ctf_integer(long long, arg3,argument3)
))
#endif /* _BTS_TP_H */
+6 -2
View File
@@ -207,7 +207,11 @@ let clipLimitsView model dispatch =
let addRow _ = Array.append model.scratch.securityClipLimits.limit [| emptyLimit |] |> (ClipLimits >> dispatch)
div []
[
p [ClassName "is-size-7 has-text-grey-mid"][ str "Clip limits can be set for one security, for all securities in a product (by selecting \"All\" for securities), or for all products within a security type (by selecting \"All\" for both symbol and security)"]
div [ ClassName "columns" ][
div [ ClassName "column is-size-7 has-text-grey-mid" ]
[str "Clip limits can be set for one security, for all securities in a product (by selecting \"All\" for securities), or for all products within a security type (by selecting \"All\" for both symbol and security)"]
div [ ClassName "column" ][]
]
TableControl.createTableWithStyle (Some headerRow) rws "table-bordered" [Width "100%"]
span [ClassName "is-pulled-right"] [ Button.button "Add" "contrast-button" "plus" Button.Enabled addRow ]
span [ClassName "is-clearfix"][]
@@ -311,7 +315,7 @@ let productLimits model dispatch =
product = {
exchange = bts.api.Venue.GLBX
securityType = bts.api.SecurityType.FUTURE
securitySymbol = model.AllValueDisplay
securitySymbol = model.AllValue
}
longPositionLimit = 0u
shortPositionLimit = 0u
+4 -1
View File
@@ -43,7 +43,10 @@ let update msg model =
model, Cmd.Empty
| Submit ->
printfn "Login with %s %s" model.user model.password
model, loginMsg (model.user.ToLower()) model.password
let isAdmin = ((model.user.ToLower().Contains "bts") || (model.user.ToLower().Contains "admin"))
match isAdmin with
| true -> model, loginMsg (model.user.ToLower()) model.password
| false -> { model with error = "Only administrators are allowed to login" }, Cmd.Empty
| LoginFailure msg ->
{ model with error = msg }, Cmd.Empty
| LoginSuccess _ -> failwith "Handled externally. Should not get here."
+1
View File
@@ -55,6 +55,7 @@ let defaultScratchUser = {
miscTags = JSMap.empty<string>
smpInstruction = ""
maxOrderRatePerConnection = ""
location = ""
}
iceData = {
authorizedTrader = ""
+2 -2
View File
@@ -4,10 +4,10 @@ testers=(
#'pedro.pinto'
# 'eric.harding'
'jake.norbut'
# 'michael.harding'
'michael.harding'
'karl.ellefsen'
'pete.fisher'
# 'taha.afzal'
'taha.afzal'
'john.colvin'
'kevin.darby'
'brian.muhr'
+1 -1
View File
@@ -2,7 +2,7 @@ This is not a test, but common setup instructions that will be used for a few te
0. This needs sim market data **not** to be merged with replay (or cert), so we can create our own markets.
Add or update this line in your spark.conf (probably in ~/www/config)
Add or update this line in your spark.conf (probably in ~/sparkdata/config)
```
ExchangeSim {value {merge_with_md:false}}
```
+9 -9
View File
@@ -1,24 +1,24 @@
This test verifies that clip limits are followed, and rule precedence works correctly
1. Pick a future, lets say ESU8.
1. Pick a future, lets say SIZ1.
2. In the Spark Admin, go to accounts and select the default account for your user (let say ACC A1).
Go to Position Limits and enter large values (for both security and product level), so that
position limits are bypassed.
Go to Position Limits and enter large values for the Product Limits and remove all rows for the Security Limits
4. Now go to Clip Limits and delete all entries.
5. Enter an order and it should fail with a message that should tell exactly why.
5. Enter an order and it should fail with a message that should tell exactly why. Make sure the orderbook and the
ladder show the message.
6. Now enter a rule for ESU8 (in the first version we can not specify securities, so go as far as the symbol (ES)).
6. Now enter a Clip Limit for SIZ1.
Enter a Clip Size of 10. Make sure orders > 10 are rejected and < 10 are allowed.
7. Now enter a non ES future order, lets say SI. Enter a 1 lot and it should be rejected.
7. Now enter an order for another future, lets say SIN1. Enter a 1 lot and it should be rejected.
8. Enter another rule, GLBX, FUTURES, * and enter a clip limit of 100.
8. Enter another rule, GLBX, FUTURES, All, All and enter a clip limit of 100.
9. Now try the SI order again. Verify it does the right thing for the clip limit you entered in 8.
9. Now try the SIN1 order again. Verify it does the right thing for the clip limit you entered in 8.
10. Verify that ESU8 is still controlled by a clip size of 10.
10. Verify that SIZ1 is still controlled by a clip size of 10.
11. Enter a future spread order. It should be rejected since we don't have any clip limits for futures.
@@ -1,5 +1,5 @@
This test verifies that security position limits are enforced correctly. (Position limits are
enforced at both the security and account level)
enforced (per account) at the product level and optionally at the security level)
0. Clear up your orders and fills so we don't have any lingering positions
(run rm -r orders and rm -r fills from /sparkdata/data/databases). Restart your sparkd
@@ -14,7 +14,7 @@ clip limits don't interfere with this test.
4. Enter an ESU8 order. It should be rejected. Make sure the rejection message makes sense
5. Now enter a product level rule for GLBX, Future, ES, 1,000,000, 1,000,000 (to bypass it),
and a security level rule GLBX, Future, ES, 50, 100
and a security level rule GLBX, Future, ES, ESU8, 50, 100.
6. Enter a 10 lot. This brings our 'position' to 10 (where 'positions' = fills + working orders).
Enter more orders to get it to 50. Now try to get past 50 and you should be stopped with a clear message.
@@ -24,12 +24,13 @@ don't cancel these yet.
the way to 150 (net 100 short), but not beyond that. Verify that.
8. Cancel all your buy orders. Cancel some of your sell orders to get the net short position to 50.
Start selling again, and make sure you are stopped at 100.
Start selling again, and make sure you are stopped at 100. Cancel all ESU8 orders.
9. Try another future, lets say SIU8. Since we don't have a position rule for it, it should fail.
10. Enter a new rule for the product (and use All for the symbol) and enter 10 for the long and short limits.
11. Now enter a 1 lot SIU8 again. Keep buying more and make sure you are stopped at the long limit of 10.
11. Now enter a 1 lot SIU8 again. Keep buying more and make sure you are stopped at the long limit of 10. Keep
these working
12. Start selling and make sure you are stopped at the short limit.
12. Start selling and make sure you are stopped at the short limit (remember to account the buys from 11)
+22 -15
View File
@@ -1,29 +1,36 @@
This test verifies the following 2 things
i. spread legs fills (and working orders) are applied toward enforcing
i. future and spread product limits can co-exist and work correctly
ii. spread legs fills (and working orders) are applied toward enforcing
the position limits for the legs
ii. leg limits are checked when entering spread orders
iii. leg limits are checked when entering spread orders
i:
1. Pick a 2 legged spread (lets say SIU8-SIZ8). Set the clip limits high so that they don't interfere.
Set the product position limits high as well so they don't interfere either.
1. Pick a 2 legged spread (lets say SIU8-SIZ8). Set the clip limits high for both spreads and futures
so that they don't interfere. Remove all Security Position limits.
2. For the security limits (which is what we will be testing), we want Max Long and Max Short of 20 and 30
for the SI futures and 100 and 110 for the SI spreads respectively.
2. For the Product Limits, set Max Long and Max Short of 100 and 110
for the SI futures and 20 and 30 for the SI spreads respectively.
3. Verify that the limits set in 2 work for futures(remember working orders count toward limit enforcement so you dont need
fills). Cancel all the orders.
3. Enter a 15 lot buy order for the spread. This 15 should count toward the leg limits. The leg long limit
is 20. So enter a 5 lot buy for SIU8 which should be allowed, but a subsequent 1 lot will violate the 20 long
and should be rejected.
4. Verify that the limits set in 2. work for spreads. Cancel all the orders.
4. Now enter a 15 lot sell for SIZ8 which should be allowed but a subsequent one lot should not be allowed, as it
will violate the short limit of 30.
5. Make these product limits 1,000,000 to make them irrelevant
ii:
5. Cancel all orders
6. For security limits enter long 10 and short 20 for SIU8 and SIZ8 futures respectively and 50 and 60 for
the SIU8-SIZ8 spread.
6. Enter a 15 lot buy for SIU8. Any spread buy order of > 5 should be rejected, since this will violate the 20 long limit.
7. Enter a 5 lot buy for SIU8-SIZ8. This 5 should count toward SIU8 long limit (which is 10). Enter
a 5 lot SIU8 buy, which should be allowed but a subsequent 1 lot buy should be rejected. Similiary, the
spreader order should count toward the SIZ8 short limit of 20. Enter a 15 lot sell on SIZ8, and a subsequent
1 lot should be rejected.
8. Enter a 20 sell for SIZ8. Any spread buy order of > 10 should be rejected since it will
violate the 30 short limit.
8. Cancel all orders
iii:
Enter a 11 lot spread order. It should be rejected because of the 10 lot limit on SIU8.
+35
View File
@@ -0,0 +1,35 @@
- Open up a ladder for a liquid future
- Make sure you have limits to trade this future
- Select Join order from the menu
Label 1) Set join thresh to absolute 10
Label 2) Set initial tick offset to 2
The goal of the join order is to watch the opposite-inside market and join when the market *flips and
has at least threshold size
*flip is when the best offer becomes the best bid, or the market trades away from you (the line moves up in the gui)
Label 3) Put an order in to way down in the bid side of the book
- Because of the parameter in label 2, the order should instead join two levels below the best bid
- Watch the opposite inside market, if it flips make sure the order moves itself to join the new best bid (former offer)
Goto Label 2 and set tick offset to 0
{
Orders should then go in where you put them
}
Goto Label l and test the ratio threshold
{
- Use a threshold of at least 1.0
}
Goto Label 3 and try a sell order
{
}
Now do this test again with "Enable Hedge" checked and hedge ticks set to 1, hedge type set to limit
This should modify the behavior such that the algorithm will send a limit order on the opposite
side of the market, one tick away from fill price in a quantity equivalent to the amount of the fill
+28
View File
@@ -0,0 +1,28 @@
- Open up a ladder for a liquid future
- Make sure you have limits to trade this future
- Select Lean order from the menu
Label 1) Set cross thresh to absolute 10
The goal of the lean order is to watch the opposite-inside market size and *cross when that size goes below the threshold
(this also implies a cross if that size goes to zero and the market trades away from you)
(if the market trades toward you, we just start watching the new ask)
*cross means take an order working on the bid and 'cross' by buying into the asks. This is also called 'paying up'
- Open up order book and fills
Label 2) Put an order in to Join the best bid
- Watch the opposite inside market, if it dips below the threshold (or trades away from you) make sure the order moves itself to cross
- Verify that the order filled at the offer price
- If the opposite inside market does not dip below threshhold, you should expect to be eventually filled at the bid price
- Verify that these fills come in at the proper price, crosses at the offer, working fills at the bid
Goto Label 2 and join the ask instead of the bid
{
}
Goto Label l and test the ratio threshold
{
- Use a threshold of at least 1.0
- Test with a larger order (say 100) to trigger crosses more quickly and across different price levels
}
+32
View File
@@ -0,0 +1,32 @@
- Open up a ladder for a liquid future
- Make sure you have limits to trade this future
- Select Tick order from the menu
Label 1) Set cross thresh to absolute 10
Label 2) Set initial tick offset to 1
The goal of the tick order is to watch the opposite-inside market size and *cross when that size goes below the threshold
(this also implies a cross if that size goes to zero and the market trades away from you)
(if the market trades toward you, the algo will 'detach' or become a regular limit order by default)
*cross means take an order working on the bid and 'cross' by buying into the asks. This is also called 'paying up'
- Open up order book and fills
Label 3) Put an order in to way down in the bid side of the book
- Because of the parameter in label 2, the order should instead join at the best bid
- Watch the opposite inside market, if it dips below the threshold or the market trades away make sure the order moves itself to cross
- Verify that the order filled at the offer price
- If the opposite inside market does not dip below threshhold, you should expect to be eventually filled at the bid price
- If the opposite inside market trades toward you, you should see the algo detach and the limit be left working
- Verify that these fills come in at the proper price, crosses at the offer, working fills at the bid
Goto Label 2 and join the ask instead of the bid
{
}
Goto Label l and test the ratio threshold
{
- Use a threshold of at least 1.0
- Test with a larger order (say 100) to trigger crosses more quickly and across different price levels
}
+16
View File
@@ -0,0 +1,16 @@
- Open up a ladder for a liquid future
- Make sure you have limits to trade this future
- Select Top order from the menu
Label 1) Set top thresh to absolute 50, start with a bid at the best, 10 lot
The goal of the top order is to not trade by yourself.
IF the order is on the market (current bid price) AND the quantity on that bid price is below top
thresh then cancel the order else do nothing
- Verify that orders immediately cancel if you put them in and inside market with less then the threshold
- Verify that orders cancel if they end up working at an inside market with less than threshold size
Goto Label l and test a sell
+9 -6
View File
@@ -12,9 +12,12 @@ clear your fills database:
and you may also want to clear your orders for a clean slate:
rm ~/sparkdata/data/databases/orders/*
Throughout the test we'll refert to accounts BTS1 and BTS2. These specific accouts aren't necessary, but rather that we have
fills in multiple distinct accounts.
If your Ladder is not centered on at 2500 after entering your first order you may need to clear other databases
rm ~/sparkdata/data/databases/*
Throughout the test we'll refer to accounts BTS1 and BTS2. These specific accounts aren't necessary, but rather that we have
fills in multiple distinct accounts.
Bring up the pnl form (empty).
Bring up a ladder form. It should be completely empty since we're controlling the md. For this exercise we'll be using ES.
@@ -58,14 +61,14 @@ The simulator might not work for orders left up overnight
If your ladder shows no working orders, place a buy order with price 2500 and qty 100
Sell a 1 lot as the current bid
The SOD should still show -1
The Buy and Sell Qty should show 1 (we crossed ourself)
The Buy and Sell Qty should show 1 (we crossed ourselves)
The net position will still say -1
Now switch to BTS2
Sell a 5 lot at the current bid
The SOD should still show -1
BTS1 Buy qty should show 5
BTS1 Buy qty should show 6 (1 (crossed) + 5 (BTS2))
BTS1 Sell Qty should show 1
Net Pos should show 3 (-1 (SOD) + 5 (Buys) -1 (Sells))
Net Pos should show 4 (-1 (SOD) + 6 (Buys) -1 (Sells))
BTS1 PnL should show 12.5
Test sorting and filtering
+3
View File
@@ -22,10 +22,13 @@ function post_issue()
source cycle_info.txt
# invoke with ./post_to_jira.sh <allocation_file> <ppinto_password>
# if authentication fails try to log out / log back in to jira using
# their web page
for assignment in $( cat $1); do
echo $assignment
IFS=: read -a fields <<<"$assignment"
tester=${fields[0]}
test=${fields[1]}
post_issue $2
sleep 5
done
+6 -2
View File
@@ -1,3 +1,7 @@
#!/bin/bash
cid=`docker ps | grep bluetradingsystems/linux_docker | awk '{print $1}'`
docker exec $cid /bin/bash -c "cd build/clang_debug/ && ninja"
if [ -f /.dockerenv ]; then
ninja
else
cid=`docker ps | grep bluetradingsystems/linux_docker | awk '{print $1}'`
docker exec $cid /bin/bash -c "cd build/clang_debug/ && ninja"
fi
+2 -2
View File
@@ -6,7 +6,7 @@ cd $DIR/../build/
rm -rf clang_debug
mkdir clang_debug
cd clang_debug
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=`realpath ../../tools/linux_control/rtags.sh` ../..
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_CXX_COMPILER=`realpath ../../tools/linux_control/rtags.sh` ../..
cd ..
rm -rf ninja_debug
@@ -18,7 +18,7 @@ cd ..
rm -rf ninja_release
mkdir ninja_release
cd ninja_release
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_CXX_COMPILER=g++ ../..
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ ../..
cd ..