Merged with master
This commit is contained in:
commit
4febc07aa0
68 files changed
+1712
-673
No files matched your search
Vendored
+3
-3
@@ -6,7 +6,7 @@
|
||||
"name": "(gdb) Launch",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceRoot}/build/ninja_debug/src/server/sparkd/sparkd",
|
||||
"program": "${workspaceRoot}/build/ninja_debug/server/sparkd/sparkd",
|
||||
"args": ["run"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceRoot}/build/ninja_debug/src/server/sparkd",
|
||||
@@ -75,10 +75,10 @@
|
||||
"name": "SparkVM Launch",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "/home/bts/spark/build/ninja_debug/src/server/sparkd/sparkd",
|
||||
"program": "/home/bts/spark/build/ninja_debug/server/sparkd",
|
||||
"args": ["run"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "/home/bts/spark/build/ninja_debug/src/server/sparkd/",
|
||||
"cwd": "/home/bts/spark/build/ninja_debug/server/",
|
||||
"environment": [],
|
||||
"externalConsole": true,
|
||||
"MIMode": "gdb",
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
# Release Notes
|
||||
|
||||
## 1.5.0
|
||||
### User Visible Changes
|
||||
#### User Interface Improvements
|
||||
- Removed security key field from most grids
|
||||
- Removed trade key field from time and sales grid
|
||||
- Fixed the "Since Open" time filter to use the exchange open time rather than 8:30 AM
|
||||
- Fixed the floating order book so that rows are no longer
|
||||
highlighted after an order is modified
|
||||
#### Algos
|
||||
- Added OCO Algo
|
||||
- An OCO order creates a relationship between a child order and a 'stop' or 'other' order such that when one of these is cancelled, both cancel, or when one is filled, the other order's size is debited in the amount of the fill. Composing this order with Cover simulates scalping functionality
|
||||
#### SDK
|
||||
- Improved SDK documentation and usability
|
||||
- Dynamic orders are now properly identified in the order book
|
||||
### Internal Changes
|
||||
- Improved robustness of limit system test
|
||||
- Extensive market data refactoring allow for security definition updates
|
||||
|
||||
|
||||
## 1.4.11
|
||||
### New Features
|
||||
- Floating Order Book
|
||||
@@ -12,6 +31,12 @@
|
||||
- Press the green checkbox to finalize your change and update the order
|
||||
### SDK
|
||||
- Improved SDK documentation and usability
|
||||
### User Interface Improvements
|
||||
- The following spreader quoting parameters have been deprecated:
|
||||
- Hidden parameter
|
||||
- Price Type setting of the Conditional parameter
|
||||
### Bug Fixes
|
||||
- Fixed a limit enforcement problem that could lead to 0 sized orders being sent to the exchange
|
||||
|
||||
## 1.4.10
|
||||
### Bug Fixes
|
||||
|
||||
+1
-1
Submodule docker/linux updated: f6d8d59860...8ee9692597.
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
},
|
||||
{
|
||||
"uri": "sftp://bts:BT5u53r@sparkvm:22/home/bts/",
|
||||
"name": "sparkvm"
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"files.associations": {
|
||||
"utility": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"list": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"vector": "cpp",
|
||||
"xhash": "cpp",
|
||||
"xstring": "cpp",
|
||||
"system_error": "cpp",
|
||||
"array": "cpp",
|
||||
"string_view": "cpp",
|
||||
"xutility": "cpp",
|
||||
"*.ipp": "cpp"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ namespace bts.shell {
|
||||
public static GridColumnSettings day_change => new GridColumnSettings(col_id(Columns.DayChange), DefaultColumnHeaders.DayChange, width: DefaultColumnWidths.Price, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
|
||||
public static GridColumnSettings session_low => new GridColumnSettings(col_id(Columns.SessionLow), DefaultColumnHeaders.SessionLow, width: DefaultColumnWidths.Price, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
|
||||
public static GridColumnSettings session_high => new GridColumnSettings(col_id(Columns.SessionHigh), DefaultColumnHeaders.SessionHigh, width: DefaultColumnWidths.Price, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, width: DefaultColumnWidths.SecurityKey);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, is_visible: false, width: DefaultColumnWidths.SecurityKey);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ namespace mbts.spark {
|
||||
price_filter.load_state(filters.price);
|
||||
size_filter.load_state(filters.size);
|
||||
aggressor_filter.load_state(filters.aggressor_sides);
|
||||
trade_key_filter.load_state(filters.trade_key);
|
||||
security_key_filter.load_state(filters.security_key);
|
||||
}
|
||||
// Columns
|
||||
@@ -47,7 +46,6 @@ namespace mbts.spark {
|
||||
add_column(TimeAndSalesView.Columns.Price, DefaultColumnHeaders.Price, DefaultColumnWidths.Price, nameof(Row.price), price_filter, DataGridFilterKnownTemplates.DoubleMinMax, System.Windows.HorizontalAlignment.Right);
|
||||
add_column(TimeAndSalesView.Columns.Size, DefaultColumnHeaders.Size, DefaultColumnWidths.Size, nameof(Row.size), size_filter, DataGridFilterKnownTemplates.UIntMinMax, System.Windows.HorizontalAlignment.Right);
|
||||
add_column(TimeAndSalesView.Columns.Aggressor, DefaultColumnHeaders.Aggressor, DefaultColumnWidths.Aggressor, nameof(Row.aggressor_side), aggressor_filter, DataGridFilterKnownTemplates.EnumValues);
|
||||
add_column(TimeAndSalesView.Columns.TradeKey, DefaultColumnHeaders.TradeKey, DefaultColumnWidths.TradeKey, nameof(Row.trade_key), trade_key_filter, DataGridFilterKnownTemplates.Regex);
|
||||
add_column(TimeAndSalesView.Columns.SecurityKey, DefaultColumnHeaders.SecurityKey, DefaultColumnWidths.SecurityKey, nameof(Row.security_key), security_key_filter, DataGridFilterKnownTemplates.Regex);
|
||||
void add_column(TimeAndSalesView.Columns col_key, string header, double width, string sort_member_path, IDataGridColumnFilter filter, string filter_template, System.Windows.HorizontalAlignment h_alignment = System.Windows.HorizontalAlignment.Left) =>
|
||||
columns.Add(new TimeAndSalesColumn(
|
||||
@@ -66,7 +64,7 @@ namespace mbts.spark {
|
||||
_resources.AddRange(
|
||||
show_ladder,
|
||||
DataGridFilterHelper.hook_filters(
|
||||
rows_view, time_filter, security_filter, price_filter, size_filter, aggressor_filter, trade_key_filter, security_key_filter),
|
||||
rows_view, time_filter, security_filter, price_filter, size_filter, aggressor_filter, security_key_filter),
|
||||
settings_manager.subscribe_current().OnDispatcher().Subscribe(grid_settings_manager)
|
||||
);
|
||||
rows_view.set_sort_descriptions(startup_data.sorting_criterion, columns);
|
||||
@@ -103,7 +101,6 @@ namespace mbts.spark {
|
||||
public IDataGridColumnPersistentFilter<Row, UIntMinMaxState> size_filter { get; } = new UIntMinMax<Row>(r => r.size, nameof(Row.size));
|
||||
public IDataGridColumnPersistentFilter<Row, AggressorSide[]> aggressor_filter { get; } = DiscreteValuesFilterVM.Create<Row, AggressorSide>(EnumHelper.get_values<AggressorSide>().ToArray(), r => r.aggressor_side, nameof(Row.aggressor_side));
|
||||
public IDataGridColumnPersistentFilter<Row, string> security_key_filter { get; } = new RegexFilterVM<Row>(r => r.security_key.ToString(), nameof(Row.security_key));
|
||||
public IDataGridColumnPersistentFilter<Row, string> trade_key_filter { get; } = new RegexFilterVM<Row>(r => r.trade_key.ToString(), nameof(Row.trade_key));
|
||||
|
||||
FilterStates _get_filter_states() =>
|
||||
new FilterStates {
|
||||
@@ -111,7 +108,6 @@ namespace mbts.spark {
|
||||
security = security_filter.get_state(),
|
||||
price = price_filter.get_state(),
|
||||
size = size_filter.get_state(),
|
||||
trade_key = trade_key_filter.get_state(),
|
||||
security_key = security_key_filter.get_state(),
|
||||
aggressor_sides = aggressor_filter.get_state()
|
||||
};
|
||||
@@ -175,7 +171,6 @@ namespace mbts.spark {
|
||||
case TimeAndSalesView.Columns.Price: return _price_text;
|
||||
case TimeAndSalesView.Columns.Size: return _size_text;
|
||||
case TimeAndSalesView.Columns.Aggressor: return _aggressor_text;
|
||||
case TimeAndSalesView.Columns.TradeKey: return _trade_key_text;
|
||||
case TimeAndSalesView.Columns.SecurityKey: return _security_key_text;
|
||||
default: return null;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace mbts.ui.spark {
|
||||
/// Interaction logic for TimeAndSalesView.xaml
|
||||
/// </summary>
|
||||
partial class TimeAndSalesView : UserControl {
|
||||
public enum Columns { Time, Security, Price, Size, OrderType, TradeKey, SecurityKey, Aggressor }
|
||||
public enum Columns { Time, Security, Price, Size, OrderType, SecurityKey, Aggressor }
|
||||
|
||||
public TimeAndSalesView() =>
|
||||
InitializeComponent();
|
||||
|
||||
@@ -84,8 +84,7 @@ namespace bts.shell {
|
||||
public static GridColumnSettings price => new GridColumnSettings(col_id(Columns.Price), DefaultColumnHeaders.Price, width: DefaultColumnWidths.Price, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
|
||||
public static GridColumnSettings size => new GridColumnSettings(col_id(Columns.Size), DefaultColumnHeaders.Size, width: DefaultColumnWidths.Size, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
|
||||
public static GridColumnSettings aggressor => new GridColumnSettings(col_id(Columns.Aggressor), DefaultColumnHeaders.Aggressor, width: DefaultColumnWidths.Aggressor);
|
||||
public static GridColumnSettings trade_key => new GridColumnSettings(col_id(Columns.TradeKey), DefaultColumnHeaders.TradeKey, width: DefaultColumnWidths.TradeKey);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, width: DefaultColumnWidths.SecurityKey);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, is_visible:false, width: DefaultColumnWidths.SecurityKey);
|
||||
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criterion {
|
||||
get {
|
||||
@@ -100,7 +99,6 @@ namespace bts.shell {
|
||||
yield return price;
|
||||
yield return size;
|
||||
yield return aggressor;
|
||||
yield return trade_key;
|
||||
yield return security_key;
|
||||
}
|
||||
}
|
||||
@@ -117,8 +115,8 @@ namespace bts.shell {
|
||||
public DoubleMinMaxState price;
|
||||
[ProtoMember(4)]
|
||||
public UIntMinMaxState size;
|
||||
[ProtoMember(5)]
|
||||
public string trade_key;
|
||||
// [ProtoMember(5)]
|
||||
// ProtoMember 5 cannot be used further
|
||||
[ProtoMember(6)]
|
||||
public string security_key;
|
||||
[ProtoMember(7)]
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace bts.shell {
|
||||
public static GridColumnSettings description => new GridColumnSettings(col_id(Columns.Description), DefaultColumnHeaders.Description, width: DefaultColumnWidths.Description);
|
||||
public static GridColumnSettings n_legs => new GridColumnSettings(col_id(Columns.n_legs), DefaultColumnHeaders.N_Legs, width: DefaultColumnWidths.N_Legs);
|
||||
public static GridColumnSettings n_working_orders => new GridColumnSettings(col_id(Columns.n_working_orders), DefaultColumnHeaders.N_Working_Orders, width: DefaultColumnWidths.N_Working_Orders);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, width: DefaultColumnWidths.SecurityKey);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, is_visible: false, width: DefaultColumnWidths.SecurityKey);
|
||||
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criterion {
|
||||
get {
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace mbts.spark {
|
||||
//new EnableHedgeModel(), //TAHA_SPREADER
|
||||
new HedgeRatioModel(),
|
||||
//new MinLeanQtyModel(), //TAHA_SPREADER
|
||||
new QuoteHiddenModel(),
|
||||
//new QuoteHiddenModel(),
|
||||
new MarketDataTypeModel(),
|
||||
new MarketDataCalculationModel(),
|
||||
new QuoteThrottleEnabledModel(quote_throttle_inside_ticks, quote_throttle_outside_ticks),
|
||||
@@ -213,7 +213,7 @@ namespace mbts.spark {
|
||||
quote_throttle_outside_ticks,
|
||||
new ConditionalQuoteEnabledModel(conditional_quoting_ticks, conditional_quoting_price_type),
|
||||
conditional_quoting_ticks,
|
||||
conditional_quoting_price_type,
|
||||
//conditional_quoting_price_type,
|
||||
//new QuoteInsideMarketThrottleEnabledModel(quote_inside_market_throttle_ticks, quote_inside_market_throttle_min_move),
|
||||
//quote_inside_market_throttle_ticks,
|
||||
//quote_inside_market_throttle_min_move,
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace mbts.spark {
|
||||
add_col(Columns.Account, DefaultColumnHeaders.Account, r => r.account, nameof(Row.account), account_filter, DataGridFilterKnownTemplates.DiscreteValues, DefaultColumnWidths.Account);
|
||||
add_col(Columns.Exchange, DefaultColumnHeaders.Exchange, r => r.exchange.ToString(), nameof(Row.exchange), exchange_filter, DataGridFilterKnownTemplates.DiscreteValues, DefaultColumnWidths.Exchange);
|
||||
add_col(Columns.TimeInForce, DefaultColumnHeaders.TimeInForce, r => r.time_in_force.ToString(), nameof(Row.time_in_force), time_in_force_filter, DataGridFilterKnownTemplates.DiscreteValues, DefaultColumnWidths.TimeInForce);
|
||||
columns.Add(new OrderTypeColumn<Columns>(Columns.OrderType, new Binding(nameof(Row.order_type)), new Binding(nameof(Row.order_metadata)), order_type_filter) { id = col_id(Columns.OrderType), sort_member_path = nameof(Row.order_type) });
|
||||
columns.Add(new OrderTypeColumn<Columns>(Columns.OrderType, new Binding(nameof(Row.order_type)), new Binding(nameof(Row.order_metadata)), new Binding(nameof(Row.dynamic_order_type_display_name)), order_type_filter) { id = col_id(Columns.OrderType), sort_member_path = nameof(Row.order_type) });
|
||||
columns.Add(new SideColumn<Row, Columns>(Columns.Side, r => r.side, side_filter) { id = col_id(Columns.Side), sort_member_path = nameof(Row.side) });
|
||||
add_col(Columns.Size, DefaultColumnHeaders.Size, r => r.size.ToString(), nameof(Row.size), size_filter, DataGridFilterKnownTemplates.UIntMinMax, DefaultColumnWidths.Size);
|
||||
add_col(Columns.Price, DefaultColumnHeaders.Price, r => r.format_price(r.price), nameof(Row.price), price_filter, DataGridFilterKnownTemplates.DoubleMinMax, DefaultColumnWidths.Price);
|
||||
@@ -196,6 +196,7 @@ namespace mbts.spark {
|
||||
public DateTime fill_time => _fill.Timestamp.ToDateTimeOffset().LocalDateTime;
|
||||
public TimeInForce time_in_force => _order.time_in_force();
|
||||
public OrderType order_type => _order.order_type();
|
||||
public string dynamic_order_type_display_name => _order.dynamic_order_type_display_name();
|
||||
public OrderMetadata order_metadata => _model.factory.get_metadata(_order.Def.CustomDef.CustomCase);
|
||||
public string account { get; private set; }
|
||||
public string user => _order.user();
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace bts.shell {
|
||||
public static GridColumnSettings fill_kind => new GridColumnSettings(col_id(Columns.FillKind), DefaultColumnHeaders.FillKind, width: DefaultColumnWidths.FillKind);
|
||||
public static GridColumnSettings fill_key => new GridColumnSettings(col_id(Columns.FillKey), DefaultColumnHeaders.FillKey, width: DefaultColumnWidths.FillKey);
|
||||
public static GridColumnSettings order_key => new GridColumnSettings(col_id(Columns.OrderKey), DefaultColumnHeaders.OrderKey, width: DefaultColumnWidths.OrderKey);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, width: DefaultColumnWidths.SecurityKey);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, is_visible: false, width: DefaultColumnWidths.SecurityKey);
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criterion {
|
||||
get {
|
||||
yield return new SortingCriteria(fill_time.id, false);
|
||||
|
||||
@@ -559,7 +559,7 @@ namespace mbts.spark {
|
||||
public class OrderBookOrderTypeColumn : OrderTypeColumn<Columns>, ICVOrderBookColumn {
|
||||
ListSortDirection? _cached_sort_direction;
|
||||
public OrderBookOrderTypeColumn(IDataGridColumnPersistentFilter<OrderRecordTuple, OrderType[]> filter)
|
||||
: base(Columns.OrderType, new Binding(nameof(OrderBookRowVM.order_type)), new Binding(nameof(OrderBookRowVM.order_metadata)), filter) {
|
||||
: base(Columns.OrderType, new Binding(nameof(OrderBookRowVM.order_type)), new Binding(nameof(OrderBookRowVM.order_metadata)), new Binding(nameof(OrderBookRowVM.dynamic_order_type_display_name)), filter) {
|
||||
id = key.ToString();
|
||||
this.filter = filter;
|
||||
sort_member_path = nameof(OrderBookRowVM.order_type);
|
||||
@@ -651,7 +651,7 @@ namespace mbts.spark {
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
|
||||
grid.Children.Add(toggle_button);
|
||||
grid.Children.Add(security_view);
|
||||
grid.HorizontalAlignment = HorizontalAlignment.Center;
|
||||
|
||||
grid.VerticalAlignment = VerticalAlignment.Center;
|
||||
//
|
||||
var border = new Border { Child = grid };
|
||||
|
||||
@@ -62,6 +62,7 @@ namespace mbts.spark {
|
||||
public string symbol => _security_md.symbol();
|
||||
// Def
|
||||
public CustomOrderDefinition.CustomOneofCase order_type => order.order_type();
|
||||
public string dynamic_order_type_display_name => order.dynamic_order_type_display_name();
|
||||
public OrderSubType order_sub_type => order.sub_type();
|
||||
public string order_sub_type_text => _fmt_order_sub_type(order_sub_type);
|
||||
public Side side => order.side();
|
||||
@@ -130,7 +131,10 @@ namespace mbts.spark {
|
||||
|
||||
public ICommand modify_order_quantity => _modify_order_quantity ??
|
||||
(_modify_order_quantity = new DelegateCommand(
|
||||
(desired_quantity) => _owner.modify_order_quantity(this, (uint)desired_quantity),
|
||||
(desired_quantity) => {
|
||||
_owner.modify_order_quantity(this, (uint)desired_quantity);
|
||||
_unselect_me();
|
||||
},
|
||||
(desired_quantity) =>
|
||||
(desired_quantity != null && this.status == OrderStatus.Working && (uint)desired_quantity != this.quantity)
|
||||
|| is_qty_dirty
|
||||
@@ -139,12 +143,20 @@ namespace mbts.spark {
|
||||
|
||||
public ICommand modify_order_price => _modify_order_price ??
|
||||
(_modify_order_price = new DelegateCommand(
|
||||
(desired_price) => _owner.modify_order_price(this, (double)desired_price),
|
||||
(desired_price) => {
|
||||
_owner.modify_order_price(this, (double)desired_price);
|
||||
_unselect_me();
|
||||
},
|
||||
(desired_price) =>
|
||||
(desired_price != null && this.status == OrderStatus.Working && (double)desired_price != this.price)
|
||||
|| is_price_dirty
|
||||
)
|
||||
);
|
||||
);
|
||||
|
||||
private void _unselect_me() {
|
||||
this.is_selected = false;
|
||||
_owner.current_row = null;
|
||||
}
|
||||
|
||||
// These fns present a way for the orderbook to avoid noisy, intermittent collection changes during "Expand/Collapse All" ops,
|
||||
// when incremental changes are ignored in favor of a full reset, after 'is_expanded' is updated for all rows.
|
||||
|
||||
@@ -76,7 +76,19 @@ namespace mbts.spark {
|
||||
public ObservableAppendCollection<DIYGrid.ColumnBase> columns { get; }
|
||||
public ObservableCollection<DIYGrid.ColumnBase> core_columns => _columns;
|
||||
public ObservableCollection<OrderBookRowVM> rows => _row_collection;
|
||||
public OrderBookRowVM current_row { get => _current_row.Value; set => _current_row.Value = value ?? _selected_rows.FirstOrDefault(); }
|
||||
public OrderBookRowVM current_row {
|
||||
get => _current_row.Value;
|
||||
set {
|
||||
_current_row.Value = value;
|
||||
// this is so that when the current_row is set to null from
|
||||
// the row_vm, we propagate the change up to the OrderBookWindow
|
||||
// so that the cancel and modify commands can_execute is updated.
|
||||
// Note that this is really only for if/when the edit_xxx columns
|
||||
// from the mini-ob are present in regular orderbook, else this is
|
||||
// a no-op.
|
||||
selected_order_changed?.Invoke(current_order);
|
||||
}
|
||||
}
|
||||
public OrderRecordImmutable? current_order => current_row?.order;
|
||||
public IEnumerable<OrderRecordImmutable> selected_orders => _selected_rows.Select(r => r.order);
|
||||
public _GridSettingsManager grid_settings_manager { get; }
|
||||
|
||||
@@ -167,11 +167,9 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
private void _vm_selected_order_changed(OrderRecordImmutable? e) {
|
||||
if (e.HasValue) {
|
||||
_modify_order_command.raiseCanExecuteChanged();
|
||||
_cancel_selected_orders_command.raiseCanExecuteChanged();
|
||||
_recreate_selected_orders_command.raiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ namespace bts.shell {
|
||||
public static GridColumnSettings last_price => new GridColumnSettings(Columns.LastPrice.ToString(), "Last Filled", width: DIYGrid.DefaultColumnWidths.LastPrice, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings status => new GridColumnSettings(Columns.Status.ToString(), "Status", width: 80);
|
||||
public static GridColumnSettings last_message => new GridColumnSettings(Columns.LastMessage.ToString(), "Last Message", width: DIYGrid.DefaultColumnWidths.LastMessage);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(Columns.SecurityKey.ToString(), DIYGrid.DefaultColumnHeaders.SecurityKey, width: DIYGrid.DefaultColumnWidths.SecurityKey);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(Columns.SecurityKey.ToString(), DIYGrid.DefaultColumnHeaders.SecurityKey, is_visible: false, width: DIYGrid.DefaultColumnWidths.SecurityKey);
|
||||
public static GridColumnSettings order_key => new GridColumnSettings(Columns.OrderKey.ToString(), DIYGrid.DefaultColumnHeaders.OrderKey, width: DIYGrid.DefaultColumnWidths.OrderKey);
|
||||
public static GridColumnSettings parent_key => new GridColumnSettings(Columns.ParentKey.ToString(), "Parent Key", width: DIYGrid.DefaultColumnWidths.ParentKey);
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace mbts.ui.spark {
|
||||
public DataTemplate JoinOrderTemplate { get; set; }
|
||||
public DataTemplate TopOrderTemplate { get; set; }
|
||||
public DataTemplate CoverOrderTemplate { get; set; }
|
||||
public DataTemplate OCOOrderTemplate { get; set; }
|
||||
public DataTemplate PricerOrderTemplate { get; set; }
|
||||
public DataTemplate OffsetOrderTemplate { get; set; }
|
||||
public DataTemplate TriggerOrderTemplate { get; set; }
|
||||
public DataTemplate IcebergOrderTemplate { get; set; }
|
||||
@@ -43,6 +45,8 @@ namespace mbts.ui.spark {
|
||||
case CustomOrderDefinition.CustomOneofCase.Join: return JoinOrderTemplate;
|
||||
case CustomOrderDefinition.CustomOneofCase.Top: return TopOrderTemplate;
|
||||
case CustomOrderDefinition.CustomOneofCase.Cover: return CoverOrderTemplate;
|
||||
case CustomOrderDefinition.CustomOneofCase.Oco : return OCOOrderTemplate;
|
||||
case CustomOrderDefinition.CustomOneofCase.Pricer: return PricerOrderTemplate;
|
||||
case CustomOrderDefinition.CustomOneofCase.Offset: return OffsetOrderTemplate;
|
||||
case CustomOrderDefinition.CustomOneofCase.Trigger: return TriggerOrderTemplate;
|
||||
case CustomOrderDefinition.CustomOneofCase.Iceberg: return IcebergOrderTemplate;
|
||||
|
||||
@@ -126,6 +126,8 @@ namespace mbts.spark
|
||||
return _child_order_choices;
|
||||
}
|
||||
}
|
||||
|
||||
public bool has_child => _order_def_tags.Any();
|
||||
|
||||
public IOrderTypeVM child_order
|
||||
{
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using mbts.ui;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using static bts.api.orderman.CustomOrderDefinition;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
static partial class OrderTypeVMFactory
|
||||
{
|
||||
class InlineOCOOrderProperties
|
||||
{
|
||||
public InlineOCOOrderProperties(OrderTemplateHeader selected_child_order_type, IReadOnlyCollection<OrderTemplateHeader> child_order_types)
|
||||
{
|
||||
ExceptionAssert.InvalidOperation.That(child_order_types.Contains(selected_child_order_type), $"Child order type {selected_child_order_type} is not in child_order_types");
|
||||
this.selected_child_order_type = new InlineUserProperty<OrderTemplateHeader>(selected_child_order_type, true);
|
||||
this.child_order_types = new InlineUserProperty<IReadOnlyCollection<OrderTemplateHeader>>(child_order_types, true);
|
||||
|
||||
var othertype = CustomOneofCase.Limit;
|
||||
this.selected_other_order_type = new InlineUserProperty<OrderTemplateHeader>(new OrderTemplateHeader(othertype), true);
|
||||
this.other_order_types = new InlineUserProperty<IReadOnlyCollection<OrderTemplateHeader>>(child_order_types, true);
|
||||
|
||||
other_ticks = new InlineUserProperty<int>(1, false);
|
||||
other_side = new InlineUserProperty<bts.api.RelativeSide>(bts.api.RelativeSide.Same, false);
|
||||
}
|
||||
public readonly InlineUserProperty<OrderTemplateHeader> selected_child_order_type;
|
||||
public readonly InlineUserProperty<IReadOnlyCollection<OrderTemplateHeader>> child_order_types;
|
||||
public readonly InlineUserProperty<OrderTemplateHeader> selected_other_order_type;
|
||||
public readonly InlineUserProperty<IReadOnlyCollection<OrderTemplateHeader>> other_order_types;
|
||||
|
||||
public readonly InlineUserProperty<int> other_ticks;
|
||||
public readonly InlineUserProperty<bts.api.RelativeSide> other_side;
|
||||
|
||||
}
|
||||
|
||||
class OCOOrderVM : OrderTypeVMBase<OCOOrderDefinition>, IHierarchicalOrderTypeVM, IDisposable
|
||||
{
|
||||
readonly IObservable<SecurityMD> _security_md_source;
|
||||
SecurityImmutable? _security;
|
||||
ObservableCollection<OrderTemplateHeader> _order_types = new ObservableCollection<OrderTemplateHeader>();
|
||||
ObservableAutoWrapper<IOrderTypeVM, OrderTemplateHeader> _child_order_choices;
|
||||
InlineOCOOrderProperties _inline_props;
|
||||
IOrderTypeVM _child_order;
|
||||
IDisposable _dispose, _child_order_errors_sub;
|
||||
|
||||
ObservableAutoWrapper<IOrderTypeVM, OrderTemplateHeader> _other_order_choices;
|
||||
IOrderTypeVM _other_order;
|
||||
IDisposable _other_order_errors_sub;
|
||||
|
||||
public int other_ticks { get; set; } = 1;
|
||||
public bts.api.RelativeSide other_side { get; set; } = bts.api.RelativeSide.Same;
|
||||
|
||||
public OCOOrderVM(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name)
|
||||
: this(model, security_md_source, security_md_source.Select(smd =>
|
||||
new InlineOCOOrderProperties(new OrderTemplateHeader(model.factory.default_order_type(smd.security)), model.factory.default_order_types(smd.security).Select(t => new OrderTemplateHeader(t)).ToList())), id, display_name)
|
||||
{ }
|
||||
|
||||
public OCOOrderVM(OrdersModel model, IObservable<SecurityMD> security_md_source,
|
||||
IObservable<InlineOCOOrderProperties> inline_properties, string id, string display_name) : base(model, id, display_name)
|
||||
{
|
||||
_security_md_source = security_md_source;
|
||||
_dispose = Disposable.Create(
|
||||
security_md_source.OnDispatcher()
|
||||
.Subscribe(smd => _security = smd.security),
|
||||
inline_properties.OnDispatcher()
|
||||
.Subscribe(p =>
|
||||
{
|
||||
if (_order_types.Count == 0 || p.child_order_types.force_override)
|
||||
{
|
||||
_order_types.SetItems(p.child_order_types.value);
|
||||
}
|
||||
if (_child_order_choices != null && (_child_order == null || p.selected_child_order_type.force_override))
|
||||
{
|
||||
_select_child_order(p.selected_child_order_type.value.key.type);
|
||||
}
|
||||
if (_other_order_choices != null && (_other_order == null || p.selected_other_order_type.force_override))
|
||||
{
|
||||
_select_other_order(p.selected_other_order_type.value.key.type);
|
||||
}
|
||||
if (p.other_ticks.force_override)
|
||||
{
|
||||
other_ticks = p.other_ticks.value;
|
||||
RaisePropertyChanged(nameof(other_ticks));
|
||||
}
|
||||
if (p.other_side.force_override)
|
||||
{
|
||||
other_side = p.other_side.value;
|
||||
RaisePropertyChanged(nameof(other_side));
|
||||
}
|
||||
_inline_props = p;
|
||||
_validate();
|
||||
})
|
||||
);
|
||||
_validate();
|
||||
}
|
||||
|
||||
public override void assign_to(CustomOrderDefinition value)
|
||||
{
|
||||
if (_child_order == null)
|
||||
_select_child_order(model.factory.default_order_type(_security.Value, true));
|
||||
if (_other_order == null )
|
||||
_select_other_order(model.factory.default_order_type(_security.Value, true));
|
||||
_validate();
|
||||
if (!HasErrors)
|
||||
{
|
||||
var i = factory.oco_order();
|
||||
i.OtherTicks = other_ticks;
|
||||
i.OtherSide = other_side;
|
||||
child_order.assign_to(i.Child);
|
||||
if (other_order != null)
|
||||
other_order.assign_to(i.Other);
|
||||
value.Oco = i;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<bts.api.RelativeSide> other_side_types => EnumHelper.get_values_except<bts.api.RelativeSide>(bts.api.RelativeSide.Undefined);
|
||||
|
||||
public ICollection<IOrderTypeVM> child_order_types
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_child_order_choices == null)
|
||||
_child_order_choices = new ObservableAutoWrapper<IOrderTypeVM, OrderTemplateHeader>(_order_types, ot => create(ot.key.type, ot.key.name, ot.display_name, model, _security_md_source));
|
||||
return _child_order_choices;
|
||||
}
|
||||
}
|
||||
|
||||
public ICollection<IOrderTypeVM> other_order_types
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_other_order_choices == null)
|
||||
_other_order_choices = new ObservableAutoWrapper<IOrderTypeVM, OrderTemplateHeader>(_order_types, ot => create(ot.key.type, ot.key.name, ot.display_name, model, _security_md_source));
|
||||
return _other_order_choices;
|
||||
}
|
||||
}
|
||||
|
||||
public IOrderTypeVM child_order
|
||||
{
|
||||
get
|
||||
{
|
||||
init();
|
||||
return _child_order;
|
||||
}
|
||||
set
|
||||
{
|
||||
Disposable.dispose(ref _child_order_errors_sub);
|
||||
_child_order = value;
|
||||
_child_order?.init();
|
||||
if (_child_order is INotifyDataErrorInfo ndei)
|
||||
{
|
||||
ndei.ErrorsChanged += on_errors_changed;
|
||||
void on_errors_changed(object s, DataErrorsChangedEventArgs e) =>
|
||||
_validate();
|
||||
_child_order_errors_sub = Disposable.Create(() => ndei.ErrorsChanged -= on_errors_changed);
|
||||
}
|
||||
_validate();
|
||||
RaisePropertyChanged(nameof(child_order));
|
||||
}
|
||||
}
|
||||
|
||||
public IOrderTypeVM other_order
|
||||
{
|
||||
get
|
||||
{
|
||||
init();
|
||||
return _other_order;
|
||||
}
|
||||
set
|
||||
{
|
||||
Disposable.dispose(ref _other_order_errors_sub);
|
||||
_other_order = value;
|
||||
_other_order?.init();
|
||||
if (_other_order is INotifyDataErrorInfo ndei)
|
||||
{
|
||||
ndei.ErrorsChanged += on_errors_changed;
|
||||
void on_errors_changed(object s, DataErrorsChangedEventArgs e) =>
|
||||
_validate();
|
||||
_other_order_errors_sub = Disposable.Create(() => ndei.ErrorsChanged -= on_errors_changed);
|
||||
}
|
||||
_validate();
|
||||
RaisePropertyChanged(nameof(other_order));
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Disposable.dispose(ref _dispose);
|
||||
if (_child_order_choices != null)
|
||||
_child_order_choices.OfType<IDisposable>().DisposeAll();
|
||||
if (_other_order_choices != null)
|
||||
_other_order_choices.OfType<IDisposable>().DisposeAll();
|
||||
}
|
||||
|
||||
public override void init()
|
||||
{
|
||||
if (_child_order == null && _security.HasValue)
|
||||
_select_child_order();
|
||||
if (_other_order == null && _security.HasValue)
|
||||
_select_other_order();
|
||||
_validate();
|
||||
}
|
||||
|
||||
void _select_child_order()
|
||||
{
|
||||
CustomOneofCase ot = _inline_props != null && _inline_props.selected_child_order_type.has_value ?
|
||||
_inline_props.selected_child_order_type.value.key.type :
|
||||
model.factory.default_order_type(_security.Value, true);
|
||||
_select_child_order(ot);
|
||||
}
|
||||
|
||||
void _select_child_order(CustomOneofCase ot)
|
||||
{
|
||||
_child_order = child_order_types.FirstOrDefault(vm => vm.order_type == ot);
|
||||
if (_child_order == null)
|
||||
_child_order = child_order_types.FirstOrDefault();
|
||||
RaisePropertyChanged(nameof(child_order));
|
||||
}
|
||||
|
||||
void _select_other_order()
|
||||
{
|
||||
CustomOneofCase ot = _inline_props != null && _inline_props.selected_other_order_type.has_value ?
|
||||
_inline_props.selected_other_order_type.value.key.type :
|
||||
model.factory.default_order_type(_security.Value, true);
|
||||
_select_other_order(ot);
|
||||
}
|
||||
|
||||
void _select_other_order(CustomOneofCase ot)
|
||||
{
|
||||
_other_order = other_order_types.FirstOrDefault(vm => vm.order_type == ot);
|
||||
if (_other_order == null)
|
||||
_other_order = other_order_types.FirstOrDefault();
|
||||
RaisePropertyChanged(nameof(other_order));
|
||||
}
|
||||
|
||||
|
||||
void _validate()
|
||||
{
|
||||
if (_child_order == null || (_child_order is INotifyDataErrorInfo ndei && ndei.HasErrors))
|
||||
set_error(nameof(child_order), string.Empty, true);
|
||||
else clear_error(nameof(child_order));
|
||||
|
||||
if ((_other_order == null ) || (_other_order is INotifyDataErrorInfo hdei && hdei.HasErrors))
|
||||
set_error(nameof(other_order), string.Empty, true);
|
||||
else clear_error(nameof(other_order));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,12 @@ namespace mbts.spark {
|
||||
public static IOrderTypeVM stop(OrdersModel model, string id, string display_name) => new StopOrderVM(model, id, display_name);
|
||||
public static IOrderTypeVM stop_limit(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name) => new StopLimitOrderVM(model, security_md_source, id, display_name);
|
||||
public static IOrderTypeVM time_box(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name) => new TimeBoxOrderVM(model, security_md_source, id, display_name);
|
||||
public static IOrderTypeVM tick(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name) => new TickOrderVM(model, security_md_source, id, display_name);
|
||||
public static IOrderTypeVM lean(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name) => new LeanOrderVM(model, security_md_source, id, display_name);
|
||||
public static IOrderTypeVM join(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name) => new JoinOrderVM(model, security_md_source, id, display_name);
|
||||
public static IOrderTypeVM top(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name) => new TopOrderVM(model, security_md_source, id, display_name);
|
||||
public static IOrderTypeVM cover(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name) => new CoverOrderVM(model, security_md_source, id, display_name);
|
||||
public static IOrderTypeVM oco(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name) => new OCOOrderVM(model, security_md_source, id, display_name);
|
||||
public static IOrderTypeVM pricer(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name) => new PricerOrderVM(model, security_md_source, id, display_name);
|
||||
public static IOrderTypeVM offset(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name) => new OffsetOrderVM(model, security_md_source, id, display_name);
|
||||
public static IOrderTypeVM trigger(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name) => new TriggerOrderVM(model, security_md_source, id, display_name);
|
||||
public static IOrderTypeVM iceberg(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name) => new IcebergOrderVM(model, security_md_source, id, display_name);
|
||||
@@ -34,11 +35,12 @@ namespace mbts.spark {
|
||||
case CustomOneofCase.Stop: return stop(model, id, display_name);
|
||||
case CustomOneofCase.StopLimit: return stop_limit(model, security_md_source, id, display_name);
|
||||
case CustomOneofCase.TimeBox: return time_box(model, security_md_source, id, display_name);
|
||||
case CustomOneofCase.Tick: return tick(model, security_md_source, id, display_name);
|
||||
case CustomOneofCase.Lean: return lean(model, security_md_source, id, display_name);
|
||||
case CustomOneofCase.Join: return join(model, security_md_source, id, display_name);
|
||||
case CustomOneofCase.Top: return top(model, security_md_source, id, display_name);
|
||||
case CustomOneofCase.Cover: return cover(model, security_md_source, id, display_name);
|
||||
case CustomOneofCase.Oco : return oco(model, security_md_source, id, display_name);
|
||||
case CustomOneofCase.Pricer: return pricer(model, security_md_source, id, display_name);
|
||||
case CustomOneofCase.Offset: return offset(model, security_md_source, id, display_name);
|
||||
case CustomOneofCase.Trigger: return trigger(model, security_md_source, id, display_name);
|
||||
case CustomOneofCase.Iceberg: return iceberg(model, security_md_source, id, display_name);
|
||||
|
||||
+25
-53
@@ -15,52 +15,42 @@ namespace mbts.spark
|
||||
{
|
||||
static partial class OrderTypeVMFactory
|
||||
{
|
||||
class InlineTickOrderProperties
|
||||
class InlinePricerOrderProperties
|
||||
{
|
||||
public InlineTickOrderProperties (OrderTemplateHeader selected_child_order_type, IReadOnlyCollection<OrderTemplateHeader> child_order_types)
|
||||
public InlinePricerOrderProperties (OrderTemplateHeader selected_child_order_type, IReadOnlyCollection<OrderTemplateHeader> child_order_types)
|
||||
{
|
||||
ExceptionAssert.InvalidOperation.That(child_order_types.Contains(selected_child_order_type), $"Child order type {selected_child_order_type} is not in child_order_types");
|
||||
this.selected_child_order_type = new InlineUserProperty<OrderTemplateHeader>(selected_child_order_type, true);
|
||||
this.child_order_types = new InlineUserProperty<IReadOnlyCollection<OrderTemplateHeader>>(child_order_types, true);
|
||||
tick_offset_on_deploy = new InlineUserProperty<uint>(0, false);
|
||||
cross_threshold = new InlineUserProperty<bts.spark.QuantityMeasure>(
|
||||
new bts.spark.QuantityMeasure() { Ratio = 1.0, Absolute = 1}, false);
|
||||
cross_ticks = new InlineUserProperty<uint>(0, false);
|
||||
max_chase_ticks = new InlineUserProperty<uint>(10, false);
|
||||
detach_on_toward = new InlineUserProperty<bool>(true, false);
|
||||
price_offset_ticks = new InlineUserProperty<int>(0, false);
|
||||
price_factor = new InlineUserProperty<double>(0, false);
|
||||
}
|
||||
public readonly InlineUserProperty<OrderTemplateHeader> selected_child_order_type;
|
||||
public readonly InlineUserProperty<IReadOnlyCollection<OrderTemplateHeader>> child_order_types;
|
||||
|
||||
public readonly InlineUserProperty<uint> tick_offset_on_deploy;
|
||||
public readonly InlineUserProperty<bts.spark.QuantityMeasure> cross_threshold;
|
||||
public readonly InlineUserProperty<uint> cross_ticks;
|
||||
public readonly InlineUserProperty<uint> max_chase_ticks;
|
||||
public readonly InlineUserProperty<bool> detach_on_toward;
|
||||
public readonly InlineUserProperty<int> price_offset_ticks;
|
||||
public readonly InlineUserProperty<double> price_factor;
|
||||
}
|
||||
|
||||
class TickOrderVM : OrderTypeVMBase<TickOrderDefinition>, IHierarchicalOrderTypeVM, IDisposable
|
||||
class PricerOrderVM : OrderTypeVMBase<PricerOrderDefinition>, IHierarchicalOrderTypeVM, IDisposable
|
||||
{
|
||||
readonly IObservable<SecurityMD> _security_md_source;
|
||||
SecurityImmutable? _security;
|
||||
ObservableCollection<OrderTemplateHeader> _order_types = new ObservableCollection<OrderTemplateHeader>();
|
||||
ObservableAutoWrapper<IOrderTypeVM, OrderTemplateHeader> _child_order_choices;
|
||||
InlineTickOrderProperties _inline_props;
|
||||
InlinePricerOrderProperties _inline_props;
|
||||
IOrderTypeVM _child_order;
|
||||
IDisposable _dispose, _child_order_errors_sub;
|
||||
|
||||
public uint tick_offset_on_deploy { get; set; } = 0;
|
||||
public bts.spark.QuantityMeasure cross_threshold { get; set; } = new bts.spark.QuantityMeasure() { Ratio = 1.0, Absolute = 1 };
|
||||
public uint cross_ticks { get; set; } = 0;
|
||||
public uint max_chase_ticks { get; set; } = 10;
|
||||
public bool detach_on_toward { get; set; } = true;
|
||||
public int price_offset_ticks { get; set; } = 0;
|
||||
public double price_factor { get; set; } = 1.0;
|
||||
|
||||
public TickOrderVM(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name)
|
||||
public PricerOrderVM(OrdersModel model, IObservable<SecurityMD> security_md_source, string id, string display_name)
|
||||
: this(model, security_md_source, security_md_source.Select(smd =>
|
||||
new InlineTickOrderProperties(new OrderTemplateHeader(model.factory.default_order_type(smd.security)), model.factory.default_order_types(smd.security).Select(t => new OrderTemplateHeader(t)).ToList())), id, display_name) { }
|
||||
new InlinePricerOrderProperties(new OrderTemplateHeader(model.factory.default_order_type(smd.security)), model.factory.default_order_types(smd.security).Select(t => new OrderTemplateHeader(t)).ToList())), id, display_name) { }
|
||||
|
||||
public TickOrderVM(OrdersModel model, IObservable<SecurityMD> security_md_source,
|
||||
IObservable<InlineTickOrderProperties> inline_properties, string id, string display_name) : base(model, id, display_name)
|
||||
public PricerOrderVM(OrdersModel model, IObservable<SecurityMD> security_md_source,
|
||||
IObservable<InlinePricerOrderProperties> inline_properties, string id, string display_name) : base(model, id, display_name)
|
||||
{
|
||||
_security_md_source = security_md_source;
|
||||
_dispose = Disposable.Create(
|
||||
@@ -76,31 +66,16 @@ namespace mbts.spark
|
||||
{
|
||||
_select_child_order(p.selected_child_order_type.value.key.type);
|
||||
}
|
||||
if (p.tick_offset_on_deploy.force_override)
|
||||
if (p.price_offset_ticks.force_override)
|
||||
{
|
||||
tick_offset_on_deploy = p.tick_offset_on_deploy.value;
|
||||
RaisePropertyChanged(nameof(tick_offset_on_deploy));
|
||||
price_offset_ticks = p.price_offset_ticks.value;
|
||||
RaisePropertyChanged(nameof(price_offset_ticks));
|
||||
}
|
||||
if (p.cross_threshold.force_override)
|
||||
if (p.price_factor.force_override)
|
||||
{
|
||||
cross_threshold = p.cross_threshold.value;
|
||||
RaisePropertyChanged(nameof(cross_threshold));
|
||||
}
|
||||
if (p.cross_ticks.force_override)
|
||||
{
|
||||
cross_ticks = p.cross_ticks.value;
|
||||
RaisePropertyChanged(nameof(cross_ticks));
|
||||
}
|
||||
if (p.max_chase_ticks.force_override)
|
||||
{
|
||||
max_chase_ticks = p.max_chase_ticks.value;
|
||||
RaisePropertyChanged(nameof(max_chase_ticks));
|
||||
}
|
||||
if (p.detach_on_toward.force_override)
|
||||
{
|
||||
detach_on_toward = p.detach_on_toward.value;
|
||||
RaisePropertyChanged(nameof(detach_on_toward));
|
||||
}
|
||||
price_factor = p.price_factor.value;
|
||||
RaisePropertyChanged(nameof(price_factor));
|
||||
}
|
||||
_inline_props = p;
|
||||
_validate();
|
||||
})
|
||||
@@ -115,14 +90,11 @@ namespace mbts.spark
|
||||
_validate();
|
||||
if (!HasErrors)
|
||||
{
|
||||
var i = factory.tick_order();
|
||||
i.TickOffsetOnDeploy = tick_offset_on_deploy;
|
||||
i.CrossThreshold = cross_threshold;
|
||||
i.CrossTicks = cross_ticks;
|
||||
i.MaxChaseTicks = max_chase_ticks;
|
||||
i.DetachOnToward = detach_on_toward;
|
||||
var i = factory.pricer_order();
|
||||
i.PriceOffsetTicks = price_offset_ticks;
|
||||
i.PriceFactor = price_factor;
|
||||
child_order.assign_to(i.Child);
|
||||
value.Tick = i;
|
||||
value.Pricer = i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,6 +211,8 @@ namespace mbts.ui {
|
||||
public static BTSColor lean_order { get { return new BTSColor(255, 170, 210); } }
|
||||
public static BTSColor join_order { get { return new BTSColor(200, 171, 232); } }
|
||||
public static BTSColor cover_order { get { return new BTSColor(134, 232, 224); } }
|
||||
public static BTSColor oco_order { get { return new BTSColor(110, 94, 11); } }
|
||||
public static BTSColor pricer_order { get { return new BTSColor(170, 132, 150); } }
|
||||
public static BTSColor trigger_order { get { return new BTSColor(172, 255, 179); } }
|
||||
public static BTSColor off_order { get { return new BTSColor(0x8a, 0x00, 0x5f); } }//8a005f
|
||||
public static BTSColor top_order { get { return new BTSColor(0xdd, 0x7a, 0x27); } }//dd7a27
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace bts.proto {
|
||||
static class DateTimeProviderExtensions {
|
||||
public static DateTime get_date_time(this DateTimeProvider dtp) {
|
||||
switch (dtp.mode) {
|
||||
case DateTimeProviderMode.CMEOpen: return MarketSchedule.get_cme_gen_open();
|
||||
case DateTimeProviderMode.CMEOpen: return MarketSchedule.get_start_of_trading_day();
|
||||
case DateTimeProviderMode.Today: return DateTime.Today;
|
||||
case DateTimeProviderMode.Explicit:
|
||||
default: return dtp.explicit_date.GetValueOrDefault();
|
||||
|
||||
@@ -36,7 +36,6 @@ namespace mbts.ui.controls {
|
||||
Symbol = 78,
|
||||
Time = 112,
|
||||
TimeInForce = 47,
|
||||
TradeKey = 76,
|
||||
User = 53,
|
||||
Aggressor = 80,
|
||||
Volume = 74,
|
||||
@@ -71,7 +70,6 @@ namespace mbts.ui.controls {
|
||||
ImpliedSize = "Qty (I)",
|
||||
Symbol = "Symbol",
|
||||
TimeInForce = "TIF",
|
||||
TradeKey = "Trade Key",
|
||||
User = "User",
|
||||
Time = "Time",
|
||||
Aggressor = "Aggressor",
|
||||
|
||||
+4
-2
@@ -6,11 +6,12 @@ using System.Windows.Data;
|
||||
namespace mbts.ui.controls {
|
||||
partial class DIYGrid {
|
||||
internal class OrderTypeColumn<TColKey> : FrameworkElementColumnBase<TColKey>, IFilterableColumn {
|
||||
readonly BindingBase _order_type_binding, _metadata_binding;
|
||||
readonly BindingBase _order_type_binding, _metadata_binding, _display_name_binding;
|
||||
|
||||
public OrderTypeColumn(TColKey key, BindingBase order_type_binding, BindingBase metadata_binding, IDataGridColumnFilter filter) : base(key) {
|
||||
public OrderTypeColumn(TColKey key, BindingBase order_type_binding, BindingBase metadata_binding, BindingBase display_name_binding, IDataGridColumnFilter filter) : base(key) {
|
||||
_order_type_binding = order_type_binding;
|
||||
_metadata_binding = metadata_binding;
|
||||
_display_name_binding = display_name_binding;
|
||||
this.filter = filter;
|
||||
Header = DefaultColumnHeaders.OrderType;
|
||||
Width = DefaultColumnWidths.OrderType;
|
||||
@@ -28,6 +29,7 @@ namespace mbts.ui.controls {
|
||||
};
|
||||
v.SetBinding(OrderTypeItem.OrderTypeProperty, _order_type_binding);
|
||||
v.SetBinding(OrderTypeItem.MetadataProperty, _metadata_binding);
|
||||
v.SetBinding(OrderTypeItem.DisplayNameProperty, _display_name_binding);
|
||||
if (font_weight_binding != null) {
|
||||
v.SetBinding(FontWeightProperty, font_weight_binding);
|
||||
} else {
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace mbts.spark.filters {
|
||||
TimeFilterMode _mode;
|
||||
TimeTextTuple _begin, _end;
|
||||
DateTime? _begin_dt, _end_dt;
|
||||
readonly DateTime _cme_open = MarketSchedule.get_cme_gen_open();
|
||||
readonly DateTime _cme_open = MarketSchedule.get_start_of_trading_day();
|
||||
|
||||
public TimeFilterVM(Func<TRow, DateTime> get_row_val, string prop_name) : base(get_row_val, prop_name) =>
|
||||
_set_default_values();
|
||||
|
||||
@@ -166,51 +166,6 @@
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.TimeBoxOrderTemplate>
|
||||
<usp:OrderModificationTemplateSelector.TickOrderTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="12"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="1" VerticalAlignment="Center">Cross Thresh</TextBlock>
|
||||
<uag:QuantityMeasureControl Grid.Row="1" Grid.Column="2" QuantityMeasure="{Binding cross_threshold}"/>
|
||||
|
||||
<TextBlock Grid.Row="3" VerticalAlignment="Center">Cross Ticks</TextBlock>
|
||||
<c:TickUpDownUInt Grid.Row="3" Grid.Column="2" Value="{Binding cross_ticks}"/>
|
||||
<TextBlock Grid.Row="5" VerticalAlignment="Center">Max Chase Ticks</TextBlock>
|
||||
<c:TickUpDownUInt Grid.Row="5" Grid.Column="2" Value="{Binding max_chase_ticks}"/>
|
||||
<CheckBox Grid.Row="7" Grid.Column="2" VerticalAlignment="Center" Margin="0,0,0,0" IsChecked="{Binding detach_on_toward}">Detach on Toward</CheckBox>
|
||||
<TextBlock Grid.Row="9" VerticalAlignment="Center">Initial Tick Offset</TextBlock>
|
||||
<c:TickUpDownUInt Grid.Row="9" Grid.Column="2" Value="{Binding tick_offset_on_deploy}"/>
|
||||
<TextBlock Grid.Row="11">Child</TextBlock>
|
||||
<uag:OrderDetailsPopupControl
|
||||
Grid.Row="11" Grid.Column="2"
|
||||
IsOpen="{Binding child_order.editable_properties_open, FallbackValue=False}"
|
||||
ItemsSource="{Binding child_order_types}"
|
||||
SelectedItem="{Binding child_order}"
|
||||
HasEditableProperties="{Binding child_order.has_editable_properties, FallbackValue=False}"
|
||||
/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.TickOrderTemplate>
|
||||
<usp:OrderModificationTemplateSelector.LeanOrderTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
@@ -379,16 +334,16 @@
|
||||
Orientation="Horizontal"
|
||||
Grid.Row="1"
|
||||
>
|
||||
<TextBlock VerticalAlignment="Center" >Hedge Ticks</TextBlock>
|
||||
<c:HelpButton Margin="4,0,0,0" ToolTip="This is the number of ticks to offset the hedge." />
|
||||
<TextBlock VerticalAlignment="Center" >Profit Ticks</TextBlock>
|
||||
<c:HelpButton Margin="4,0,0,0" ToolTip="This is the number of ticks in your favor to offset the profit/hedge order." />
|
||||
</StackPanel>
|
||||
<c:TickUpDownInt Grid.Row="1" Grid.Column="2" Value="{Binding hedge_ticks}"/>
|
||||
<StackPanel
|
||||
Orientation="Horizontal"
|
||||
Grid.Row="3"
|
||||
>
|
||||
<TextBlock VerticalAlignment="Center">Hedge</TextBlock>
|
||||
<c:HelpButton Margin="4,0,0,0" ToolTip="This is the type of the hedge order to send for each fill of Child Order." />
|
||||
<TextBlock VerticalAlignment="Center">Profit Order</TextBlock>
|
||||
<c:HelpButton Margin="4,0,0,0" ToolTip="This is the type of the profit/hedge order to send for each fill of Child Order." />
|
||||
</StackPanel>
|
||||
<uag:OrderDetailsPopupControl
|
||||
Grid.Row="3" Grid.Column="2"
|
||||
@@ -415,6 +370,68 @@
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.CoverOrderTemplate>
|
||||
<usp:OrderModificationTemplateSelector.OCOOrderTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="12"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="1" >
|
||||
<TextBlock VerticalAlignment="Center" >Stop Ticks</TextBlock>
|
||||
<c:HelpButton Margin="4,0,0,0" ToolTip="This is the number of ticks away from the main order to start the 'stop' order." />
|
||||
</StackPanel>
|
||||
<c:TickUpDownInt Grid.Row="1" Grid.Column="2" Value="{Binding other_ticks}"/>
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="3" >
|
||||
<TextBlock VerticalAlignment="Center" >Stop Side</TextBlock>
|
||||
<c:HelpButton Margin="4,0,0,0" ToolTip="The Side of the 'stop' order" />
|
||||
</StackPanel>
|
||||
<ComboBox Grid.Row="3" Grid.Column="2" ItemsSource="{Binding other_side_types}" ItemTemplate="{StaticResource EnumDescriptionTemplate}" SelectedItem="{Binding other_side}"/>
|
||||
<StackPanel
|
||||
Orientation="Horizontal"
|
||||
Grid.Row="5"
|
||||
>
|
||||
<TextBlock VerticalAlignment="Center">Stop Order</TextBlock>
|
||||
<c:HelpButton Margin="4,0,0,0" ToolTip="This is the type of the 'stop' order to send." />
|
||||
</StackPanel>
|
||||
<uag:OrderDetailsPopupControl
|
||||
Grid.Row="5" Grid.Column="2"
|
||||
IsOpen="{Binding other_order.editable_properties_open, FallbackValue=False}"
|
||||
ItemsSource="{Binding other_order_types}"
|
||||
SelectedItem="{Binding other_order}"
|
||||
HasEditableProperties="{Binding other_order.has_editable_properties, FallbackValue=False}"
|
||||
/>
|
||||
<StackPanel
|
||||
Orientation="Horizontal"
|
||||
Grid.Row="7"
|
||||
>
|
||||
<TextBlock VerticalAlignment="Center">Child</TextBlock>
|
||||
<c:HelpButton Margin="4,0,0,0" ToolTip="This is the type of order to be placed when the algo is triggered." />
|
||||
</StackPanel>
|
||||
|
||||
<uag:OrderDetailsPopupControl
|
||||
Grid.Row="7" Grid.Column="2"
|
||||
IsOpen="{Binding child_order.editable_properties_open, FallbackValue=False}"
|
||||
ItemsSource="{Binding child_order_types}"
|
||||
SelectedItem="{Binding child_order}"
|
||||
HasEditableProperties="{Binding child_order.has_editable_properties, FallbackValue=False}"
|
||||
/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.OCOOrderTemplate>
|
||||
<usp:OrderModificationTemplateSelector.OffsetOrderTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
@@ -773,9 +790,11 @@
|
||||
</usp:DynamicOrderParamTemplateSelector>
|
||||
</ItemsControl.ItemTemplateSelector>
|
||||
</ItemsControl>
|
||||
<TextBlock Grid.Row="3">Child</TextBlock>
|
||||
<TextBlock Grid.Row="3"
|
||||
Visibility="{Binding has_child, Converter={StaticResource BooleanToVisibilityConverter}}" >Child</TextBlock>
|
||||
<uag:OrderDetailsPopupControl
|
||||
Grid.Row="3" Grid.Column="2"
|
||||
Grid.Row="3" Grid.Column="2"
|
||||
Visibility="{Binding has_child, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
IsOpen="{Binding child_order.editable_properties_open, FallbackValue=False}"
|
||||
ItemsSource="{Binding child_order_types}"
|
||||
SelectedItem="{Binding child_order}"
|
||||
|
||||
@@ -69,6 +69,9 @@ namespace mbts.spark {
|
||||
public static CustomOrderDefinition.CustomOneofCase order_type(this OrderRecordImmutable order) =>
|
||||
order.HasDef && order.Def.HasCustomDef ? order.Def.CustomDef.CustomCase : CustomOrderDefinition.CustomOneofCase.None;
|
||||
|
||||
public static string dynamic_order_type_display_name(this OrderRecordImmutable order) =>
|
||||
order.HasDef && order.Def.HasCustomDef && order.Def.CustomDef.HasDynamic ? order.Def.CustomDef.Dynamic.DynamicOrderType : string.Empty;
|
||||
|
||||
public static OrderSubType sub_type(this OrderRecordImmutable order) =>
|
||||
order.HasDef ? order.Def.SubType : OrderSubType.None;
|
||||
|
||||
|
||||
@@ -28,31 +28,10 @@ namespace mbts.spark {
|
||||
static readonly int sod_hh = (int)config.Configuration.get<bts.config.SODTime>().sod_hh;
|
||||
static readonly int sod_mm = (int)config.Configuration.get<bts.config.SODTime>().sod_mm;
|
||||
static readonly TimeZoneInfo central_tzi = TimeZoneInfo.FindSystemTimeZoneById(cst_id);
|
||||
static readonly DateTime _start_of_trading_day_utc;
|
||||
static readonly DateTime _adjusted_central_sod;
|
||||
|
||||
|
||||
static readonly DateTime unadjusted_central_sod = TimeZoneInfo.ConvertTimeFromUtc(
|
||||
DateTime.UtcNow.Date.Add(new TimeSpan(sod_hh, sod_mm, 0)),
|
||||
central_tzi
|
||||
);
|
||||
|
||||
static MarketSchedule() {
|
||||
var cme_schedule = config.Configuration.get<bts.md.CMETradingSchedule>();
|
||||
_cme_gen_open_hrs = cme_schedule?.gen_open_hour ?? 8.5;
|
||||
|
||||
_adjusted_central_sod = !central_tzi.IsDaylightSavingTime(unadjusted_central_sod) ? unadjusted_central_sod.AddHours(1) : unadjusted_central_sod;
|
||||
|
||||
// Note that this isn't the acutal start of the trading day
|
||||
// but it's close enough for pnl purposes.
|
||||
// In reality, instruments have different schedules
|
||||
|
||||
// if now is less than the current sod, then we me move the sod back a day to account for the trading day start
|
||||
if (_adjusted_central_sod >= TimeZoneInfo.ConvertTime(DateTime.Now, central_tzi)) {
|
||||
_adjusted_central_sod = _adjusted_central_sod.AddDays(-1);
|
||||
}
|
||||
var local_time_zone_sod = TimeZoneInfo.ConvertTime(_adjusted_central_sod, central_tzi, TimeZoneInfo.Local);
|
||||
_start_of_trading_day_utc = local_time_zone_sod.ToUniversalTime();
|
||||
}
|
||||
// for object initializers
|
||||
public MarketSchedule() { }
|
||||
@@ -73,6 +52,27 @@ namespace mbts.spark {
|
||||
return last_open;
|
||||
}
|
||||
|
||||
// DateTime? used here b/c we can't set a default parameter with DateTime.Now
|
||||
// since it's not a compile-time constant
|
||||
public static DateTime get_start_of_trading_day(DateTime? target_datetime = null, DateTimeKind dtk = DateTimeKind.Local ) {
|
||||
if (target_datetime == null) target_datetime = DateTime.Now;
|
||||
var dst_adjusted_central_sod = new DateTimeOffset(
|
||||
new DateTime(target_datetime.Value.Date.Add(new TimeSpan(sod_hh, sod_mm, 0)).Ticks, DateTimeKind.Unspecified),
|
||||
central_tzi.BaseUtcOffset
|
||||
);
|
||||
|
||||
// if we're not currently past the start of the trading day, then the start must be yesterday
|
||||
var temp = dst_adjusted_central_sod;
|
||||
if (temp >= TimeZoneInfo.ConvertTime(target_datetime.Value, central_tzi)) {
|
||||
temp = dst_adjusted_central_sod.AddDays(-1);
|
||||
}
|
||||
var local_time_zone_sod = TimeZoneInfo.ConvertTime(temp.DateTime, central_tzi, TimeZoneInfo.Local);
|
||||
if (dtk == DateTimeKind.Utc) {
|
||||
return local_time_zone_sod.ToUniversalTime();
|
||||
}
|
||||
return local_time_zone_sod;
|
||||
}
|
||||
|
||||
public static DateTime get_utctimestamp_as_localtime(string s) {
|
||||
return DateTimeOffset.ParseExact(s, "yyyyMMddHHmmssffffff", null, System.Globalization.DateTimeStyles.AssumeUniversal).ToLocalTime().LocalDateTime;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace mbts.spark.utilities {
|
||||
static readonly OrderMetadata _default_order_metadata = new OrderMetadata { KeyBinding = "", Color = BTSColors.Orders.spreader_order };
|
||||
static readonly CustomOrderDefinition.CustomOneofCase[]
|
||||
// The following standard types are not yet ready for production use:
|
||||
// CustomOrderDefinition.CustomOneofCase.Tick,
|
||||
// CustomOrderDefinition.CustomOneofCase.Dynamic,
|
||||
_standard_types = new[] {
|
||||
CustomOrderDefinition.CustomOneofCase.Market,
|
||||
@@ -37,6 +36,7 @@ namespace mbts.spark.utilities {
|
||||
CustomOrderDefinition.CustomOneofCase.Lean,
|
||||
CustomOrderDefinition.CustomOneofCase.Join,
|
||||
CustomOrderDefinition.CustomOneofCase.Cover,
|
||||
CustomOrderDefinition.CustomOneofCase.Oco,
|
||||
CustomOrderDefinition.CustomOneofCase.Offset,
|
||||
CustomOrderDefinition.CustomOneofCase.Top,
|
||||
CustomOrderDefinition.CustomOneofCase.Trigger,
|
||||
@@ -228,6 +228,15 @@ namespace mbts.spark.utilities {
|
||||
Child = custom_order(),
|
||||
Hedge = custom_order(),
|
||||
};
|
||||
public OCOOrderDefinition oco_order() => new OCOOrderDefinition
|
||||
{
|
||||
Child = custom_order(),
|
||||
Other = custom_order(),
|
||||
};
|
||||
public PricerOrderDefinition pricer_order() => new PricerOrderDefinition
|
||||
{
|
||||
Child = custom_order(),
|
||||
};
|
||||
public OffsetOrderDefinition offset_order() => new OffsetOrderDefinition
|
||||
{
|
||||
Child = custom_order(),
|
||||
@@ -262,6 +271,8 @@ namespace mbts.spark.utilities {
|
||||
case CustomOrderDefinition.CustomOneofCase.Join: rv.Join = join_order(); break;
|
||||
case CustomOrderDefinition.CustomOneofCase.Top: rv.Top = top_order(); break;
|
||||
case CustomOrderDefinition.CustomOneofCase.Cover: rv.Cover = cover_order(); break;
|
||||
case CustomOrderDefinition.CustomOneofCase.Oco: rv.Oco = oco_order(); break;
|
||||
case CustomOrderDefinition.CustomOneofCase.Pricer: rv.Pricer = pricer_order(); break;
|
||||
case CustomOrderDefinition.CustomOneofCase.Offset: rv.Offset = offset_order(); break;
|
||||
case CustomOrderDefinition.CustomOneofCase.Trigger: rv.Trigger = trigger_order(); break;
|
||||
case CustomOrderDefinition.CustomOneofCase.Spreader: rv.Spreader = spreader_order(); break;
|
||||
@@ -285,6 +296,8 @@ namespace mbts.spark.utilities {
|
||||
case CustomOrderDefinition.CustomOneofCase.Join: return new OrderMetadata { KeyBinding = "J", Color = BTSColors.Orders.join_order };
|
||||
case CustomOrderDefinition.CustomOneofCase.Top: return new OrderMetadata { KeyBinding = "D", Color = BTSColors.Orders.top_order };
|
||||
case CustomOrderDefinition.CustomOneofCase.Cover: return new OrderMetadata { KeyBinding = "C", Color = BTSColors.Orders.cover_order };
|
||||
case CustomOrderDefinition.CustomOneofCase.Oco: return new OrderMetadata { KeyBinding = "C", Color = BTSColors.Orders.oco_order };
|
||||
case CustomOrderDefinition.CustomOneofCase.Pricer: return new OrderMetadata { KeyBinding = "C", Color = BTSColors.Orders.pricer_order };
|
||||
case CustomOrderDefinition.CustomOneofCase.Offset: return new OrderMetadata { KeyBinding = "O", Color = BTSColors.Orders.tick_order };
|
||||
case CustomOrderDefinition.CustomOneofCase.Trigger: return new OrderMetadata { KeyBinding = "T", Color = BTSColors.Orders.trigger_order };
|
||||
case CustomOrderDefinition.CustomOneofCase.Spreader: goto default;
|
||||
@@ -306,6 +319,8 @@ namespace mbts.spark.utilities {
|
||||
case OrderState.CustomOneofCase.Join: return new OrderMetadata { KeyBinding = "J", Color = BTSColors.Orders.join_order };
|
||||
case OrderState.CustomOneofCase.Top: return new OrderMetadata { KeyBinding = "D", Color = BTSColors.Orders.top_order };
|
||||
case OrderState.CustomOneofCase.Cover: return new OrderMetadata { KeyBinding = "C", Color = BTSColors.Orders.cover_order };
|
||||
case OrderState.CustomOneofCase.Oco: return new OrderMetadata { KeyBinding = "C", Color = BTSColors.Orders.oco_order };
|
||||
case OrderState.CustomOneofCase.Pricer: return new OrderMetadata { KeyBinding = "C", Color = BTSColors.Orders.pricer_order };
|
||||
case OrderState.CustomOneofCase.Offset: return new OrderMetadata { KeyBinding = "O", Color = BTSColors.Orders.tick_order };
|
||||
case OrderState.CustomOneofCase.Trigger: return new OrderMetadata { KeyBinding = "T", Color = BTSColors.Orders.trigger_order };
|
||||
case OrderState.CustomOneofCase.Spreader: goto default;
|
||||
@@ -345,6 +360,8 @@ namespace mbts.spark.utilities {
|
||||
case nameof(JoinOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Join;
|
||||
case nameof(TopOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Top;
|
||||
case nameof(CoverOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Cover;
|
||||
case nameof(OCOOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Oco;
|
||||
case nameof(PricerOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Pricer;
|
||||
case nameof(OffsetOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Offset;
|
||||
case nameof(TriggerOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Trigger;
|
||||
case nameof(DynamicOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Dynamic;
|
||||
|
||||
@@ -1,8 +1,31 @@
|
||||
# BTS Spark
|
||||
|
||||
|
||||
Our offering consists of a client UI [Spark Client](https://www.bluetradingsystems.com/images/Images/spark/02.06.19/Ladder.png), a high performance professional futures front end, connected via our proprietary protocol over TCP to our Spark Server, which in turn connects to execution venues via their native protocols (typically FIX/TCP for execution and some proprietary protocol over UDP multicast for market data).
|
||||
|
||||

|
||||
|
||||
|
||||
# BTS Spark Client SDK
|
||||
|
||||
#### Getting Started
|
||||
We currently offer two API extension points. This repository, our BTS **Spark Client SDK** allows users to control our Spark Server externally, that is, out of process, using the exact same protocol our own Spark Client does. In other words, a client application developed via the Spark Client SDK, say a VB .NET UI, would be able to provide any functionality our own UI provides.
|
||||
|
||||
## Git
|
||||
We currently offer bindings for the Spark protocol to C++, C# and Excel clients. Since the underlying transport is TCP, clients developed via the Spark Client SDK can be located anywhere in the world, as long as they can reach the Spark Server via TCP. We do require a VPN or a secure network, since the Spark Protocol is currently not yet encrypted.
|
||||
|
||||
Our second API extension point is intended for users that require adding functionality to our Spark Server. If you are interested in extending the server process through custom order types, market data sources, or execution gateways, please see the [Spark Server SDK](https://github.com/BlueTradingSystems/spark_sdk).
|
||||
|
||||
|
||||
### In Depth
|
||||
|
||||
* [Interface Overview](doc/Overview.md)
|
||||
* [Threading Notes](doc/Threading.md)
|
||||
|
||||
|
||||
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Git
|
||||
|
||||
* First clone the spark_client_sdk repo
|
||||
|
||||
@@ -11,7 +34,7 @@
|
||||
```
|
||||
|
||||
|
||||
## Build
|
||||
### Build
|
||||
* Use msbuild to target windows / .net 4.71
|
||||
* Install studio here if you don't have it: https://visualstudio.microsoft.com/downloads/
|
||||
* Use VSCode for editing, it's better: https://code.visualstudio.com/
|
||||
@@ -24,7 +47,7 @@ spark_client_sdk\src\spark_sdk> msbuild
|
||||
|
||||
* spark_sdk binaries will be produced in the bin\Debug directory
|
||||
|
||||
## Connecting to Spark Server
|
||||
### Connecting to Spark Server
|
||||
|
||||
* Start your exe using the -ConfigServer parameter to point at a running Spark Server
|
||||
```
|
||||
@@ -35,7 +58,7 @@ spark_client_sdk\src\spark_sdk> msbuild
|
||||
include: "http://location:8000/config/"
|
||||
```
|
||||
|
||||
## Examples
|
||||
### Examples
|
||||
* Make sure you can connect to a running server
|
||||
* run spark_sdk.exe with no parameters to see help
|
||||
```
|
||||
@@ -58,22 +81,15 @@ Arguments:
|
||||
* [Driver](src/spark_sdk/samples/SDKMain.cs)
|
||||
|
||||
|
||||
## Excel
|
||||
### Excel
|
||||
```
|
||||
spark_sdk\bin\Debug\net471> start spark_excel-addin64-packed.xll
|
||||
```
|
||||
* This will start excel and load the bts addin
|
||||
* Check the [```excel```](excel/) directory for an example spreadsheet
|
||||
|
||||
|
||||
## Notes
|
||||
|
||||
* Our client side API is based on Google's protocol buffers; the message types are all protos. https://developers.google.com/protocol-buffers/
|
||||
|
||||
* We extended the protoc compiler to generate c#, c++, excel and js bindings to the services provided by our server process (https://github.com/BlueTradingSystems/spark_sdk)
|
||||
|
||||
|
||||
* ### Dotnet core
|
||||
### Dotnet core
|
||||
|
||||
* Right now we only support c# Windows 10 clients, but the package targets both net471 and .net core 2.1.6, so in theory one could run a .net core or c++ client on linux with a little work.
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
|
||||
## Spark Client SDK Overview
|
||||
|
||||
The high level description of our order entry interface is as follows:
|
||||
|
||||
```
|
||||
service OrderService {
|
||||
// RPCs
|
||||
rpc create_order(Create) returns (Response)
|
||||
rpc cancel_order(Cancel) returns (Response)
|
||||
rpc update_order(Update) returns (Response)
|
||||
// Streams
|
||||
rpc orders (OrdersSub) returns (stream OrderRecord);
|
||||
rpc fills (FillsSub) returns (stream Fill);
|
||||
}
|
||||
```
|
||||
|
||||
This description uses the Google Protocol Buffers syntax to define the server interface (we use our own little compiler to generate bindings to this interface in C#, C++ and Excel). Using this server interface we can create, cancel or update orders, using the Remote Procedure Calls (RPCs) defined these orders can be exchange native orders or our own high level algo orders, or new order types created by users via the Spark Server SDK). We can monitor order state by subscribing to the orders stream above, which produces a a stream of OrderRecord objects, each capturing the latest state of a particular order, as it goes through it life cycle.
|
||||
|
||||
An OrderRecord looks like this:
|
||||
|
||||
```
|
||||
message OrderRecord {
|
||||
uint32 key;
|
||||
uint32 parent_key;
|
||||
OrderDefinition def;
|
||||
OrderState state;
|
||||
}
|
||||
```
|
||||
|
||||
We have an order key, a possibly null parent order key, an OrderDefinition record, which defines the basic elements of the order, namely its type, side, security, account, etc, and an OrderState record, which captures the latest state of the order:
|
||||
|
||||
```
|
||||
message OrderState {
|
||||
// Standard order state, shared by all order types
|
||||
OrderStatus status ;
|
||||
double price ;
|
||||
uint32 quantity ;
|
||||
uint32 filled_quantity;
|
||||
double last_price;
|
||||
double avg_price;
|
||||
string last_msg;
|
||||
google.protobuf.Timestamp created;
|
||||
google.protobuf.Timestamp last_change;
|
||||
// Custom order state, specific to the order type in question
|
||||
oneof custom {
|
||||
// native order types
|
||||
MarketOrderState market;
|
||||
LimitOrderState limit;
|
||||
StopOrderState stop;
|
||||
StopLimitOrderState stop_limit;
|
||||
// algo order types
|
||||
IcebergOrderState iceberg;
|
||||
SpreaderOrderState spreader;
|
||||
TimeBoxOrderState time_box;
|
||||
TickOrderState tick;
|
||||
LeanOrderState lean;
|
||||
JoinOrderState join;
|
||||
TopOrderState top;evident
|
||||
TriggerOrderState trigger;
|
||||
CoverOrderState cover;
|
||||
OffsetOrderState offset;
|
||||
DynamicOrderState dynamic;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This OrderState record consists of a common part, applicable to all order types, and a custom part that is specific to the particular order type the record is associated with. Most of the standard fields should be self-explanatory, the latest price, the latest quantity, the filled quantity, etc. The status enumerate field tells you which state the order is in. We currently define the following states:
|
||||
|
||||
```
|
||||
enum OrderStatus {
|
||||
// The order has been constructed but not acted on. Inactive orders
|
||||
// can be abandoned without consequences. This state should only be
|
||||
// used internally by the order manager, i.e. it should never appear
|
||||
// in externally visible orders.
|
||||
ORDER_STATUS_INACTIVE = 0;
|
||||
// The order is currently working, i.e. its algorithm is operating.
|
||||
ORDER_STATUS_WORKING = 1;
|
||||
// The order has completed successfully and accomplished its
|
||||
// goal. This is a terminal state.
|
||||
ORDER_STATUS_COMPLETED = 2;
|
||||
// The order was terminated orderly before it had a chance to
|
||||
// complete. This is a terminal state.
|
||||
ORDER_STATUS_CANCELED = 3;
|
||||
// The order has encountered an unexpected condition from which it
|
||||
// cannot recover. This a terminal state.
|
||||
ORDER_STATUS_ERROR = 4;
|
||||
// The last known state for this order was ORDER_STATUS_WORKING, but
|
||||
// since then the execution gateway has signaled a disconnect. This
|
||||
// is not a terminal state.
|
||||
ORDER_STATUS_DISCONNECTED = 5;
|
||||
// The order is initializiYou can ng. It cannot be modified at this
|
||||
point.
|
||||
ORDER_STATUS_PENDING_WORKING = 6;
|
||||
// The order is invalid and was rejected by Spark (not the
|
||||
// exchange), on creation. This is a terminal state.
|
||||
ORDER_STATUS_REJECTED_BY_SPARK= 7;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Threading
|
||||
Check out our API Threading Doc [here](Threading.md).
|
||||
@@ -0,0 +1,74 @@
|
||||
|
||||
# Client API Threading
|
||||
|
||||
BTS API provides two types of calls. There are RPC (remote procedure calls) which accept an argument and return a value and there are streams of tabular data which we call subscriptions. All communication to and from the server happens on a connection thread owned by the ServiceContext object and data must be marshaled back to the right context when the call is complete.
|
||||
|
||||
## RPC
|
||||
|
||||
### C#
|
||||
|
||||
All API calls provide both a synchronous and [asynchronous](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/async) version. If you are calling the API from a WPF or Windows Forms application you should always prefer the async version of the method because it will efficiently make the call and resume execution on the correct thread without blocking or lagging user interactions. The synchronous calls are intended for use in console applications where nothing else needs use of the thread until the data is available.
|
||||
|
||||
The async version of the method will return a `Result<T>` type which is used to signal if an error occurred during the call. You should test the Result.success to see if the call succeeded before using Result.value.
|
||||
|
||||
```csharp
|
||||
var s = context.locate<api.user.AuthService>();
|
||||
var result = await s.get_users_async(new GetUsersRequest());
|
||||
if (result.success) {
|
||||
Console.WriteLine(result.value);
|
||||
}
|
||||
else {
|
||||
Console.WriteLine($"Error {result.error_message}");
|
||||
}
|
||||
```
|
||||
|
||||
### C++
|
||||
|
||||
All C++ API calls also provide both a blocking synchronous version and a callback based asynchronous version. In the asynchronous case the callback will execute on the ServiceContext thread and you will need to handle marshaling that data to the appropriate thread. Just like in c# the callback will receive a `Result<T>` which will indicate success or failure. `Result.value` returns an `std::shared_ptr` so you have control over the lifetime of the value.
|
||||
|
||||
## Subscriptions
|
||||
|
||||
BTS provides streaming updates for some types of data. These updates are incremental in nature and will provide a snapshot of the current state on a new subscription. Streaming updates use the [ReactiveX library](http://reactivex.io) to manage subscribing and unsubscribing. This library provides a rich set of operators that you can use to slide and dice the data streams based on your specific application requirements.
|
||||
|
||||
### C#
|
||||
|
||||
The subscription callback will arrive on the ServiceContext thread but it can be easily marshaled to the thread of your choice using the [ObserveOn](http://reactivex.io/documentation/operators/observeon.html) operator. For a WPF or Windows Forms application the most common use of this will be [ObserveOnDispatcher]() which will simply execute the callback in the context of the original calling thread. By your choice of where to place the `ObserveOnDispatcher` call in your reactive call chain you can choose whether other operators execute before after switching threads.
|
||||
|
||||
In this example the `Where` and `SelectMany` operators will execute on `ServiceContext` connection thread and only the resulting matches will be marshaled across to the calling thread. It is safe to unsubscribe by disposing `sub` from any thread.
|
||||
|
||||
```csharp
|
||||
var orders = context.locate<OrderService>();
|
||||
ObservableCollection<OrderRecord> orders_with_errors;
|
||||
IDisposable sub =
|
||||
orders
|
||||
.subscribe_orders()
|
||||
.SelectMany(update => update.added)
|
||||
.Where(o => o.State.Status == OrderStatus.Error)
|
||||
.ObserveOnDispatcher()
|
||||
.Subscribe(o => {
|
||||
orders_with_errors.Add(o);
|
||||
});
|
||||
```
|
||||
|
||||
### C++
|
||||
|
||||
The C++ subscription callbacks use the [RxCpp](https://github.com/ReactiveX/RxCpp) library which implements the [ReactiveX](http://reactivex.io) operators. The subscribe call will return an `rxcpp::composite_subscription` which implements [RAII](https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization) and will unsubscribe when it is destroyed.
|
||||
|
||||
```cpp
|
||||
#include "lib/api/public/ServiceContext.h"
|
||||
#include "lib/api/services/OrderService.client.pb.h"
|
||||
#include <rxcpp/rx.hpp>
|
||||
#include <google/protobuf/util/json_util.h>
|
||||
//...
|
||||
bts::api::ServiceContext ctx;
|
||||
auto client = ctx.locate<bts::api::orderman::OrderService>();
|
||||
auto sub =
|
||||
client.subscribe_orders().subscribe([=](const bts::api::orderman::OrdersUpdate& update) {
|
||||
std::string result;
|
||||
for(const auto& order : update.added()) {
|
||||
auto status = google::protobuf::util::MessageToJsonString(*order, &result, {});
|
||||
std::cout << "New order: " << result << std::endl;
|
||||
}
|
||||
});
|
||||
|
||||
```
|
||||
@@ -61,6 +61,7 @@
|
||||
<None Include="$(OutputPath)\net471\spark_excel_example_2018.xlsm" pack="true" PackagePath=".\excel\spark_excel_example_2018.xlsm" />
|
||||
<None Include="$(OutputPath)\net471\spark_excel-addin64-packed.xll" pack="true" PackagePath=".\excel\spark_excel-addin64-packed.xll" />
|
||||
<None Include="$(OutputPath)\net471\spark_excel-addin64.dna" pack="true" PackagePath=".\excel\spark_excel-addin64.dna" />
|
||||
<None Include="doc/**" pack="true" PackagePath=".\doc\" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences" Condition= " '$(SparkRoot)' != '' ">
|
||||
|
||||
@@ -124,10 +124,16 @@ namespace bts.tests
|
||||
over_limit_order_key = over_limit_order_result.value.OrderKey;
|
||||
no_limit_order_key = no_limit_order_result.value.OrderKey;
|
||||
|
||||
bool waiting_for_orders = true;
|
||||
|
||||
var orders = _order_service.subscribei_orders().Subscribe(ords =>
|
||||
{
|
||||
waiting_for_orders = false;
|
||||
|
||||
IEnumerable<OrderRecordImmutable> filtered_orders = ords.all.Where(x => x.Key == under_limit_order_key || x.Key == over_limit_order_key || x.Key == no_limit_order_key);
|
||||
|
||||
Assert.IsTrue(filtered_orders.Count() == 3, "There should be 3 matching orders... there are not");
|
||||
|
||||
foreach(var o in filtered_orders)
|
||||
{
|
||||
if(o.Key == under_limit_order_key) {
|
||||
@@ -142,6 +148,9 @@ namespace bts.tests
|
||||
}
|
||||
});
|
||||
|
||||
while(waiting_for_orders) {
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
// Restore the Limits to the original values
|
||||
bool success = false;
|
||||
|
||||
@@ -3,3 +3,9 @@
|
||||
rm -rf $1
|
||||
mkdir $1
|
||||
cp -r $2/files/* $1
|
||||
|
||||
for filename in $1/*; do
|
||||
if [[ $filename == *.xz ]]; then
|
||||
unxz $filename
|
||||
fi
|
||||
done
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/services/AdminService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.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;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MDRecoverableConsumer.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_tests.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/MDSupplementarySource.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SODPosition.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/core/IOrderServices.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_testLine truncated
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/services/AdminService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MDRecoverableConsumer.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_tests.cpp;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/catch_test_runner.cpp;utils/AuthToken.cpp;utils/Dispatcher.cpp;utils/GrowableSPSCQueue.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SecureLogon.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/download.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp;utils/stats.cpp;utils/tests/AuthTokenTests.cpp;utils/thread_manager.cpp)
|
||||
@@ -93,6 +93,8 @@ message CustomOrderDefinition
|
||||
TriggerOrderDefinition trigger = 22;
|
||||
CoverOrderDefinition cover = 23;
|
||||
OffsetOrderDefinition offset = 24;
|
||||
OCOOrderDefinition oco = 25;
|
||||
PricerOrderDefinition pricer = 26;
|
||||
|
||||
DynamicOrderDefinition dynamic = 1000;
|
||||
}
|
||||
@@ -175,6 +177,17 @@ message OffsetOrderDefinition {
|
||||
uint32 tick_offset_on_deploy = 1;
|
||||
CustomOrderDefinition child = 6;
|
||||
}
|
||||
message OCOOrderDefinition {
|
||||
CustomOrderDefinition other = 1;
|
||||
int32 other_ticks = 2;
|
||||
api.RelativeSide other_side = 4;
|
||||
CustomOrderDefinition child = 3;
|
||||
}
|
||||
message PricerOrderDefinition {
|
||||
int32 price_offset_ticks = 1;
|
||||
double price_factor = 2;
|
||||
CustomOrderDefinition child = 3;
|
||||
}
|
||||
message DynamicOrderDefinition {
|
||||
string dynamic_order_type = 1;
|
||||
map<string, DynamicOrderParam> order_params = 2;
|
||||
@@ -224,6 +237,8 @@ message OrderState {
|
||||
TriggerOrderState trigger = 21;
|
||||
CoverOrderState cover = 22;
|
||||
OffsetOrderState offset = 24;
|
||||
OCOOrderState oco = 25;
|
||||
PricerOrderState pricer = 26;
|
||||
|
||||
DynamicOrderState dynamic = 255; // do not use anything bigger than 255, or things will break
|
||||
}
|
||||
@@ -297,6 +312,8 @@ message TopOrderState {}
|
||||
message TriggerOrderState {}
|
||||
message CoverOrderState {}
|
||||
message OffsetOrderState {}
|
||||
message OCOOrderState {}
|
||||
message PricerOrderState {}
|
||||
message DynamicOrderState {}
|
||||
|
||||
enum OrderStatus {
|
||||
|
||||
@@ -123,14 +123,14 @@ message RecordOptions {
|
||||
// Replay options
|
||||
//
|
||||
message ReplayOptions {
|
||||
optional string host = 1 [default = "mdreplay"];
|
||||
optional string base_path = 2 [default = "/spark"];
|
||||
optional string file_name = 3 [default = "futures.coconut"];
|
||||
optional string url = 1 [default = "http://mdreplay.bluetradesys.local/spark/futures.coconut"];
|
||||
|
||||
// 2.0 = double speed, 0.5 = half speed
|
||||
optional double speed = 11 [default = 1.0];
|
||||
|
||||
optional bool interactive = 12 [default = false];
|
||||
|
||||
optional string fallback = 20 [default ="data_files/futures.coconut"];
|
||||
}
|
||||
|
||||
message RelayOptions {
|
||||
|
||||
@@ -66,6 +66,14 @@ enum Side {
|
||||
SIDE_SELL = 50;
|
||||
}
|
||||
|
||||
enum RelativeSide {
|
||||
RELATIVESIDE_UNDEFINED = 0;
|
||||
RELATIVESIDE_OPPOSITE = 1;
|
||||
RELATIVESIDE_SAME = 2;
|
||||
RELATIVESIDE_BUY = 49;
|
||||
RELATIVESIDE_SELL = 50;
|
||||
}
|
||||
|
||||
enum PutOrCall {
|
||||
PUTORCALL_PUT = 0;
|
||||
PUTORCALL_CALL = 1;
|
||||
|
||||
@@ -182,23 +182,46 @@ void replay_url(const std::string& url, IRelayWriter& writer, int32_t naggle_ms)
|
||||
auto filename = url.substr(last_slash+1);
|
||||
filename = os::sparkdata_path("data/replay/") + filename;
|
||||
utils::download_file_if_newer(host, path, filename);
|
||||
replay_file(filename, writer, naggle_ms, true);
|
||||
if (boost::filesystem::exists(filename)) {
|
||||
replay_file(filename, writer, naggle_ms, true);
|
||||
}
|
||||
}
|
||||
|
||||
void replay_url_with_fallback(const std::string& url, IRelayWriter& writer, int32_t naggle_ms) {
|
||||
// loops forever
|
||||
replay_url(url, writer, naggle_ms);
|
||||
// If it returns it means it failed to download or play cached
|
||||
const auto fallback = config::get<ReplayOptions>().fallback();
|
||||
if (boost::filesystem::exists(fallback)) {
|
||||
replay_file(fallback, writer, naggle_ms);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
shared_ptr<IRelayWriter> mkrelayproducer(bool shared);
|
||||
|
||||
/*this is the public one*/
|
||||
void replay_recording(const string& filename, int32_t naggle_ms) {
|
||||
void replay_recording(const string& filename, int32_t naggle_ms, const std::string fallback) {
|
||||
auto writer = mkrelayproducer(true);
|
||||
if (config::get<ReplayOptions>().interactive()) {
|
||||
naggle_ms = -1;
|
||||
}
|
||||
|
||||
// Try relay_url/replay_file
|
||||
// If it fails resort to the fallback location
|
||||
|
||||
if (filename.find("http://") == 0) {
|
||||
// loops forever
|
||||
replay_url(filename, *writer, naggle_ms);
|
||||
}
|
||||
else {
|
||||
else if (boost::filesystem::exists(filename)) {
|
||||
// loops forever
|
||||
replay_file(filename, *writer, naggle_ms);
|
||||
}
|
||||
// try fallback
|
||||
if (boost::filesystem::exists(fallback)) {
|
||||
replay_file(fallback, *writer, naggle_ms);
|
||||
}
|
||||
}
|
||||
void print_recording(const string& filename) {
|
||||
ConsoleReplayWriter writer;
|
||||
|
||||
@@ -28,8 +28,9 @@ void record_everything(std::string path, std::string filename);
|
||||
void print_recording(const std::string&);
|
||||
void unprint_recording(const std::string& src, const std::string& dest);
|
||||
void trace_recording(const std::string& file, security_key key);
|
||||
void replay_recording(const std::string&, int32_t delay_ms);
|
||||
void replay_recording(const std::string&, int32_t delay_ms, const std::string fallback="");
|
||||
void replay_url(const std::string& url, IRelayWriter& writer, int32_t naggle_ms);
|
||||
void replay_url_with_fallback(const std::string& url, IRelayWriter& writer, int32_t naggle_ms);
|
||||
void replay_file(const std::string& filename, IRelayWriter& writer, int32_t naggle_ms, bool loop=false);
|
||||
|
||||
}}//namespace
|
||||
|
||||
@@ -11,7 +11,8 @@ namespace orderman {
|
||||
class ChildOrder {
|
||||
public:
|
||||
ChildOrder()
|
||||
: _order(nullptr), _parent_order_services(nullptr), _active(false) {}
|
||||
: _order(nullptr), _parent_order_services(nullptr),
|
||||
_child_order_services(nullptr), _active(false) {}
|
||||
|
||||
ChildOrder(Order &o, OrderServices &services)
|
||||
: _order(&o), _parent_order_services(&services),
|
||||
|
||||
@@ -119,6 +119,12 @@ class OrderStateUpdateEvent : public mercury::Event<OrderStateUpdateEvent> {
|
||||
case api::orderman::OrderState::kOffset:
|
||||
result.mutable_offset();
|
||||
break;
|
||||
case api::orderman::OrderState::kOco:
|
||||
result.mutable_oco();
|
||||
break;
|
||||
case api::orderman::OrderState::kPricer:
|
||||
result.mutable_pricer();
|
||||
break;
|
||||
case api::orderman::OrderState::kDynamic:
|
||||
result.mutable_dynamic();
|
||||
break;
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
#include "lib/orderman/orders/book_algos/JoinOrder.h"
|
||||
#include "lib/orderman/orders/book_algos/LeanOrder.h"
|
||||
#include "lib/orderman/orders/book_algos/OffsetOrder.h"
|
||||
#include "lib/orderman/orders/book_algos/TickOrder.h"
|
||||
#include "lib/orderman/orders/book_algos/OCOOrder.h"
|
||||
#include "lib/orderman/orders/book_algos/PricerOrder.h"
|
||||
#include "lib/orderman/orders/book_algos/TopOrder.h"
|
||||
#include "lib/orderman/orders/spreader_orders/SpreaderOrder.h"
|
||||
|
||||
@@ -152,7 +153,7 @@ Order &OrderFactory::allocate(OrderKey k, OrderKey pk,
|
||||
order_ptr.reset(new orderman::TimeBoxOrder());
|
||||
break;
|
||||
case CustomOrderDefinition::kTick:
|
||||
order_ptr.reset(new orderman::TickOrder());
|
||||
bts_assert(false);
|
||||
break;
|
||||
case CustomOrderDefinition::kLean:
|
||||
order_ptr.reset(new orderman::LeanOrder());
|
||||
@@ -171,7 +172,13 @@ Order &OrderFactory::allocate(OrderKey k, OrderKey pk,
|
||||
break;
|
||||
case CustomOrderDefinition::kOffset:
|
||||
order_ptr.reset(new orderman::OffsetOrder());
|
||||
break;
|
||||
break;
|
||||
case CustomOrderDefinition::kOco:
|
||||
order_ptr.reset(new orderman::OCOOrder());
|
||||
break;
|
||||
case CustomOrderDefinition::kPricer:
|
||||
order_ptr.reset(new orderman::PricerOrder());
|
||||
break;
|
||||
case CustomOrderDefinition::kDynamic: {
|
||||
order_ptr = me->dynamic_order_registry.build(
|
||||
def.custom_def().dynamic().dynamic_order_type());
|
||||
|
||||
@@ -292,7 +292,7 @@ void NativeOrder::warm_up_activate(OrderServicesData&data, OrderServices& servic
|
||||
}
|
||||
|
||||
|
||||
void NativeOrder::_on_activate(Price p, Quantity q,
|
||||
bool NativeOrder::_on_activate(Price p, Quantity q,
|
||||
bts::orderman::OrderServices &services) {
|
||||
me->state.set_price(p.value());
|
||||
me->state.set_quantity(q.value());
|
||||
@@ -312,7 +312,7 @@ void NativeOrder::_on_activate(Price p, Quantity q,
|
||||
"Dropping order {}",
|
||||
key().value());
|
||||
transition(ORDER_STATUS_REJECTED_BY_SPARK, "Exchange gateway is down");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// can we trade?
|
||||
@@ -328,7 +328,7 @@ void NativeOrder::_on_activate(Price p, Quantity q,
|
||||
|
||||
transition(ORDER_STATUS_REJECTED_BY_SPARK,
|
||||
fmt::format("Unauthorized order: {}", lqr.error_msg));
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// can we trade this security, with this size?
|
||||
@@ -345,7 +345,7 @@ void NativeOrder::_on_activate(Price p, Quantity q,
|
||||
|
||||
transition(ORDER_STATUS_REJECTED_BY_SPARK,
|
||||
fmt::format("Order would breach limit: {}", lqr.error_msg));
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// are we under the messaging threshold?
|
||||
@@ -356,7 +356,7 @@ void NativeOrder::_on_activate(Price p, Quantity q,
|
||||
key().value());
|
||||
transition(ORDER_STATUS_REJECTED_BY_SPARK,
|
||||
"Messaging threshold breached");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// if we are here we are good.
|
||||
@@ -395,6 +395,7 @@ void NativeOrder::_on_activate(Price p, Quantity q,
|
||||
auto const &ts = services.get_time_str();
|
||||
me->create_transact_time_bm = encoding.overwrite(
|
||||
me->create_transact_time_bm, &ts.value()[0], ts.value().size());
|
||||
return true;
|
||||
}
|
||||
|
||||
OrderOpResult NativeOrder::on_activate(Price p, Quantity q,
|
||||
@@ -409,7 +410,7 @@ OrderOpResult NativeOrder::on_activate(Price p, Quantity q,
|
||||
services.log_scope("NativeOrder::on_activate", key().value());
|
||||
|
||||
// this is a brand new order
|
||||
_on_activate(p,q,services);
|
||||
if (_on_activate(p,q,services)) {
|
||||
me->services->queue_fix(*me->session_services,
|
||||
jetfix::MessageTypes::NewOrderSingle,
|
||||
me->create_encoding);
|
||||
@@ -421,6 +422,8 @@ OrderOpResult NativeOrder::on_activate(Price p, Quantity q,
|
||||
key().value());
|
||||
// early return so we skip the expensive report_state() call
|
||||
return OrderOpResult{};
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// all cases below are for orders recovered from disk
|
||||
|
||||
@@ -43,7 +43,7 @@ class NativeOrder : public Order {
|
||||
void on_cancel_reject(const CancelRejectEvent &);
|
||||
void on_gateway_status(const GatewayStatusChangeEvent &);
|
||||
void report_state();
|
||||
void _on_activate(Price p, Quantity q,
|
||||
bool _on_activate(Price p, Quantity q,
|
||||
bts::orderman::OrderServices &services);
|
||||
void init_fix();
|
||||
void add_exchange_order_id_to_fix();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "BookAlgo.h"
|
||||
#include "lib/orderman/actors/order_manager/OrderBuilder.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include "lib/utils/helper_macros.h"
|
||||
#include "lib/orderman/actors/order_manager/OrderBuilder.h"
|
||||
#include <google/protobuf/timestamp.pb.h>
|
||||
|
||||
namespace bts {
|
||||
@@ -9,113 +9,165 @@ namespace orderman {
|
||||
|
||||
using namespace api::orderman;
|
||||
|
||||
struct BookAlgo::PImpl {
|
||||
PImpl()
|
||||
: services(nullptr), fake_detached_child(false), supports_hedge(false),
|
||||
has_activated_child(false) {}
|
||||
|
||||
OrderServices *services;
|
||||
|
||||
struct BookAlgo::PImpl
|
||||
{
|
||||
PImpl() : services(nullptr), is_detached(false),
|
||||
supports_hedge(false), has_activated_child(false)
|
||||
{
|
||||
}
|
||||
|
||||
OrderServices* services;
|
||||
|
||||
api::orderman::OrderDefinition def;
|
||||
api::orderman::OrderState state;
|
||||
|
||||
|
||||
OrderBuilder child_builder;
|
||||
ChildOrder child;
|
||||
api::orderman::OrderState child_state;
|
||||
bool fake_detached_child;
|
||||
|
||||
bool supports_hedge;
|
||||
OrderBuilder hedge_builder;
|
||||
std::vector<ChildOrder> hedges;
|
||||
using HedgeStateMap =
|
||||
boost::container::flat_map<OrderKey, api::orderman::OrderState>;
|
||||
HedgeStateMap hedges_state;
|
||||
|
||||
ChildOrder child;
|
||||
api::orderman::OrderState child_state;
|
||||
bool is_detached;
|
||||
|
||||
bool supports_hedge;
|
||||
OrderBuilder hedge_builder;
|
||||
|
||||
BookAlgo::HedgeMap hedges;
|
||||
BookAlgo::HedgeStateMap hedges_state;
|
||||
|
||||
double tick_size;
|
||||
bool has_activated_child;
|
||||
};
|
||||
|
||||
BookAlgo::BookAlgo() : me(new PImpl()) {}
|
||||
BookAlgo::BookAlgo() : me(new PImpl())
|
||||
{
|
||||
}
|
||||
|
||||
BookAlgo::~BookAlgo() {}
|
||||
|
||||
const api::orderman::OrderDefinition &BookAlgo::definition() const {
|
||||
|
||||
|
||||
const api::orderman::OrderDefinition& BookAlgo::definition() const
|
||||
{
|
||||
return me->def;
|
||||
}
|
||||
|
||||
const api::orderman::OrderState &BookAlgo::this_state() const {
|
||||
const api::orderman::OrderState& BookAlgo::this_state() const
|
||||
{
|
||||
return me->state;
|
||||
}
|
||||
|
||||
void BookAlgo::set_price(double p) { me->state.set_price(p); }
|
||||
|
||||
void BookAlgo::set_quantity(uint32_t s) { me->state.set_quantity(s); }
|
||||
|
||||
const api::orderman::OrderState &BookAlgo::child_state() const {
|
||||
return me->child_state;
|
||||
|
||||
void BookAlgo::set_price(double p)
|
||||
{
|
||||
me->state.set_price(p);
|
||||
}
|
||||
|
||||
void BookAlgo::set_quantity(uint32_t s)
|
||||
{
|
||||
me->state.set_quantity(s);
|
||||
}
|
||||
|
||||
void BookAlgo::set_child_price(double p) { me->child_state.set_price(p); }
|
||||
const api::orderman::OrderState& BookAlgo::child_state() const
|
||||
{
|
||||
return me->child_state;
|
||||
}
|
||||
|
||||
void BookAlgo::set_child_price(double p)
|
||||
{
|
||||
me->child_state.set_price(p);
|
||||
}
|
||||
|
||||
void BookAlgo::set_child_quantity(uint32_t s) {
|
||||
void BookAlgo::set_child_quantity(uint32_t s)
|
||||
{
|
||||
me->child_state.set_quantity(s);
|
||||
}
|
||||
|
||||
void BookAlgo::activate_child(Price p, Quantity q) {
|
||||
// per Pedro, activating the child is not a synchronous calls, and he asserts
|
||||
// that this is done only once
|
||||
if (!me->has_activated_child) {
|
||||
void BookAlgo::activate_child(Price p, Quantity q)
|
||||
{
|
||||
//per Pedro, activating the child is not a synchronous calls, and he asserts that this is done only once
|
||||
if(!me->has_activated_child)
|
||||
{
|
||||
me->child.activate(p, q);
|
||||
me->has_activated_child = true;
|
||||
}
|
||||
}
|
||||
|
||||
void BookAlgo::update_child(Price p, Quantity q)
|
||||
{
|
||||
me->child.update(p, q);
|
||||
}
|
||||
|
||||
void BookAlgo::cancel_child()
|
||||
{
|
||||
me->child.cancel();
|
||||
}
|
||||
|
||||
void BookAlgo::build_and_send_hedge(Price p, Quantity q)
|
||||
{
|
||||
auto hedge = me->hedge_builder.build();
|
||||
auto key = hedge.key();
|
||||
me->hedges[key] = std::move(hedge);
|
||||
me->hedges[key].activate(p, q);
|
||||
}
|
||||
|
||||
void BookAlgo::update_child(Price p, Quantity q) { me->child.update(p, q); }
|
||||
|
||||
void BookAlgo::cancel_child() { me->child.cancel(); }
|
||||
|
||||
void BookAlgo::build_and_send_hedge(Price p, Quantity q) {
|
||||
auto hedge = me->hedge_builder.build();
|
||||
me->hedges.push_back(std::move(hedge));
|
||||
me->hedges.back().activate(p, q);
|
||||
double BookAlgo::tick_size() const
|
||||
{
|
||||
return me->tick_size;
|
||||
}
|
||||
|
||||
double BookAlgo::tick_size() const { return me->tick_size; }
|
||||
BookAlgo::HedgeStateMap& BookAlgo::hedges_state()
|
||||
{
|
||||
return me->hedges_state;
|
||||
}
|
||||
|
||||
void BookAlgo::on_init_new(const api::orderman::OrderDefinition &def,
|
||||
const PreActivationOrderServices &services) {
|
||||
BookAlgo::HedgeMap& BookAlgo::hedges()
|
||||
{
|
||||
return me->hedges;
|
||||
}
|
||||
|
||||
bool BookAlgo::is_detached() const
|
||||
{
|
||||
return me->is_detached;
|
||||
}
|
||||
|
||||
|
||||
void BookAlgo::on_init_new(const api::orderman::OrderDefinition& def,
|
||||
const PreActivationOrderServices &services)
|
||||
{
|
||||
me->services = nullptr;
|
||||
me->def = def;
|
||||
|
||||
me->child_state.set_status(ORDER_STATUS_INACTIVE);
|
||||
|
||||
me->child_state.set_status(ORDER_STATUS_INACTIVE);
|
||||
OrderDefinition child_def = def;
|
||||
setup_child(def, services, me->child_state, &child_def);
|
||||
me->child_builder = OrderBuilder(key(), child_def, services.order_factory, 1);
|
||||
|
||||
OrderDefinition hedge_def = def;
|
||||
|
||||
OrderDefinition hedge_def = def;
|
||||
me->supports_hedge = setup_hedge(def, services, &hedge_def);
|
||||
if (me->supports_hedge)
|
||||
if(me->supports_hedge)
|
||||
me->hedge_builder = OrderBuilder(key(), hedge_def, services.order_factory, 4);
|
||||
|
||||
const bts::api::Security *sec =
|
||||
services.sec_db.resolve(SecurityKey(def.security_key()));
|
||||
if (sec) {
|
||||
|
||||
const bts::api::Security* sec = services.sec_db.resolve(SecurityKey(def.security_key()));
|
||||
if(sec)
|
||||
{
|
||||
me->tick_size = sec->contract_spec().low_tick();
|
||||
transition(ORDER_STATUS_INACTIVE);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
auto msg = fmt::format("Unknown security: {}", def.security_key());
|
||||
me->state.set_last_msg(msg);
|
||||
transition(ORDER_STATUS_REJECTED_BY_SPARK, msg);
|
||||
transition(ORDER_STATUS_REJECTED_BY_SPARK, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void BookAlgo::on_init_recovered(const api::orderman::OrderRecord &rec,
|
||||
const PreActivationOrderServices &) {
|
||||
void BookAlgo::on_init_recovered(const api::orderman::OrderRecord& rec,
|
||||
const PreActivationOrderServices &)
|
||||
{
|
||||
auto const &def = rec.def();
|
||||
me->def = def;
|
||||
me->state = rec.state();
|
||||
switch (me->state.status()) {
|
||||
case ORDER_STATUS_WORKING: {
|
||||
switch (me->state.status())
|
||||
{
|
||||
case ORDER_STATUS_WORKING:
|
||||
{
|
||||
auto msg = "System restarted with active BookAlgo";
|
||||
me->state.set_last_msg(msg);
|
||||
transition(ORDER_STATUS_ERROR, msg);
|
||||
@@ -142,20 +194,20 @@ void BookAlgo::on_init_recovered(const api::orderman::OrderRecord &rec,
|
||||
OrderOpResult BookAlgo::on_activate(Price p, Quantity q, OrderServices &services) {
|
||||
bts_assert(!me->services);
|
||||
me->services = &services;
|
||||
switch (this_state().status()) {
|
||||
switch (this_state().status())
|
||||
{
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
me->child_builder.activate(services);
|
||||
if (me->supports_hedge)
|
||||
me->child_builder.activate(services);
|
||||
if(me->supports_hedge)
|
||||
me->hedge_builder.activate(services);
|
||||
|
||||
|
||||
me->child = me->child_builder.build();
|
||||
set_price(p.value());
|
||||
set_quantity(q.value());
|
||||
services.subscribe_to_child_updates(
|
||||
[this](auto const &os) { this->on_child_order_update(os); });
|
||||
services.subscribe_to_book(
|
||||
SecurityKey(me->def.security_key()),
|
||||
[this](auto const &b) { this->on_book_update(b); });
|
||||
[this](auto const &os) { this->on_child_order_update(os); });
|
||||
services.subscribe_to_book(SecurityKey(me->def.security_key()),
|
||||
[this](auto const &b) { this->on_book_update(b); });
|
||||
transition(ORDER_STATUS_WORKING);
|
||||
break;
|
||||
|
||||
@@ -171,7 +223,7 @@ OrderOpResult BookAlgo::on_activate(Price p, Quantity q, OrderServices &services
|
||||
// state)
|
||||
case ORDER_STATUS_WORKING:
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
@@ -182,10 +234,13 @@ OrderOpResult BookAlgo::on_activate(Price p, Quantity q, OrderServices &services
|
||||
}
|
||||
|
||||
OrderOpResult BookAlgo::on_update(Price p, Quantity q) {
|
||||
{
|
||||
LOG(OrderMan, Info, "Updating BookAlgo {}", key().value());
|
||||
switch (this_state().status()) {
|
||||
switch (this_state().status())
|
||||
{
|
||||
case ORDER_STATUS_WORKING:
|
||||
switch (child_state().status()) {
|
||||
switch (child_state().status())
|
||||
{
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
set_price(p.value());
|
||||
set_quantity(q.value());
|
||||
@@ -193,8 +248,8 @@ OrderOpResult BookAlgo::on_update(Price p, Quantity q) {
|
||||
case ORDER_STATUS_WORKING:
|
||||
set_price(p.value());
|
||||
set_quantity(q.value());
|
||||
if (!me->fake_detached_child)
|
||||
me->child.update(p, q);
|
||||
if(!me->is_detached)
|
||||
me->child.update(p,q);
|
||||
break;
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
// we launched our child but we are not yet able
|
||||
@@ -204,7 +259,7 @@ OrderOpResult BookAlgo::on_update(Price p, Quantity q) {
|
||||
|
||||
// if the child was in any of these states we couldn't be
|
||||
// in the working state
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
@@ -237,18 +292,22 @@ OrderOpResult BookAlgo::on_update(Price p, Quantity q) {
|
||||
}
|
||||
|
||||
OrderOpResult BookAlgo::on_cancel() {
|
||||
|
||||
|
||||
LOG(OrderMan, Info, "Canceling BookAlgo Order {}", key().value());
|
||||
|
||||
switch (this_state().status()) {
|
||||
switch (this_state().status())
|
||||
{
|
||||
case ORDER_STATUS_WORKING:
|
||||
switch (child_state().status()) {
|
||||
switch (child_state().status())
|
||||
{
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
transition(ORDER_STATUS_CANCELED);
|
||||
break;
|
||||
case ORDER_STATUS_WORKING:
|
||||
if (!me->fake_detached_child)
|
||||
if(!me->is_detached)
|
||||
me->child.cancel();
|
||||
for (auto &i : me->hedges)
|
||||
for(auto& i : me->hedges)
|
||||
i.detach();
|
||||
transition(ORDER_STATUS_CANCELED);
|
||||
break;
|
||||
@@ -258,7 +317,7 @@ OrderOpResult BookAlgo::on_cancel() {
|
||||
break;
|
||||
|
||||
// child cannot be in any of these if we are in the working state
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
@@ -289,50 +348,103 @@ OrderOpResult BookAlgo::on_cancel() {
|
||||
return OrderOpResult{};
|
||||
}
|
||||
|
||||
void BookAlgo::transition(api::orderman::OrderStatus new_status,
|
||||
std::string msg) {
|
||||
void BookAlgo::transition(api::orderman::OrderStatus new_status, std::string msg)
|
||||
{
|
||||
auto const &from = OrderStatus_Name(me->state.status());
|
||||
auto const &to = OrderStatus_Name(new_status);
|
||||
LOG(OrderMan, Info, "Transitioning BookAlgo {} from {} to {}. Msg: {}",
|
||||
key().value(), from, to, msg);
|
||||
LOG(OrderMan, Info, "Transitioning BookAlgo {} from {} to {}. Msg: {}", key().value(), from, to, msg);
|
||||
me->state.set_status(new_status);
|
||||
}
|
||||
|
||||
void BookAlgo::on_child_order_update(const OrderStateUpdateEvent &ev) {
|
||||
if (me->fake_detached_child)
|
||||
return;
|
||||
if (ev.key != me->child.key())
|
||||
void BookAlgo::on_child_order_update(const OrderStateUpdateEvent& ev)
|
||||
{
|
||||
if(me->is_detached)
|
||||
return;
|
||||
if(ev.key != me->child.key()) //hedge state change
|
||||
{
|
||||
api::orderman::OrderState orig_state = api::orderman::OrderState::default_instance(); //TODO this isn't quite right, should be hedgetype state
|
||||
auto it = me->hedges_state.find(ev.key);
|
||||
if(it != me->hedges_state.end())
|
||||
orig_state = it->second;
|
||||
me->hedges_state[ev.key] = ev.rebuild_state();
|
||||
else {
|
||||
switch (this_state().status())
|
||||
{
|
||||
case ORDER_STATUS_WORKING:
|
||||
switch (ev.status)
|
||||
{
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
break;
|
||||
case ORDER_STATUS_WORKING:
|
||||
process_hedge_state_change(orig_state, ev);
|
||||
break;
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
process_hedge_state_change(orig_state, ev);
|
||||
transition(ORDER_STATUS_COMPLETED);
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
process_hedge_state_change(orig_state, ev);
|
||||
transition(ORDER_STATUS_ERROR, "Unexpected child order state");
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else //child state change
|
||||
{
|
||||
api::orderman::OrderState orig_state = child_state();
|
||||
me->child_state = ev.rebuild_state();
|
||||
switch (this_state().status()) {
|
||||
switch (this_state().status())
|
||||
{
|
||||
case ORDER_STATUS_WORKING:
|
||||
switch (ev.status) {
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
break;
|
||||
case ORDER_STATUS_WORKING:
|
||||
if (me->supports_hedge)
|
||||
send_hedge_if_new_fills(orig_state, ev);
|
||||
break;
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
transition(ORDER_STATUS_COMPLETED);
|
||||
if (me->supports_hedge)
|
||||
send_hedge_if_new_fills(orig_state, ev);
|
||||
break;
|
||||
switch (ev.status)
|
||||
{
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
break;
|
||||
case ORDER_STATUS_WORKING:
|
||||
process_child_state_change(orig_state, ev);
|
||||
break;
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
process_child_state_change(orig_state, ev);
|
||||
transition(ORDER_STATUS_COMPLETED);
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
transition(ORDER_STATUS_ERROR, "Unexpected child order state");
|
||||
break;
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
process_child_state_change(orig_state, ev);
|
||||
transition(ORDER_STATUS_ERROR, "Unexpected child order state");
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -354,56 +466,54 @@ void BookAlgo::on_child_order_update(const OrderStateUpdateEvent &ev) {
|
||||
report_state();
|
||||
}
|
||||
|
||||
void BookAlgo::report_state() {
|
||||
auto merged_state = me->state;
|
||||
void BookAlgo::report_state()
|
||||
{
|
||||
OrderState merged_state = me->state;
|
||||
merged_state.set_filled_quantity(child_state().filled_quantity());
|
||||
merged_state.set_last_price(child_state().last_price());
|
||||
merged_state.set_avg_price(child_state().avg_price());
|
||||
merged_state.set_display_status(
|
||||
bts::api::orderman::OrderState_DisplayStatus::
|
||||
OrderState_DisplayStatus_HIDDEN);
|
||||
merged_state.set_display_status(bts::api::orderman::OrderState_DisplayStatus::OrderState_DisplayStatus_HIDDEN);
|
||||
me->services->report_state(merged_state);
|
||||
}
|
||||
|
||||
void BookAlgo::payup(const md::PriceSize &opposite,
|
||||
const bts::orderman::BookUpdateEvent &,
|
||||
uint32_t cross_ticks) {
|
||||
void BookAlgo::payup(const md::PriceSize& opposite, const bts::orderman::BookUpdateEvent&, uint32_t cross_ticks)
|
||||
{
|
||||
double new_price = opposite.price() + me->tick_size * cross_ticks;
|
||||
me->child.update(Price(new_price), Quantity(this_state().quantity()));
|
||||
report_state();
|
||||
}
|
||||
|
||||
void BookAlgo::paydown(const md::PriceSize &opposite,
|
||||
const bts::orderman::BookUpdateEvent &,
|
||||
uint32_t cross_ticks) {
|
||||
void BookAlgo::paydown(const md::PriceSize& opposite, const bts::orderman::BookUpdateEvent&, uint32_t cross_ticks)
|
||||
{
|
||||
double new_price = opposite.price() - me->tick_size * cross_ticks;
|
||||
me->child.update(Price(new_price), Quantity(this_state().quantity()));
|
||||
report_state();
|
||||
}
|
||||
|
||||
void BookAlgo::detach(bts::api::orderman::OrderStatus status_after_detach) {
|
||||
me->fake_detached_child = true;
|
||||
void BookAlgo::detach(bts::api::orderman::OrderStatus status_after_detach)
|
||||
{
|
||||
me->child.detach();
|
||||
transition(status_after_detach);
|
||||
report_state();
|
||||
}
|
||||
|
||||
void BookAlgo::on_book_update(const bts::orderman::BookUpdateEvent &) {}
|
||||
void BookAlgo::on_book_update(const bts::orderman::BookUpdateEvent&) {}
|
||||
|
||||
bool BookAlgo::setup_hedge(const api::orderman::OrderDefinition &,
|
||||
const PreActivationOrderServices &,
|
||||
api::orderman::OrderDefinition *) {
|
||||
return false;
|
||||
bool BookAlgo::setup_hedge(const api::orderman::OrderDefinition&, const PreActivationOrderServices&, api::orderman::OrderDefinition*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void BookAlgo::send_hedge_if_new_fills(
|
||||
const api::orderman::OrderState &orig_state,
|
||||
const OrderStateUpdateEvent &new_state) {
|
||||
UNUSED(orig_state);
|
||||
UNUSED(new_state);
|
||||
// uint32_t qty = new_state.state.filled_quantity() -
|
||||
// orig_state.filled_quantity(); UNUSED(qty);
|
||||
void BookAlgo::process_child_state_change(const api::orderman::OrderState& orig_state, const OrderStateUpdateEvent& new_state)
|
||||
{
|
||||
UNUSED(orig_state);UNUSED(new_state);
|
||||
}
|
||||
|
||||
void BookAlgo::process_hedge_state_change(const api::orderman::OrderState& orig_state, const OrderStateUpdateEvent& new_state)
|
||||
{
|
||||
UNUSED(orig_state);UNUSED(new_state);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -33,7 +33,8 @@ protected:
|
||||
api::orderman::OrderState&, api::orderman::OrderDefinition*) = 0;
|
||||
virtual bool setup_hedge(const api::orderman::OrderDefinition& parent, const PreActivationOrderServices&,
|
||||
api::orderman::OrderDefinition*);
|
||||
virtual void send_hedge_if_new_fills(const api::orderman::OrderState&, const OrderStateUpdateEvent&);
|
||||
virtual void process_child_state_change(const api::orderman::OrderState&, const OrderStateUpdateEvent&);
|
||||
virtual void process_hedge_state_change(const api::orderman::OrderState&, const OrderStateUpdateEvent&);
|
||||
|
||||
virtual void on_child_order_update(const OrderStateUpdateEvent&);
|
||||
virtual void on_book_update(const bts::orderman::BookUpdateEvent&);
|
||||
@@ -49,6 +50,7 @@ private:
|
||||
std::unique_ptr<PImpl> me;
|
||||
|
||||
protected:
|
||||
double tick_size() const;
|
||||
const api::orderman::OrderState& this_state() const;
|
||||
void set_price(double);
|
||||
void set_quantity(uint32_t);
|
||||
@@ -59,9 +61,14 @@ protected:
|
||||
void activate_child(Price p, Quantity q);
|
||||
void update_child(Price, Quantity);
|
||||
void cancel_child();
|
||||
bool is_detached() const;
|
||||
|
||||
void build_and_send_hedge(Price, Quantity);
|
||||
double tick_size() const;
|
||||
typedef boost::container::flat_map<OrderKey, ChildOrder> HedgeMap;
|
||||
typedef boost::container::flat_map<OrderKey, api::orderman::OrderState> HedgeStateMap;
|
||||
HedgeStateMap& hedges_state();
|
||||
HedgeMap& hedges();
|
||||
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -10,87 +10,94 @@ namespace orderman {
|
||||
|
||||
using namespace api::orderman;
|
||||
|
||||
struct CoverOrder::PImpl {
|
||||
struct CoverOrder::PImpl
|
||||
{
|
||||
PImpl() {}
|
||||
|
||||
int hedge_ticks;
|
||||
OrderDefinition hedge_def;
|
||||
|
||||
int hedge_ticks;
|
||||
OrderDefinition hedge_def;
|
||||
};
|
||||
|
||||
|
||||
CoverOrder::CoverOrder() : me(new PImpl()) {}
|
||||
|
||||
CoverOrder::~CoverOrder() {}
|
||||
|
||||
void CoverOrder::setup_child(const api::orderman::OrderDefinition &this_def,
|
||||
const PreActivationOrderServices &,
|
||||
api::orderman::OrderState &initial_state,
|
||||
api::orderman::OrderDefinition *out_child) {
|
||||
void CoverOrder::setup_child(const api::orderman::OrderDefinition& this_def, const PreActivationOrderServices&,
|
||||
api::orderman::OrderState& initial_state, api::orderman::OrderDefinition* out_child)
|
||||
{
|
||||
initial_state.mutable_cover();
|
||||
auto const &cover_def = this_def.custom_def().cover();
|
||||
auto const &cover_def = this_def.custom_def().cover();
|
||||
*out_child->mutable_custom_def() = cover_def.child();
|
||||
|
||||
me->hedge_ticks = cover_def.hedge_ticks();
|
||||
|
||||
me->hedge_ticks = cover_def.hedge_ticks();
|
||||
}
|
||||
|
||||
bool CoverOrder::setup_hedge(const api::orderman::OrderDefinition &this_def,
|
||||
const PreActivationOrderServices &,
|
||||
api::orderman::OrderDefinition *out_hedge) {
|
||||
bool CoverOrder::setup_hedge(const api::orderman::OrderDefinition& this_def, const PreActivationOrderServices&,
|
||||
api::orderman::OrderDefinition* out_hedge)
|
||||
{
|
||||
auto const &cover_def = this_def.custom_def().cover();
|
||||
if (cover_def.has_hedge()) {
|
||||
*out_hedge->mutable_custom_def() = cover_def.hedge();
|
||||
if (definition().side() == api::SIDE_BUY)
|
||||
if(cover_def.has_hedge())
|
||||
{
|
||||
*out_hedge->mutable_custom_def() = cover_def.hedge();
|
||||
if(definition().side() == api::SIDE_BUY)
|
||||
out_hedge->set_side(api::SIDE_SELL);
|
||||
else
|
||||
out_hedge->set_side(api::SIDE_BUY);
|
||||
return true;
|
||||
} else
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void CoverOrder::send_hedge_if_new_fills(
|
||||
const api::orderman::OrderState &orig_state,
|
||||
const OrderStateUpdateEvent &new_state) {
|
||||
void CoverOrder::process_child_state_change(const api::orderman::OrderState& orig_state, const OrderStateUpdateEvent& new_state)
|
||||
{
|
||||
uint32_t qty = new_state.filled_quantity - orig_state.filled_quantity();
|
||||
if (qty > 0) {
|
||||
if(qty > 0)
|
||||
{
|
||||
double prx = new_state.last_price;
|
||||
if (definition().side() ==
|
||||
api::SIDE_BUY) // if this is a buy, I'm going to sell my hedge, nticks
|
||||
// higher than the fill price
|
||||
if(definition().side() == api::SIDE_BUY) //if this is a buy, I'm going to sell my hedge, nticks higher than the fill price
|
||||
prx = prx + tick_size() * me->hedge_ticks;
|
||||
else
|
||||
prx = prx - tick_size() * me->hedge_ticks;
|
||||
|
||||
|
||||
build_and_send_hedge(Price(prx), Quantity(qty));
|
||||
}
|
||||
}
|
||||
|
||||
void CoverOrder::on_book_update(const bts::orderman::BookUpdateEvent &) {
|
||||
switch (this_state().status()) {
|
||||
void CoverOrder::on_book_update(const bts::orderman::BookUpdateEvent& )
|
||||
{
|
||||
switch (this_state().status())
|
||||
{
|
||||
case ORDER_STATUS_WORKING:
|
||||
switch (child_state().status()) {
|
||||
case ORDER_STATUS_INACTIVE: {
|
||||
activate_child(Price(this_state().price()),
|
||||
Quantity(this_state().quantity()));
|
||||
transition(ORDER_STATUS_WORKING);
|
||||
report_state();
|
||||
} break;
|
||||
case ORDER_STATUS_WORKING: {
|
||||
} break;
|
||||
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
switch (child_state().status())
|
||||
{
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
{
|
||||
activate_child(Price(this_state().price()), Quantity(this_state().quantity()));
|
||||
transition(ORDER_STATUS_WORKING);
|
||||
report_state();
|
||||
}
|
||||
break;
|
||||
|
||||
// child cannot be in any of these states if we are in the working state
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
case ORDER_STATUS_WORKING:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
break;
|
||||
|
||||
// child cannot be in any of these states if we are in the working state
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
@@ -106,8 +113,9 @@ void CoverOrder::on_book_update(const bts::orderman::BookUpdateEvent &) {
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -22,7 +22,7 @@ protected:
|
||||
api::orderman::OrderState&, api::orderman::OrderDefinition*) override;
|
||||
bool setup_hedge(const api::orderman::OrderDefinition& parent, const PreActivationOrderServices&,
|
||||
api::orderman::OrderDefinition*) override;
|
||||
void send_hedge_if_new_fills(const api::orderman::OrderState&, const OrderStateUpdateEvent&) override;
|
||||
void process_child_state_change(const api::orderman::OrderState&, const OrderStateUpdateEvent&) override;
|
||||
void on_book_update(const bts::orderman::BookUpdateEvent&) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
#include "OCOOrder.h"
|
||||
|
||||
#include "lib/orderman/actors/order_manager/OrderBuilder.h"
|
||||
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include "lib/utils/helper_macros.h"
|
||||
#include <google/protobuf/timestamp.pb.h>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
using namespace api::orderman;
|
||||
|
||||
struct OCOOrder::PImpl
|
||||
{
|
||||
PImpl() {}
|
||||
|
||||
int other_ticks;
|
||||
bts::api::RelativeSide other_side;
|
||||
OrderDefinition other_def;
|
||||
bool hedge_sent;
|
||||
};
|
||||
|
||||
|
||||
OCOOrder::OCOOrder() : me(new PImpl()) {}
|
||||
|
||||
OCOOrder::~OCOOrder() {}
|
||||
|
||||
void OCOOrder::setup_child(const api::orderman::OrderDefinition& this_def, const PreActivationOrderServices&,
|
||||
api::orderman::OrderState& initial_state, api::orderman::OrderDefinition* out_child)
|
||||
{
|
||||
initial_state.mutable_oco();
|
||||
auto const &oco_def = this_def.custom_def().oco();
|
||||
*out_child->mutable_custom_def() = oco_def.child();
|
||||
|
||||
me->other_ticks = oco_def.other_ticks();
|
||||
me->other_side = oco_def.other_side();
|
||||
me->hedge_sent = false;
|
||||
}
|
||||
|
||||
//hedge here means 'other'
|
||||
bool OCOOrder::setup_hedge(const api::orderman::OrderDefinition& this_def, const PreActivationOrderServices&,
|
||||
api::orderman::OrderDefinition* out_hedge)
|
||||
{
|
||||
auto const &oco_def = this_def.custom_def().oco();
|
||||
if(oco_def.has_other())
|
||||
{
|
||||
*out_hedge->mutable_custom_def() = oco_def.other();
|
||||
bts_assert_msg(me->other_side != api::RELATIVESIDE_UNDEFINED, "undefined relativeside");
|
||||
|
||||
if(oco_def.other_side() == api::RELATIVESIDE_BUY)
|
||||
out_hedge->set_side(api::SIDE_BUY);
|
||||
else if(oco_def.other_side() == api::RELATIVESIDE_SELL)
|
||||
out_hedge->set_side(api::SIDE_SELL);
|
||||
else if(oco_def.other_side() == api::RELATIVESIDE_SAME)
|
||||
out_hedge->set_side(definition().side());
|
||||
else if(oco_def.other_side() == api::RELATIVESIDE_OPPOSITE)
|
||||
{
|
||||
if(definition().side() == api::SIDE_BUY)
|
||||
out_hedge->set_side(api::SIDE_SELL);
|
||||
else
|
||||
out_hedge->set_side(api::SIDE_BUY);
|
||||
}
|
||||
else
|
||||
bts_assert_msg(false, "unknown relativeside");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void OCOOrder::process_child_state_change(const api::orderman::OrderState& orig_state, const OrderStateUpdateEvent& new_state)
|
||||
{
|
||||
uint32_t fill_qty = new_state.filled_quantity - orig_state.filled_quantity();
|
||||
const auto& the_state = hedges_state();
|
||||
auto& the_hedges = hedges();
|
||||
for(const auto& i : the_state)
|
||||
{
|
||||
const auto& hedge_state = i.second;
|
||||
|
||||
uint32_t working_qty = hedge_state.quantity() - hedge_state.filled_quantity();
|
||||
uint32_t newqty = working_qty - std::min(fill_qty, working_qty);
|
||||
bts_assert(newqty <= working_qty);
|
||||
|
||||
auto it = the_hedges.find(i.first);
|
||||
if(it != the_hedges.end())
|
||||
{
|
||||
if(newqty != working_qty)
|
||||
{
|
||||
if(newqty > 0)
|
||||
{
|
||||
LOG(OrderMan, Info, "OCO reducing hedge qty from {} to {}", working_qty, newqty);
|
||||
it->second.update(Price(hedge_state.price()), Quantity(newqty));
|
||||
}
|
||||
else
|
||||
it->second.cancel();
|
||||
}
|
||||
else if(new_state.status != api::orderman::OrderStatus::ORDER_STATUS_PENDING_WORKING &&
|
||||
new_state.status != api::orderman::OrderStatus::ORDER_STATUS_WORKING)
|
||||
{
|
||||
it->second.cancel();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(OrderMan, Error, "OCO Can't find hedge order {}", i.first);
|
||||
cancel_child();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OCOOrder::process_hedge_state_change(const api::orderman::OrderState& orig_state, const OrderStateUpdateEvent& new_state)
|
||||
{
|
||||
uint32_t fill_qty = new_state.filled_quantity - orig_state.filled_quantity();
|
||||
uint32_t working_qty = child_state().quantity() - child_state().filled_quantity();
|
||||
uint32_t newqty = working_qty - std::min(fill_qty, working_qty);
|
||||
bts_assert(newqty <= working_qty);
|
||||
if(newqty != working_qty)
|
||||
{
|
||||
if(newqty > 0)
|
||||
{
|
||||
LOG(OrderMan, Info, "OCO reducing child qty from {} to {}", working_qty, newqty);
|
||||
update_child(Price(child_state().price()), Quantity(newqty));
|
||||
}
|
||||
else
|
||||
cancel_child();
|
||||
}
|
||||
else if(new_state.status != api::orderman::OrderStatus::ORDER_STATUS_PENDING_WORKING &&
|
||||
new_state.status != api::orderman::OrderStatus::ORDER_STATUS_WORKING)
|
||||
{
|
||||
cancel_child();
|
||||
}
|
||||
}
|
||||
|
||||
void OCOOrder::on_book_update(const bts::orderman::BookUpdateEvent& )
|
||||
{
|
||||
switch (this_state().status())
|
||||
{
|
||||
case ORDER_STATUS_WORKING:
|
||||
switch (child_state().status())
|
||||
{
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
{
|
||||
activate_child(Price(this_state().price()), Quantity(this_state().quantity()));
|
||||
|
||||
if(!me->hedge_sent)
|
||||
{
|
||||
double prx = this_state().price();
|
||||
if(definition().side() == api::SIDE_BUY)
|
||||
prx = prx + tick_size() * me->other_ticks;
|
||||
else
|
||||
prx = prx - tick_size() * me->other_ticks;
|
||||
build_and_send_hedge( Price(prx), Quantity(this_state().quantity()) );
|
||||
me->hedge_sent = true;
|
||||
}
|
||||
transition(ORDER_STATUS_WORKING);
|
||||
report_state();
|
||||
}
|
||||
break;
|
||||
case ORDER_STATUS_WORKING:
|
||||
{
|
||||
}
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
break;
|
||||
|
||||
// child cannot be in any of these states if we are in the working state
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OCOOrder::on_cancel(trace::CorID const&)
|
||||
{
|
||||
LOG(OrderMan, Info, "Canceling OCOOrder Order {}", key().value());
|
||||
|
||||
switch (this_state().status())
|
||||
{
|
||||
case ORDER_STATUS_WORKING:
|
||||
switch (child_state().status())
|
||||
{
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
transition(ORDER_STATUS_CANCELED);
|
||||
break;
|
||||
case ORDER_STATUS_WORKING:
|
||||
if(!is_detached())
|
||||
{
|
||||
cancel_child();
|
||||
for(auto& i : hedges())
|
||||
i.second.cancel();
|
||||
}
|
||||
transition(ORDER_STATUS_CANCELED);
|
||||
break;
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
// child is running but it cannot be canceled at this point
|
||||
transition(this_state().status(), "Cannot cancel order");
|
||||
break;
|
||||
|
||||
// child cannot be in any of these if we are in the working state
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
transition(this_state().status(), "Cannot cancel order");
|
||||
break;
|
||||
|
||||
// these are unreacheable for this order type
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
report_state();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/orderman/orders/book_algos/BookAlgo.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
class OrderStateUpdateEvent;
|
||||
class BookUpdateEvent;
|
||||
|
||||
//OCOOrder initializes the child order as normal
|
||||
//it also initializes a 'hedge' or 'other' at the same time, the child and the hedge are managed with OCO semantics:
|
||||
//when one fills the other's quantity is reduced (or cancelled on a full fill)
|
||||
|
||||
class OCOOrder : public BookAlgo
|
||||
{
|
||||
public:
|
||||
OCOOrder();
|
||||
virtual ~OCOOrder();
|
||||
|
||||
void on_cancel(trace::CorID const&) override ;
|
||||
protected:
|
||||
void setup_child(const api::orderman::OrderDefinition&, const PreActivationOrderServices&,
|
||||
api::orderman::OrderState&, api::orderman::OrderDefinition*) override;
|
||||
bool setup_hedge(const api::orderman::OrderDefinition& parent, const PreActivationOrderServices&,
|
||||
api::orderman::OrderDefinition*) override;
|
||||
void process_child_state_change(const api::orderman::OrderState&, const OrderStateUpdateEvent&) override;
|
||||
void process_hedge_state_change(const api::orderman::OrderState&, const OrderStateUpdateEvent&) override;
|
||||
void on_book_update(const bts::orderman::BookUpdateEvent&) override;
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -10,65 +10,75 @@ namespace orderman {
|
||||
|
||||
using namespace api::orderman;
|
||||
|
||||
struct OffsetOrder::PImpl {
|
||||
struct OffsetOrder::PImpl
|
||||
{
|
||||
PImpl() {}
|
||||
|
||||
uint32_t tick_offset_on_deploy;
|
||||
|
||||
uint32_t tick_offset_on_deploy;
|
||||
};
|
||||
|
||||
|
||||
OffsetOrder::OffsetOrder() : me(new PImpl()) {}
|
||||
|
||||
OffsetOrder::~OffsetOrder() {}
|
||||
|
||||
void OffsetOrder::setup_child(const api::orderman::OrderDefinition &this_def,
|
||||
const PreActivationOrderServices &,
|
||||
api::orderman::OrderState &initial_state,
|
||||
api::orderman::OrderDefinition *out_child) {
|
||||
initial_state.mutable_tick();
|
||||
auto const &offset_def = this_def.custom_def().offset();
|
||||
void OffsetOrder::setup_child(const api::orderman::OrderDefinition& this_def, const PreActivationOrderServices&,
|
||||
api::orderman::OrderState& initial_state, api::orderman::OrderDefinition* out_child)
|
||||
{
|
||||
initial_state.mutable_offset();
|
||||
auto const &offset_def = this_def.custom_def().offset();
|
||||
*out_child->mutable_custom_def() = offset_def.child();
|
||||
|
||||
me->tick_offset_on_deploy = offset_def.tick_offset_on_deploy();
|
||||
|
||||
me->tick_offset_on_deploy = offset_def.tick_offset_on_deploy();
|
||||
}
|
||||
|
||||
void OffsetOrder::on_book_update(const bts::orderman::BookUpdateEvent &book) {
|
||||
switch (this_state().status()) {
|
||||
|
||||
void OffsetOrder::on_book_update(const bts::orderman::BookUpdateEvent& book)
|
||||
{
|
||||
switch (this_state().status())
|
||||
{
|
||||
case ORDER_STATUS_WORKING:
|
||||
switch (child_state().status()) {
|
||||
case ORDER_STATUS_INACTIVE: {
|
||||
if (definition().side() == api::SIDE_BUY) {
|
||||
const auto &same = book.book.side(api::Side::SIDE_BUY)[0];
|
||||
double price =
|
||||
same.price() - tick_size() * me->tick_offset_on_deploy;
|
||||
activate_child(Price(price), Quantity(this_state().quantity()));
|
||||
transition(ORDER_STATUS_WORKING);
|
||||
} else {
|
||||
const auto &same = book.book.side(api::Side::SIDE_SELL)[0];
|
||||
double price =
|
||||
same.price() + tick_size() * me->tick_offset_on_deploy;
|
||||
activate_child(Price(price), Quantity(this_state().quantity()));
|
||||
transition(ORDER_STATUS_WORKING);
|
||||
switch (child_state().status())
|
||||
{
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
{
|
||||
if(definition().side() == api::SIDE_BUY)
|
||||
{
|
||||
const auto& same = book.book.side(api::Side::SIDE_BUY)[0];
|
||||
double price = same.price() - tick_size() * me->tick_offset_on_deploy;
|
||||
activate_child(Price(price), Quantity(this_state().quantity()));
|
||||
transition(ORDER_STATUS_WORKING);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto& same = book.book.side(api::Side::SIDE_SELL)[0];
|
||||
double price = same.price() + tick_size() * me->tick_offset_on_deploy;
|
||||
activate_child(Price(price), Quantity(this_state().quantity()));
|
||||
transition(ORDER_STATUS_WORKING);
|
||||
}
|
||||
report_state();
|
||||
}
|
||||
report_state();
|
||||
} break;
|
||||
case ORDER_STATUS_WORKING: {
|
||||
detach();
|
||||
} break;
|
||||
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
break;
|
||||
|
||||
// child cannot be in any of these states if we are in the working state
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
case ORDER_STATUS_WORKING:
|
||||
{
|
||||
detach();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
break;
|
||||
|
||||
// child cannot be in any of these states if we are in the working state
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
@@ -84,8 +94,9 @@ void OffsetOrder::on_book_update(const bts::orderman::BookUpdateEvent &book) {
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "PricerOrder.h"
|
||||
|
||||
#include "lib/orderman/actors/order_manager/OrderBuilder.h"
|
||||
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include <google/protobuf/timestamp.pb.h>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
using namespace api::orderman;
|
||||
|
||||
struct PricerOrder::PImpl
|
||||
{
|
||||
PImpl() {}
|
||||
|
||||
int32_t price_offset_ticks;
|
||||
double price_factor;
|
||||
};
|
||||
|
||||
|
||||
PricerOrder::PricerOrder() : me(new PImpl()) {}
|
||||
|
||||
PricerOrder::~PricerOrder() {}
|
||||
|
||||
void PricerOrder::setup_child(const api::orderman::OrderDefinition& this_def, const PreActivationOrderServices&,
|
||||
api::orderman::OrderState& initial_state, api::orderman::OrderDefinition* out_child)
|
||||
{
|
||||
initial_state.mutable_pricer();
|
||||
auto const &pricer_def = this_def.custom_def().pricer();
|
||||
*out_child->mutable_custom_def() = pricer_def.child();
|
||||
|
||||
me->price_offset_ticks = pricer_def.price_offset_ticks();
|
||||
me->price_factor = pricer_def.price_factor();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/orderman/orders/book_algos/BookAlgo.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
class OrderStateUpdateEvent;
|
||||
class BookUpdateEvent;
|
||||
|
||||
//PricerOrder matches the bid (for buy) or offer (for sell) price of it's target security times a factor plus a constant
|
||||
|
||||
class PricerOrder : public BookAlgo
|
||||
{
|
||||
public:
|
||||
PricerOrder();
|
||||
virtual ~PricerOrder();
|
||||
|
||||
protected:
|
||||
void setup_child(const api::orderman::OrderDefinition& this_def, const PreActivationOrderServices&,
|
||||
api::orderman::OrderState&, api::orderman::OrderDefinition*) override;
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -1,172 +0,0 @@
|
||||
#include "TickOrder.h"
|
||||
|
||||
#include "lib/orderman/actors/order_manager/OrderBuilder.h"
|
||||
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include <google/protobuf/timestamp.pb.h>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
using namespace api::orderman;
|
||||
|
||||
struct TickOrder::PImpl {
|
||||
PImpl() {}
|
||||
|
||||
uint32_t tick_offset_on_deploy;
|
||||
spark::QuantityMeasure cross_threshold;
|
||||
uint32_t cross_ticks;
|
||||
uint32_t max_chase_ticks;
|
||||
bool detach_on_toward;
|
||||
|
||||
md::PriceSize opposite_at_inception;
|
||||
};
|
||||
|
||||
TickOrder::TickOrder() : me(new PImpl()) {}
|
||||
|
||||
TickOrder::~TickOrder() {}
|
||||
|
||||
void TickOrder::setup_child(const api::orderman::OrderDefinition &this_def,
|
||||
const PreActivationOrderServices &,
|
||||
api::orderman::OrderState &initial_state,
|
||||
api::orderman::OrderDefinition *out_child) {
|
||||
initial_state.mutable_tick();
|
||||
auto const &tick_def = this_def.custom_def().tick();
|
||||
*out_child->mutable_custom_def() = tick_def.child();
|
||||
|
||||
me->tick_offset_on_deploy = tick_def.tick_offset_on_deploy();
|
||||
me->cross_threshold = tick_def.cross_threshold();
|
||||
me->cross_ticks = tick_def.cross_ticks();
|
||||
me->max_chase_ticks = tick_def.max_chase_ticks();
|
||||
me->cross_threshold = tick_def.cross_threshold();
|
||||
me->detach_on_toward = tick_def.detach_on_toward();
|
||||
}
|
||||
|
||||
void TickOrder::payup(const md::PriceSize &opposite,
|
||||
const bts::orderman::BookUpdateEvent &,
|
||||
uint32_t cross_ticks) {
|
||||
double new_price = opposite.price() + tick_size() * cross_ticks;
|
||||
double limit =
|
||||
me->opposite_at_inception.price() + tick_size() * me->max_chase_ticks;
|
||||
if (new_price <= limit)
|
||||
update_child(Price(new_price), Quantity(this_state().quantity()));
|
||||
else {
|
||||
update_child(Price(limit), Quantity(this_state().quantity()));
|
||||
detach();
|
||||
}
|
||||
report_state();
|
||||
}
|
||||
|
||||
void TickOrder::paydown(const md::PriceSize &opposite,
|
||||
const bts::orderman::BookUpdateEvent &,
|
||||
uint32_t cross_ticks) {
|
||||
double new_price = opposite.price() - tick_size() * cross_ticks;
|
||||
double limit =
|
||||
me->opposite_at_inception.price() - tick_size() * me->max_chase_ticks;
|
||||
if (new_price >= limit)
|
||||
update_child(Price(new_price), Quantity(this_state().quantity()));
|
||||
else {
|
||||
update_child(Price(limit), Quantity(this_state().quantity()));
|
||||
detach();
|
||||
}
|
||||
report_state();
|
||||
}
|
||||
|
||||
void TickOrder::on_book_update(const bts::orderman::BookUpdateEvent &book) {
|
||||
switch (this_state().status()) {
|
||||
case ORDER_STATUS_WORKING:
|
||||
switch (child_state().status()) {
|
||||
case ORDER_STATUS_INACTIVE: {
|
||||
if (definition().side() == api::SIDE_BUY) {
|
||||
me->opposite_at_inception = book.book.side(api::Side::SIDE_SELL)[0];
|
||||
if (me->tick_offset_on_deploy > 0) {
|
||||
double price = me->opposite_at_inception.price() -
|
||||
tick_size() * me->tick_offset_on_deploy;
|
||||
activate_child(Price(price), Quantity(this_state().quantity()));
|
||||
transition(ORDER_STATUS_WORKING);
|
||||
} else {
|
||||
activate_child(Price(this_state().price()),
|
||||
Quantity(this_state().quantity()));
|
||||
transition(ORDER_STATUS_WORKING);
|
||||
}
|
||||
} else {
|
||||
me->opposite_at_inception = book.book.side(api::Side::SIDE_BUY)[0];
|
||||
if (me->tick_offset_on_deploy > 0) {
|
||||
double price = me->opposite_at_inception.price() +
|
||||
tick_size() * me->tick_offset_on_deploy;
|
||||
activate_child(Price(price), Quantity(this_state().quantity()));
|
||||
transition(ORDER_STATUS_WORKING);
|
||||
} else {
|
||||
activate_child(Price(this_state().price()),
|
||||
Quantity(this_state().quantity()));
|
||||
transition(ORDER_STATUS_WORKING);
|
||||
}
|
||||
}
|
||||
report_state();
|
||||
} break;
|
||||
case ORDER_STATUS_WORKING: {
|
||||
Quantity thresh = SpreaderUtils::_quantity_threshold(
|
||||
me->cross_threshold, Quantity(this_state().quantity()));
|
||||
if (definition().side() == api::SIDE_BUY) {
|
||||
const auto &opposite = book.book.side(api::Side::SIDE_SELL)[0];
|
||||
if (opposite.price() < me->opposite_at_inception.price()) {
|
||||
if (me->detach_on_toward)
|
||||
detach();
|
||||
else
|
||||
me->opposite_at_inception = opposite;
|
||||
} else if (opposite.price() > me->opposite_at_inception.price())
|
||||
payup(opposite, book, me->cross_ticks);
|
||||
else {
|
||||
if (opposite.size() <= thresh.value())
|
||||
payup(opposite, book, me->cross_ticks);
|
||||
}
|
||||
} else {
|
||||
const auto &opposite = book.book.side(api::Side::SIDE_BUY)[0];
|
||||
if (opposite.price() > me->opposite_at_inception.price()) {
|
||||
if (me->detach_on_toward)
|
||||
detach();
|
||||
else
|
||||
me->opposite_at_inception = opposite;
|
||||
} else if (opposite.price() < me->opposite_at_inception.price())
|
||||
paydown(opposite, book, me->cross_ticks);
|
||||
else {
|
||||
if (opposite.size() <= thresh.value())
|
||||
paydown(opposite, book, me->cross_ticks);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
break;
|
||||
|
||||
// child cannot be in any of these states if we are in the working state
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
case ORDER_STATUS_ERROR:
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/orderman/orders/book_algos/BookAlgo.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
class OrderStateUpdateEvent;
|
||||
class BookUpdateEvent;
|
||||
|
||||
//TickOrder deploys N ticks away from the initial opposite inside market and watches for it to trade below a certain size.
|
||||
//If that size goes below a threshold or the market moves away, TickOrder Pays up once.
|
||||
//The process repeats until the algo has paid up a max of N ticks from the original opposite inside order.
|
||||
//If the market moves toward, the algo either starts watching the new inside market and keeps going or detaches depending on a parameter
|
||||
|
||||
class TickOrder : public BookAlgo
|
||||
{
|
||||
public:
|
||||
TickOrder();
|
||||
virtual ~TickOrder();
|
||||
|
||||
protected:
|
||||
void setup_child(const api::orderman::OrderDefinition& this_def, const PreActivationOrderServices&,
|
||||
api::orderman::OrderState&, api::orderman::OrderDefinition*) override;
|
||||
void on_book_update(const bts::orderman::BookUpdateEvent&) override;
|
||||
private:
|
||||
void payup(const md::PriceSize& opposite, const bts::orderman::BookUpdateEvent&, uint32_t cross_ticks) override;
|
||||
void paydown(const md::PriceSize& opposite, const bts::orderman::BookUpdateEvent&, uint32_t cross_ticks) override;
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -65,6 +65,7 @@ HTTPStream::HTTPStream(const std::string& host, const std::string& path, const s
|
||||
HTTPStream::~HTTPStream() { }
|
||||
|
||||
|
||||
// returns true if file was downloaded
|
||||
bool download_file_if_newer(const string& host, const string& path, const string& destination) {
|
||||
struct stat st = boost::initialized_value;
|
||||
stat(destination.c_str(), &st);
|
||||
|
||||
+57
-18
@@ -1,8 +1,23 @@
|
||||
# BTS Spark SDK
|
||||
# BTS Spark
|
||||
|
||||
#### Getting Started
|
||||
Our offering consists of a client UI ([Spark Client](https://www.bluetradingsystems.com/bts-spark#ladder-algo-screen)), a high performance professional futures front end, connected via our proprietary protocol over TCP to our Spark Server, which in turn connects to execution venues via their native protocols (typically FIX/TCP for execution and some proprietary protocol over UDP multicast for market data).
|
||||
|
||||
## Docker
|
||||

|
||||
|
||||
|
||||
# BTS Spark Server SDK
|
||||
|
||||
This API extension point is intended for users that require adding functionality to our Spark Server. Using the **Spark Server SDK** users can create [new order types](https://github.com/BlueTradingSystems/spark_sdk/blob/master/examples/order_plugin_example.cpp), [new market data sources](https://github.com/BlueTradingSystems/spark_sdk/blob/master/examples/md_publisher_example.cpp) and soon new execution gateways. In this case users implement the new functionality in C++, producing a shared library that is loaded at run time by our Spark Server.
|
||||
|
||||
If you are interested in sending orders or otherwise controlling a spark server remotely please see the BTS [Spark Client SDK](https://github.com/BlueTradingSystems/spark_client_sdk) repo.
|
||||
|
||||
### In Depth
|
||||
|
||||
* [Spark Algo Descriptions](doc/algos.md)
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Docker
|
||||
|
||||
We use docker to provide a full dev environment with all the tools users need to develop their own algos.
|
||||
|
||||
@@ -35,7 +50,7 @@ $ docker start --attach -i bts_sdk
|
||||
|
||||
* If you prefer to run docker as a daemon, check out [``~/spark_sdk/sdk_shell.sh``](sdk_shell.sh)
|
||||
|
||||
## Git
|
||||
### Git
|
||||
|
||||
* We assume the git you are using is git-lfs compatible; if you're using the git that comes with our docker, you're all set.
|
||||
|
||||
@@ -50,7 +65,7 @@ $ cd spark_sdk
|
||||
```
|
||||
|
||||
|
||||
## Development
|
||||
### Development
|
||||
|
||||
Look at [examples/md_publisher_example.cpp](examples/md_publisher_example.cpp) to look at how to build a custom market data producer
|
||||
|
||||
@@ -62,10 +77,27 @@ run ```build_examples.sh``` to make sure you can build the examples, this will p
|
||||
$ cd ~/spark_sdk/examples
|
||||
$ ./build_examples.sh
|
||||
```
|
||||
#### Server Layout
|
||||
* Spark servers reside on a port, usually 8000, but your production instance could be on a different $PORT
|
||||
|
||||
##### SDK Package Layout
|
||||
* The sdk puts logs in ``~/sparkdata/data/logging/log``
|
||||
* The sdk package has binaries in ``spark_skd/lib``
|
||||
* Put plugins in ``spark_sdk/lib/plugins/`` for debugging
|
||||
|
||||
##### Production layout
|
||||
* Production Logs are in ``~/$PORT/sparkdata/data/logging/log`` on the host
|
||||
* Production binaries are in ``/sparkbin`` inside the docker container
|
||||
* Production algo plugins should go into the ``/sparkbin/plugins`` directory
|
||||
|
||||
#### Recorded market data
|
||||
* We first check for http://mdreplay/spark/futures.coconut
|
||||
|
||||
* Then fall back to ``./data_files/ relative to the sparkd binary``
|
||||
|
||||
## Debugging
|
||||
|
||||
Copy the order_plugin_example.so to ```spark_sdk/lib/plugins/``` and start the sparkd server process inside gdb
|
||||
Copy the order_plugin_example.so to ``spark_sdk/lib/plugins/`` and start the sparkd server process inside gdb
|
||||
```
|
||||
$ cp -f order_plugin_example.so ~/spark_sdk/lib/plugins/
|
||||
$ cd ~/spark_sdk/lib
|
||||
@@ -87,24 +119,31 @@ $ cp -f order_plugin_example.so ~/spark_sdk/lib/plugins/
|
||||
$ cd ~/spark_sdk/lib
|
||||
$ ./sparkd run
|
||||
```
|
||||
|
||||
## Connect to Admin (Risk) UI to set limits or add users
|
||||
* Browse to http://location:$PORT
|
||||
* Login as bts, no password
|
||||
* Add or manage user trading and market data permissions by clicking the Users icon on the left side
|
||||
* Add or manage accounts and risk limits by clicking on the Accounts icon on the left side
|
||||
|
||||
## Other interesting web accessible things
|
||||
|
||||
* When you have a running server you can:
|
||||
* Browse to http://location/$PORT/config to check configuration overrides
|
||||
* Browse to http://location:$PORT/perf_trace to see socket to socket latencies
|
||||
* Send us an email for help: api_support@bluetradesys.com
|
||||
|
||||
|
||||
## Connect Spark windows client
|
||||
|
||||
* To start a spark client, use the -ConfigServer parameter to point at this new server
|
||||
```
|
||||
> spark.exe -ConfigServer http://location/8000/config
|
||||
> spark.exe -ConfigServer http://location:$PORT/config
|
||||
```
|
||||
Or create a file called spark.conf at %APPDATA%\bts\conf\ that contains:
|
||||
```
|
||||
include: "http://location:8000/config/"
|
||||
include: "http://location:$PORT/config/"
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
* When you have a running server you can:
|
||||
* Browse to http://location/8000 to set risk limits and create users
|
||||
* Browse to http://location/8000/config to check configuration overrides
|
||||
* Browse to http://location/8000/perf_trace to see socket to socket latencies
|
||||
* Send us an email for help: api_support@bluetradesys.com
|
||||
|
||||
|
||||
|
||||
## Download the Spark windows client
|
||||
* Download the bts installer here:
|
||||
@@ -0,0 +1,40 @@
|
||||
# BTS Basic Algos
|
||||
|
||||
## Lean
|
||||
|
||||
The goal of the lean order is to watch the opposite-inside market size and cross when that sizegoes below the threshold (this also implies a cross if that size goes to zero and the markettrades away from you)If the market trades toward you, you can opt into several different behaviors
|
||||
|
||||
##### Parameters
|
||||
* Cross Thresh - size thresh in absolute or ratio terms
|
||||
* Max Chase Ticks - max levels to pay up, in ticks
|
||||
|
||||
|
||||
## Join
|
||||
The goal of the join order is to watch the opposite-inside market and join when the market flips (that is, when the best offer becomes the best bid) and has at least threshold size.
|
||||
|
||||
##### Parameters
|
||||
* Join Thresh - size thresh in absolute or ratio terms
|
||||
|
||||
|
||||
## Top
|
||||
|
||||
The goal of the top order is to not trade by yourself, but the intent at the time of order entry is toget filled.If the order is on the market (say current bid price) AND the quantity on that bid price is belowtop thresh then cancel the order else remain working.
|
||||
|
||||
##### Parameters
|
||||
* Top Thresh - size thresh in absolute or ratio terms
|
||||
|
||||
|
||||
## Cover
|
||||
A Cover order’s purpose is to fire a hedge order (of any type) in response to fills from it’s childorder on the opposite side of the market N ticks away
|
||||
|
||||
##### Parameters
|
||||
* Profit Ticks - ticks above or below fill price to place profit / cover order
|
||||
|
||||
|
||||
## OCO
|
||||
An OCO order creates a relationship between a child order and a 'stop' or 'other' order such that when one of these is cancelled, both cancel, or when one is filled, the other order's size is debited in the amount of the fill.
|
||||
|
||||
Composing this order with Cover simulates scalping functionality
|
||||
|
||||
##### Parameters
|
||||
* Stop Ticks - ticks below or above main order to place stop / other order
|
||||
@@ -358,7 +358,7 @@ DynamicOrderDescriptor get_dynamic_iceberg_order_desc() {
|
||||
DynamicOrderDescriptor desc;
|
||||
|
||||
// order type name
|
||||
desc.set_dynamic_order_type("DynamicIcebergOrder");
|
||||
desc.set_dynamic_order_type("dice");
|
||||
|
||||
// show size
|
||||
auto param = desc.add_param_desc();
|
||||
|
||||
@@ -25,6 +25,7 @@ ln -sf $1/server $1/sdk/lib
|
||||
|
||||
mkdir $1/sdk/examples
|
||||
cp $2/examples/* $1/sdk/examples
|
||||
cp $2/doc/* $1/sdk/doc
|
||||
cp $2/sdk_shell.sh $1/sdk/sdk_shell.sh
|
||||
cp $2/update_github.sh $1/sdk/update_github.sh
|
||||
cp $2/README.md $1/sdk/README.md
|
||||
|
||||
@@ -148,7 +148,7 @@ int start_exchange_sim()
|
||||
switch(conf.source_case()) {
|
||||
case config::ExchangeSim::SOURCE_NOT_SET:
|
||||
case config::ExchangeSim::kReplayUrl:
|
||||
md::replay_url(conf.replay_url(),
|
||||
md::replay_url_with_fallback(conf.replay_url(),
|
||||
player,
|
||||
config::get<md::RelayOptions>().naggle_ms());
|
||||
break;
|
||||
|
||||
@@ -58,9 +58,11 @@ void clean_dir(const std::string base_path) {
|
||||
}
|
||||
|
||||
void run_replay() {
|
||||
auto naggle_ms = config::get<RelayOptions>().naggle_ms();
|
||||
auto file = "http://mdreplay.bluetradesys.local/spark/futures.coconut";
|
||||
replay_recording(file, naggle_ms);
|
||||
auto naggle_ms = config::get<RelayOptions>().naggle_ms();
|
||||
const auto& options = config::get<ReplayOptions>();
|
||||
auto file = options.url();
|
||||
auto fallback_path = options.fallback();
|
||||
replay_recording(file, naggle_ms, fallback_path);
|
||||
}
|
||||
|
||||
void run_onixs() {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
- Set
|
||||
ExchangeSim {value {merge_with_md:false}}
|
||||
|
||||
in your spark.conf
|
||||
|
||||
- Use the order ticket to put in a 10 lot 55 dollar bid
|
||||
- Open up a ladder for SIM:CLZ9 and put in 10 lot offers at 55.10, 55.11, 55.12 and 1 lot bids at 54.99 and 54.98
|
||||
- Select OCO order from the menu.
|
||||
|
||||
-Set Stop Side to Same, Stop Type and Child type to Limit
|
||||
-Set Stop Ticks to -1
|
||||
-Put in a 1 lot bid at 54.93, you should see another 1 lot bid go in one tick worse
|
||||
-Move these orders independently (but don't get filled)
|
||||
-Cancel one order, the other should cancel
|
||||
-Check that an order goes in 1 tick better than where you click if you set the Stop Ticks to 1
|
||||
|
||||
|
||||
-Now set Stop Side to Opposite and Stop ticks to 3, send a 5 lot bid at 55.02
|
||||
-You should see a 5 lot buy go in at 55.02 and a 5 lot sell at 55.05.
|
||||
-Move the bid up to 55.03, the offer should not move
|
||||
-Move the offer up to 55.06, the bid should stay put
|
||||
- Cancel either the bid or the offer, the other will cancel. Set it up again and cancel the other side.
|
||||
|
||||
-Keep Stop Side at Opposite and Stop ticks to 3, send a 5 lot bid at 55.03
|
||||
-Switch to normal limit orders, send a 1 lot buy at 55.06. You should see a fill at 06 and the 5 lot bid at 03 should reduce to 4
|
||||
-Still with limit orders, send a 2 lot sell at 55.03. You should see a fill at 04 and the 4 lot offer at 06 should reduce to 2
|
||||
- (you might see the sell order have 1/2 in the badge. This means 1 fill / 2 total quantity, however I think this is a bug because we are working 2 still and that is correct)
|
||||
-Finally send a 2 lot buy (limit) at 55.06, you should see both the sell side OCO fill and the buy side OCO cancel
|
||||
-Flip this section around buy vs sell and make sure it does the same thing
|
||||
|
||||
Now compose a bracket order (extra credit if you make a template for it in the new guis)
|
||||
Select Cover
|
||||
Set Profit ticks to 1,
|
||||
Profit Order = OCO
|
||||
Child=Limit
|
||||
|
||||
For the OCO
|
||||
Stop Ticks = 3
|
||||
Stop Side = Same
|
||||
Stop Order = Trigger
|
||||
Child = Limit
|
||||
|
||||
Send in a buy of this order at 55.05
|
||||
Fill a 1 lot of this order at 55.05 (by putting in a Limit 55.05 sell)
|
||||
You should see a 1 lot sell order go in at 55.06 and a 1 lot sell trigger at 55.03
|
||||
Cancel one of those orders and the other should go away
|
||||
Reference in new issue
Block a user