Compare commits

..
Author SHA1 Message Date
Eric Harding cbd9d3c61f Add utility function to scan all unexpired securities 2020-01-17 13:33:24 -05:00
Pedro Pinto 48372f2189 Refactored Gateway/IVenue protocol to always generate orders 2020-01-08 16:02:58 -05:00
Pedro Pinto c9b60333f5 Added single message overload to reactor. 2020-01-02 15:48:55 -05:00
Pedro Pinto ccca656b88 Merged 2020-01-02 15:21:33 -05:00
Eric Harding f5ae6559ee Add default_venue_observer so I don't need a nullptr 2019-12-31 11:40:26 -05:00
Eric Harding 917c3ee909 Update SecureLogon for ilink3 2019-12-30 16:49:58 -05:00
Pedro Pinto bf8369fca8 FIX Venue 2019-12-26 11:49:02 -05:00
Eric Harding 25866533ea Generated ilink message code 2019-12-24 13:09:43 -05:00
Eric Harding 4306ac0737 Fix build 2019-12-24 12:56:36 -05:00
Pedro Pinto 874f655b55 Revised IVenue, IConnectionController to handle failover and checkpoints 2019-12-20 17:32:20 -05:00
Pedro Pinto 17c7a631f9 FIX. 2019-12-20 14:00:16 -05:00
Pedro Pinto 0a98fd7fed FIX Venue. 2019-12-20 08:33:57 -05:00
Pedro Pinto d82855aec2 Gateway. 2019-12-18 17:33:20 -05:00
Pedro Pinto 516c9c0d84 Started working on networking. 2019-12-11 10:39:27 -05:00
Pedro Pinto 1bfdeeded4 Gateway refactor. 2019-12-09 14:18:42 -05:00
Pedro Pinto 929c19f4b2 Gateway work. 2019-12-05 09:57:42 -05:00
Pedro Pinto 70e58edacb More gateway work. 2019-12-04 18:11:25 -05:00
Pedro Pinto 26702a1a7e Changed compile time calculation of tag str/tag crc to use contexpr
This is much simpler than the template mess it replaces.
2019-11-24 21:39:17 -05:00
Pedro Pinto 71db591365 Working on gateway. 2019-11-23 14:07:30 -05:00
Pedro Pinto a8d013d054 Changed bts_assert to bts_assert_d in performance sensitive code. 2019-11-23 14:05:57 -05:00
Pedro Pinto 3179f2647f Changed OM<->GW protocol 2019-11-21 11:14:12 -05:00
Pedro Pinto 91020c2ccc Wiring complete 2019-11-15 09:03:51 -05:00
Pedro Pinto 404104e12b Cleaner syntax, more wiring complete. 2019-11-14 14:40:07 -05:00
Pedro Pinto a4145e6bd5 Interconnect done. 2019-11-13 14:47:38 -05:00
Pedro Pinto 425cd6e6a0 New approach to signals/slots 2019-11-13 08:40:21 -05:00
Pedro Pinto c21735ad92 Work on orchestration. 2019-11-08 12:48:17 -05:00
Pedro Pinto 2f4708eaf5 Added some benchmarks, fixed build. 2019-11-08 12:19:52 -05:00
Pedro Pinto 062e28bf5d Removed logging in hot path. 2019-10-11 11:26:38 -04:00
Pedro Pinto a2754bc2f5 Removed logging from polling loop. 2019-10-11 11:26:26 -04:00
Pedro Pinto 6638a89abe Dropped call to config from the hot path. 2019-10-11 11:21:06 -04:00
Pedro Pinto a11979f1a2 Cosmetic fix in jetfix.proto 2019-10-11 11:20:08 -04:00
Pedro Pinto 7a04547b8d Removed obsolete code. 2019-10-01 15:17:26 -04:00
Pedro Pinto d4ebfcb5a2 Clang format. 2019-10-01 14:47:00 -04:00
Pedro Pinto 4ac3b77030 Removed unused code. 2019-09-27 17:11:49 -04:00
Pedro Pinto 5e9bd1729b Ran clang format. 2019-09-27 15:25:21 -04:00
Pedro Pinto 14f6e7646a Ran clang format. 2019-09-27 14:46:19 -04:00
Pedro Pinto e8281dc5a0 Fixed perflog build reporting type (it was always reporting release) 2019-09-26 13:30:31 -04:00
Pedro Pinto d3efd1215f Merge branch 'ice_exec3' into SP-231-improve-order-manager-performance 2019-09-26 10:09:06 -04:00
Pedro Pinto a5ac746a9d Added another benchmark 2019-09-24 16:04:39 -04:00
Kevin Darby a39d91ceb3 Merge branch 'pnl-rounding-error' of bitbucket.org:bluetradesys/spark into ice_exec3 2019-09-24 14:38:26 -04:00
John Colvin ddc50e1fba pnl initial calc type was not being applied to data 2019-09-24 13:32:54 -05:00
John Colvin ffb571d1cf fix pnl rounding issues (use 9 decimal places) 2019-09-24 13:32:53 -05:00
John Colvin 2a36c05d75 fix PNLRowData Equals impl (was not comparing market prices) 2019-09-24 13:32:53 -05:00
John Colvin a3730eb203 Update.naggle merge maintains changes (could get into state where changes became adds/removes) 2019-09-24 13:32:53 -05:00
John Colvin d033275694 remove unused member OrdersModel.on_account_pnl 2019-09-24 13:32:53 -05:00
Jake Norbut 016ddf9b69 fixing pay less definition 2019-09-24 08:21:56 -05:00
Pedro Pinto 578d8678d0 Updated subrepo ptrs 2019-09-24 09:02:08 -04:00
Pedro Pinto 7e7b96be22 Merge branch 'master' into SP-231-improve-order-manager-performance 2019-09-24 09:01:37 -04:00
Pedro Pinto 26dd802e6a Merge branch 'ice_exec3' into SP-231-improve-order-manager-performance 2019-09-24 09:01:14 -04:00
Pedro Pinto 129a0fe3ca Merged faster_orderman 2019-09-24 09:01:05 -04:00
Pedro Pinto 2c95cb6905 Fixed doc typo 2019-09-24 08:43:32 -04:00
John Colvin 0cc5817932 expand synthetic leg columns to fit name 2019-09-24 01:04:28 -05:00
Michael Harding 032836dea4 Test updates 2019-09-23 15:54:33 -04:00
Kevin Darby a06461eb5e Merge branch 'master' of bitbucket.org:bluetradesys/spark into ice_exec3 2019-09-23 13:58:22 -04:00
Kevin Darby 34e7d6a617 remove ice bust handling 2019-09-23 13:57:43 -04:00
Kevin Darby 276e9ad0ef Merged in fix_expired_fill_crash (pull request #358)
Fix expired fill crash
2019-09-23 17:50:02 +00:00
Pedro Pinto 5968ac10d2 The fix is right, but the code was a bit clumsy. 2019-09-23 13:48:26 -04:00
Kevin Darby 31e44d8c10 Merge branch 'master' of bitbucket.org:bluetradesys/spark into ice_exec3 2019-09-23 13:03:20 -04:00
John Colvin 9bf7666c30 downgrade pnl rounding error Log assert to warning 2019-09-23 11:56:57 -05:00
Kevin Darby 8fdab4a510 note about expired securities in sod tests 2019-09-23 12:47:48 -04:00
Kevin Darby 385adaa1b0 Merge branch 'fix_expired_fill_crash' of bitbucket.org:bluetradesys/spark into ice_exec3 2019-09-23 12:36:16 -04:00
Kevin Darby f9506bc9ad Merge branch 'master' of bitbucket.org:bluetradesys/spark into ice_exec3 2019-09-23 12:36:00 -04:00
Kevin Darby b9fd0e2e28 in SIM you can trade an expired security and if we leave it out of this map
we will later attempt to add this fill twice while testing SOD because the test
asks to delete the fills db
2019-09-23 12:31:03 -04:00
Kevin Darby 6b5b517d70 slight nit in GLBXExecutionGateway 2019-09-23 12:29:38 -04:00
Pedro Pinto 61f0851c3f Merged ice_exec3 2019-09-23 08:40:55 -04:00
Pedro Pinto 5e6dea91f3 Tech doc 2019-09-23 08:39:24 -04:00
Pedro Pinto ec1d925dbe Added to .gitignore 2019-09-22 08:25:10 -04:00
Kevin Darby 96bec55ee7 fix build, we will have to handle these ice cpps someplace else 2019-09-20 15:01:56 -04:00
Kevin Darby 424bb36fc7 update jakes script for ice cpps 2019-09-20 14:30:27 -04:00
Kevin Darby c24700195f fixed cpp coming from market data for ice, added the obligatory overrides 2019-09-20 14:15:27 -04:00
Jake Norbut f7184b0949 updating tests 2019-09-20 09:13:01 -05:00
John Colvin 633ebf38a2 restore original ComboBox default padding on the left 2019-09-19 18:58:19 -05:00
John Colvin 1eb8352b6b OrdersModel blocks GlbxIceberg orders from going out to non-glbx exchange 2019-09-19 17:21:48 -05:00
John Colvin 33c201b395 remove unused SparkTag.CreateOrder 2019-09-19 17:21:17 -05:00
Pedro Pinto 0c91672317 Better docs for orderman 2019-09-19 14:54:29 -04:00
Kevin Darby 34fc6af137 fix mview test 2019-09-19 14:17:53 -04:00
Kevin Darby 6cc25a7337 Merge branch 'master' of bitbucket.org:bluetradesys/spark into ice_exec3 2019-09-19 13:56:32 -04:00
Kevin Darby 0c9a9fcb5e git lfs 2019-09-19 13:56:01 -04:00
Kevin Darby 48b62f1cab new externals 2019-09-19 13:40:01 -04:00
Kevin Darby 5a0ceafa66 Merge branch 'master' of bitbucket.org:bluetradesys/spark into ice_exec3 2019-09-19 13:28:31 -04:00
Kevin Darby d31969606e Merge branch 'master' of bitbucket.org:bluetradesys/spark into ice_exec3 2019-09-19 13:27:52 -04:00
Kevin Darby 6c6fb74506 Merged in minimal_api_tests (pull request #348)
RTM. Minimal api tests

Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-09-19 17:26:14 +00:00
Pedro Pinto a69ed30e70 Updated release notes. 2019-09-19 13:19:52 -04:00
Eric Harding a654f302a2 Merged in SP-106-md-crashy (pull request #351)
SP-106 md crashy
2019-09-19 17:10:35 +00:00
John Colvin 9ca3285888 miniob 'CheckColumn' is visible 2019-09-19 11:56:47 -05:00
Eric Harding df4c3b9376 Merge branch 'master' of bitbucket.org:bluetradesys/spark into SP-106-md-crashy 2019-09-19 09:11:10 -04:00
Pedro Pinto f21c9f96d1 Merged from prod 2019-09-18 16:25:35 -04:00
Pedro Pinto 16a71a9f63 Updated release notes. 2019-09-18 16:24:09 -04:00
Kevin Darby facb3249d0 Merge branch 'minimal_api_tests' of bitbucket.org:bluetradesys/spark into ice_exec3 2019-09-18 15:24:51 -04:00
Kevin Darby f323efc61a Merge branch 'master' of bitbucket.org:bluetradesys/spark into ice_exec3 2019-09-18 15:24:14 -04:00
Kevin Darby a8689aee06 verified client api examples work 2019-09-18 15:13:53 -04:00
Kevin Darby 85b2d257a7 updated the example excel sheet, added some manual tests to vet api docs and excel 2019-09-18 14:57:40 -04:00
Michael Harding f49ca9f7bd Merged in system-tests (pull request #347)
System tests
2019-09-18 18:39:11 +00:00
Eric Harding 297233eae6 Clientbuild probably needs this too 2019-09-18 13:28:00 -04:00
Eric Harding 0114dd0276 SP-106 MDConsumerHandle crash both managed+native 2019-09-18 12:58:15 -04:00
Eric Harding ffd35aebac Enable btree_map.h on windows 2019-09-18 09:52:41 -04:00
Pedro Pinto b92fed4f47 Merged from prod 2019-09-17 16:59:03 -04:00
Pedro Pinto e62fe88f1a Deleted unused file. 2019-09-12 15:23:51 -04:00
Pedro Pinto 14993973ff Minor refactoring. 2019-09-12 15:17:21 -04:00
Pedro Pinto 7e84e688b7 Improved OrderManager documentation. 2019-09-12 14:26:53 -04:00
Eric Harding 98dd396687 SP-214 add doc comment for on_status 2019-09-12 14:26:32 -04:00
Eric Harding eea3bc1d8b SP-214 simplify trading status for synthetic logic 2019-09-12 14:26:32 -04:00
Eric Harding 9e2f72b26e SP-214 attempt to simplify calling securityTradingStatus 2019-09-12 14:26:32 -04:00
Eric Harding 1137b0daf8 SP-214 Missed initialization of EventStream 2019-09-12 14:26:32 -04:00
Eric Harding d60720208d SP-214 Wire StatusEvent to IAlgoOrder/IAlgoServices 2019-09-12 14:26:32 -04:00
Eric Harding 780633e639 SP-214 add status to MDSource.h 2019-09-12 14:26:32 -04:00
Eric Harding 7168a4b54c SP-214 Expose trading_status on MDConsumer. 2019-09-12 14:26:32 -04:00
Eric Harding b5e85ac873 SP-214 map cme status to co2 status 2019-09-12 14:26:32 -04:00
Eric Harding a5a5d56228 Write exchange_status MDP3 2019-09-12 14:26:32 -04:00
276 changed files with 139155 additions and 966 deletions

No files matched your search

+1
View File
@@ -33,3 +33,4 @@ trace_data/
/src/lib/orderman/perf_analysis/log.csv
/doc/user/public/*
.ionide/*
/.ignore
+1 -1
View File
@@ -40,7 +40,7 @@ else ()
-fPIC -Wall -pedantic -Wextra -Werror \
-Wno-missing-braces -Wno-ignored-qualifiers \
--std=c++17 -fdiagnostics-color")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -DNDEBUG -O3")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -DNDEBUG -O3")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wno-undef")
add_subdirectory(src/server/sparkd)
add_subdirectory(src/lib)
@@ -154,7 +154,7 @@ insert_anchor_links = "right"
- Pay Less - If enabled by checking the checkbox, the spreader will
attempt to pay less when the quantity at the level of the calculated
hedge price is more than the threshold defined.  The hedge order is
hedge price is less than the threshold defined.  The hedge order is
paid less by the “Payless Ticks” as defined per leg.
- Pay Up - If enabled by checking the checkbox, the spreader will pay
up when the quantity at the level of the calculated hedge price is
+6 -2
View File
@@ -10,13 +10,17 @@ insert_anchor_links = "right"
- A new, more powerful PnL form is now available
### API Changes
- Added security state information (pre open, halted, normal, closed, etc)
### Bug Fixes
- Brought back the "select all" check box in the mini order book
- Fixed an issue in the market data subsystem that on rare occasions could result in a startup crash
### Internal Changes
- Fixed an issue that was stopping us from interpreting SOD times as local rather than GMT
## 2.9.3
### Internal Changes
- Fixed system test scripts
## 2.9.2
### Bug Fixes
- Fixed an issue with the exchange simulator that could lead to crossed markets
## 2.9.1
### Bug Fixes
- Fixed an issue with trade sound alerts, where in some cases the use of a "In Between" condition could lead to a UI failure.
@@ -227,7 +227,7 @@ namespace bts.shell {
public string strip_name;
[ProtoMember(26)]
public string last_price_from_spread;
[ProtoMember(27)]
[ProtoMember(28)]
public string mic_code;
}
@@ -227,7 +227,7 @@ namespace mbts.ui.spark {
}
DataGridColumn _column_factory(LegSpreaderParamsTuple l) {
var col = new DataGridColumnInternal(l.leg.Security, ParameterCellTemplateConverter, ParameterCellEditingTemplateConverter) { Width = 75, };
var col = new DataGridColumnInternal(l.leg.Security, ParameterCellTemplateConverter, ParameterCellEditingTemplateConverter);
col.HeaderTemplate = (DataTemplate)FindResource(IsNew ? RemovableColumnHeaderTemplateKey : NonRemovableColumnHeaderTemplateKey);
DataGridEx.SetRightBorder(col, new DataGridExVerticalLine(false, true, Colors.DarkGray, 1));
return col;
@@ -75,7 +75,7 @@ namespace bts.shell.fills {
[DIYGridColumnID(nameof(Columns.Symbol))]
public string[] symbol { get; set; }
[ProtoMember(16)]
[ProtoMember(17)]
[DIYGridColumnID(nameof(Columns.FillStatus))]
public Fill.Types.FillStatus[] fill_status { get; set; }
}
@@ -451,7 +451,7 @@ namespace mbts.spark {
price = temp_price;
}
}
await _model.order_gateway.send_order(order, price, size);
await _model.order_gateway.send_order(security, order, price, size);
if (auto_clear)
size_calculator.value = 0;
var fav_algo = order_properties_vm.selected_favorite_algo_definition;
@@ -750,6 +750,7 @@ namespace mbts.spark {
};
header_cb.SetBinding(CheckBox.IsCheckedProperty, new Binding(nameof(OrderBookVM.all_rows_selected)));
this.Header = header_cb;
is_visible = true;
}
public override FrameworkElement view_factory() {
@@ -288,7 +288,14 @@ namespace mbts.spark {
double price = attach_vm.price;
uint? size = attach_vm.size;
uint algo_template_key = attach_vm.algo_vm.algo_root.id.is_persisted ? attach_vm.algo_vm.algo_root.id.persisted : 0u;
var order_tups = selected_rows.Select(r => r.order_tuple).ToList();
// Don't pass any order tuples that don't have a security defined.
// The actual security is passed to the OrdersModel - instead of just the security key -
// so it can prevent GlbxIceberg orders from being sent to a non-glbx exchange (such as Ice).
/// Impl details: <see cref="OrdersModel.send_order(SecurityImmutable, OrderDefinitionImmutable?, double, uint)"/>
var order_tups = selected_rows
.Select(r => r.order_tuple)
.Where(ot => ot.order.security.HasValue)
.ToList();
var mod_algo_vm = attach_vm.algo_vm.algo_root;
await Task.WhenAll(order_tups.Select(t => {
var algo = t.order.order.Def.CustomDef.actual().CloneToMutable();
@@ -302,6 +309,7 @@ namespace mbts.spark {
};
}
return _model.send_order(
t.order.security.Value,
t.order.order.Def.with(
attach_target_order_key: t.order.order.Key,
custom_def: algo
@@ -501,6 +501,12 @@ namespace bts.shell.pnl {
account_name == other.account_name &&
sod == other.sod &&
day == other.day &&
bid_price.Equals(other.bid_price) &&
ask_price.Equals(other.ask_price) &&
last_price.Equals(other.last_price) &&
mid_price.Equals(other.mid_price) &&
settlement_price.Equals(other.settlement_price) &&
calc_type.Equals(other.calc_type) &&
raw_day == other.raw_day &&
working.summary == other.working.summary;
@@ -97,22 +97,22 @@ namespace bts.shell.pnl {
if (security.HasValue && security.Value.ContractCase != Security.ContractOneofCase.Future) {
day_long = day_short = sod_long = sod_short = 0;
} else {
day_long = (decimal)DoubleUtil.nan_to_zero(data.day.long_pos);
day_short = (decimal)DoubleUtil.nan_to_zero(data.day.short_pos);
sod_long = (decimal)DoubleUtil.nan_to_zero(data.sod.long_pos);
sod_short = (decimal)DoubleUtil.nan_to_zero(data.sod.short_pos);
day_long = DoubleUtil.round_to_decimal(data.day.long_pos);
day_short = DoubleUtil.round_to_decimal(data.day.short_pos);
sod_long = DoubleUtil.round_to_decimal(data.sod.long_pos);
sod_short = DoubleUtil.round_to_decimal(data.sod.short_pos);
}
var nd = new PNLNormalizedData(
(decimal)DoubleUtil.nan_to_zero(day_pnl.value),
DoubleUtil.round_to_decimal(day_pnl.value),
day_long,
day_short,
(decimal)DoubleUtil.nan_to_zero(data.raw_day.long_pos),
(decimal)DoubleUtil.nan_to_zero(data.raw_day.short_pos),
(decimal)DoubleUtil.nan_to_zero(sod_pnl.value),
DoubleUtil.round_to_decimal(data.raw_day.long_pos),
DoubleUtil.round_to_decimal(data.raw_day.short_pos),
DoubleUtil.round_to_decimal(sod_pnl.value),
sod_long,
sod_short,
(decimal)DoubleUtil.nan_to_zero(data.working_long_pos),
(decimal)DoubleUtil.nan_to_zero(data.working_short_pos));
DoubleUtil.round_to_decimal(data.working_long_pos),
DoubleUtil.round_to_decimal(data.working_short_pos));
if (_normalized_data != nd) {
_normalized_data = nd;
updated?.Invoke(nd);
@@ -103,7 +103,7 @@ namespace bts.shell.pnl {
load_from(settings);
_dispose = Disposable.Create(
pnl_source.Operate(
_calculation_type.observe_current(),
_calculation_type.observe_current(true),
(data, calc) => data.with(calc_type: calc)
).FilterWithRaw(filter_src, PNLRowData.key_fn, null)
.OnDispatcher()
@@ -373,7 +373,9 @@ namespace bts.shell.pnl {
var less_last = data - last_data;
var plus_new = less_last + new_data;
data += new_data - last_data;
Log.assert(plus_new == data);
if (plus_new != data) {
Log.Ui.warn($"Detected PNL arithmetic rounding error in the group sum for '{string.Join(" ", GroupNamePath)}' (this bug is under investigation).");
}
last_data = new_data;
}
void on_is_selected_changed(bool is_selected) {
+1 -1
View File
@@ -53,7 +53,7 @@ namespace mbts.spark {
send_order = new DelegateCommand<Side>(side => {
bool price_valid = _validate_price(), size_valid = size_calculator.validate();
if (price_valid && size_valid && !HasErrors && !properties_vm.HasErrors) {
model.send_order(properties_vm.create(side), price, size_calculator.value.Value).ignore();
model.send_order(security, properties_vm.create(side), price, size_calculator.value.Value).ignore();
RequestClose?.Invoke(this, new EventArgs());
}
});
+7
View File
@@ -200,6 +200,13 @@ namespace mbts.spark {
public static string short_description(this OrderRecordImmutable order, ContractSpecificationImmutable? spec) =>
$"{(order.HasDef ? order.Def.Side.ToString() : "(unknown-side)")} {(order.HasState ? ($@"{spec.format(order.State.Price)} @ {order.State.Quantity}") : "(unknown-price) @ (unknown-quantity)")}";
public static string short_description(SecurityImmutable security, Side side, double price, uint quantity) =>
new StringBuilderEx(
security.ToString(), " ",
side.ToString(), " ",
price_quantity_description(price, quantity, security.spec_or_default())
).ToString();
public static string short_description(this OrderRecordImmutable order, SecurityImmutable? security) {
var spec = security.spec_or_default();
return new StringBuilderEx(
+25 -8
View File
@@ -75,7 +75,6 @@ namespace mbts.spark {
.TableCheckedAutoCorrect(EqualityComparer<(SecurityImmutable? sec, PNLUnitImmutable data)>.Default)
.Where(t => t.has_changes())
.Cache();
on_account_pnl = _position_service.subscribei_pnl_account_data().Naggle(interval, scheduler).Table().Cache();
var working_orders = on_orders.Filter(tup => tup.order.is_active());
this.working_orders =
on_orders.Scan(
@@ -241,7 +240,6 @@ namespace mbts.spark {
.Filter(os => os.order.is_active() && os.order.State.DisplayStatus == OrderState.Types.DisplayStatus.Visible, key => key.order.Key)
.Subscribe(_security_working_orders_with_piq_demuxer),
on_positions.Subscribe(_security_positions_demuxer),
_bus.subscribe(SparkTags.CreateOrder).Subscribe(a => send_order(a.definition, a.price, a.size).ignore()),
_bus.subscribe(SparkTags.RecreateOrder).Subscribe(a => a.ForEach(x => send_order(x.definition, x.price, x.size).ignore())),
_bus.subscribe(SparkTags.CancelOrders).Subscribe(x => cancel_orders(x).ignore()),
_bus.subscribe(SparkTags.DetachOrders).Subscribe(x => detach_orders(x).ignore()),
@@ -266,7 +264,6 @@ namespace mbts.spark {
public IObservable<IReadOnlyDictionary<uint, OrderSecurity>> working_orders { get; }
public IObservable<TableUpdate<(SecurityImmutable?, PNLUnitImmutable), int>> on_pnl { get; }
public IObservable<TableUpdate<PNLRowData, PNLKey>> security_account_pnl { get; }
public IObservable<TableUpdate<AccountPNLImmutable, uint>> on_account_pnl { get; }
public IObservable<TableUpdate<(SecurityImmutable?, PositionUnitImmutable), int>> on_positions { get; }
public IObservable<TableUpdate<(AlgoData algo, AlgoDefinitionMetadata? meta), AlgoKey>> studio_algos_with_meta { get; }
public IObservable<TableUpdate<(SecurityImmutable?, ManualFillImmutable), int>> on_manual_fills_securities { get; }
@@ -287,13 +284,33 @@ namespace mbts.spark {
#endregion
#region Input
public async Task<uint?> send_order(OrderDefinitionImmutable? order, double price, uint size) {
// the security arg is needed for a temporary hack to prevent GlbxIceberg orders from going out in non-glbx exchanges (like Ice)
// eventually, we'll need an algo type model to handle this stuff.
// This hack leverages the fact that every place that calls 'send_order' already has the security handy (not just the sec id).
public Task<uint?> send_order(SecurityImmutable security, OrderDefinitionImmutable? order, double price, uint size) {
if (order.HasValue) {
var result = (await send_order_get_error(order.Value, price, size));
_activity.on_send_order(order.Value, price, size, result.key, result.error);
return result.key;
#if DEBUG
if (security.Exchange != Venue.Glbx && security.Exchange != Venue.Sim) {
#else
if (security.Exchange != Venue.Glbx) {
#endif
var algo_structure = OrderDataHelper.enumerate_algo_structure(order.Value.CustomDef);
if (algo_structure.Any(t => t.type == CustomOrderDefinition.CustomOneofCase.GlbxIceberg)) {
Log.Ui.info($"OrdersModel prevented a GlbxIceberg order from going out to a non-glbx exchange ({OrderUtils.short_description(security, order.Value.Side, price, size)}).");
return Task.FromResult<uint?>(null);
}
}
return send_order(order.Value, price, size);
}
return 0;
return Task.FromResult<uint?>(null);
}
/// Note: this method is private to force outside callers to use this overload <see cref="send_order(SecurityImmutable, OrderDefinitionImmutable?, double, uint)"/>.
/// This allows us to control which orders can be sent to which security/exchange (e.g., GlbxIceberg orders are only permitted for securities on the Glbx exchange).
async Task<uint?> send_order(OrderDefinitionImmutable order, double price, uint size) {
var result = (await send_order_get_error(order, price, size));
_activity.on_send_order(order, price, size, result.key, result.error);
return result.key;
}
async Task<(uint? key, string error)> send_order_get_error(OrderDefinitionImmutable order, double price, uint size) {
+1 -1
View File
@@ -339,7 +339,7 @@
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="Padding" Value="3,3,1,3"/>
<Setter Property="Padding" Value="6,3,1,3"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
-1
View File
@@ -17,7 +17,6 @@ namespace mbts.spark {
#endregion
#region Order
public static ITag<(OrderDefinitionImmutable definition, double price, uint size)> CreateOrder { get; } = new SparkTag<(OrderDefinitionImmutable, double, uint)>();
public static ITag<IEnumerable<(OrderDefinitionImmutable definition, double price, uint size)>> RecreateOrder { get; } = new SparkTag<IEnumerable<(OrderDefinitionImmutable, double, uint)>>();
public static ITag<IEnumerable<uint>> CancelOrders { get; } = new SparkTag<IEnumerable<uint>>();
@@ -1,10 +1,9 @@
using System;
using System.Linq;
namespace mbts.ui.controls
{
internal class DoubleUtil
{
namespace mbts.ui.controls {
static class DoubleUtil {
public const int API_DECIMAL_PRECISION = 9;
/* smallest such that 1.0+DBL_EPSILON != 1.0 */
private const double EPSILON = 2.2204460492503131e-016;
private const double BIG_EPSILON = EPSILON * 10;
@@ -36,6 +35,9 @@ namespace mbts.ui.controls
(double.IsNaN(right) ? double.NaN : -right) :
(double.IsNaN(right) ? left : left - right);
public static decimal round_to_decimal(double value, int decimals = API_DECIMAL_PRECISION) =>
double.IsNaN(value) ? 0 : (decimal)Math.Round(value, decimals, MidpointRounding.AwayFromZero);
internal static bool AreClose(double v1, double v2) {
if (v1 == v2) return true;
double delta = Math.Abs(v1 - v2);
+54 -45
View File
@@ -8,7 +8,6 @@ using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
namespace bts.api.core {
@@ -94,38 +93,38 @@ namespace bts.api.core {
new Update<T, TKey>(new T[0], new T[0], new Change<T>[0], new T[0], key_extractor);
public Update<T,TKey> merge(Update<T, TKey> next) {
var comp = new RowEqualityComparer<T, TKey>(_key);
var added = this.added as HashSet<T> ?? new HashSet<T>(this.added, comp);
var added = this.added as KeyedValueSet<TKey, T> ?? new KeyedValueSet<TKey, T>(this.added, _key);
var changes = this.changed as ChangeDict<T,TKey> ?? new ChangeDict<T,TKey>(this.changes, _key);
var removed = this.removed as HashSet<T> ?? new HashSet<T>(this.removed, comp);
var removed = this.removed as KeyedValueSet<TKey, T> ?? new KeyedValueSet<TKey, T>(this.removed, _key);
// Add
added.UnionWith(next.added);
foreach (var v in next.added) {
var k = _key(v);
if (removed.TryPop(k, out var oldval)) {
changes.AddOrMerge(new Change<T>(oldval, v));
} else {
added[k] = v;
}
}
// Change
foreach (var c in next.changes) {
if (added.Contains(c.Old)) {
added.Remove(c.Old);
added.Add(c.New);
}
else {
var k = _key(c.Old);
if (!added.TryReplace(k, c.New))
changes.AddOrMerge(c);
}
}
// Remove
foreach (var r in next.removed) {
if (!added.Remove(r)) {
removed.Add(r);
}
changes.Remove(_key(r));
var k = _key(r);
if (!added.Remove(k))
removed[k] = changes.TryRemove(k, out var ch) ? ch.Old : r;
}
return new Update<T, TKey>(
next.all,
added, changes, removed,
_key
);
_key);
}
public IEnumerable<T> all { get; }
@@ -148,6 +147,39 @@ namespace bts.api.core {
#endif
}
class KeyedValueSet<TKey, TValue> : IEnumerable<TValue> {
readonly Dictionary<TKey, TValue> _cache = new Dictionary<TKey, TValue>();
public KeyedValueSet(IEnumerable<TValue> value, Func<TValue, TKey> key) {
foreach (var v in value)
_cache[key(v)] = v;
}
public TValue this[TKey key] {
set => _cache[key] = value;
}
public bool Remove(TKey key) =>
_cache.Remove(key);
public bool TryPop(TKey key, out TValue value) =>
_cache.TryGetValue(key, out value) && _cache.Remove(key);
public bool TryReplace(TKey key, TValue value) {
if (_cache.ContainsKey(key)) {
_cache[key] = value;
return true;
}
return false;
}
public IEnumerator<TValue> GetEnumerator() =>
_cache.Values.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() =>
GetEnumerator();
}
class ChangeDict<T, TKey> : IEnumerable<Change<T>> {
Dictionary<TKey, Change<T>> _changes;
Func<Change<T>, TKey> _key;
@@ -167,9 +199,11 @@ namespace bts.api.core {
return null;
}
public void Remove(TKey key) {
public bool Remove(TKey key) =>
_changes.Remove(key);
}
public bool TryRemove(TKey key, out Change<T> result) =>
_changes.TryGetValue(key, out result) && _changes.Remove(key);
#region IEnumerable
public IEnumerator<Change<T>> GetEnumerator() {
@@ -181,31 +215,6 @@ namespace bts.api.core {
#endregion
}
struct RowEqualityComparer<T,TKey> : IEqualityComparer<T>, IEqualityComparer<Change<T>>
where TKey : IEquatable<TKey> {
readonly Func<T,TKey> _key;
public RowEqualityComparer(Func<T,TKey> key) {
_key = key;
}
public bool Equals(T x, T y) {
return _key(x).Equals(_key(y));
}
public bool Equals(Change<T> x, Change<T> y) {
return Equals(x.New, y.New);
}
public int GetHashCode(T obj) {
return _key(obj).GetHashCode();
}
public int GetHashCode(Change<T> c) {
return GetHashCode(c.New);
}
}
public class TableUpdate<T, TKey> where TKey : IEquatable<TKey> {
// warning: this does not have a key_extractor
public static readonly TableUpdate<T, TKey> empty = new TableUpdate<T, TKey>(ImmutableDictionary<TKey, T>.Empty, Array.Empty<T>(), Array.Empty<Change<T>>(), Array.Empty<T>(), null);
@@ -922,4 +931,4 @@ namespace bts.api.core {
$"T is '{typeof(T)}', TKey is '{typeof(TKey)}'";
}
}
}
}
+2
View File
@@ -36,6 +36,7 @@ namespace bts {
Plugin,
ClientSdk,
Http,
OrderMan2,
// Please keep this list in sync with logging.h/logging.cpp
}
@@ -105,6 +106,7 @@ namespace bts {
internal static Logger DataFlow => new Logger(Subsystem.DataFlow);
public static Logger ClientSdk => new Logger(Subsystem.ClientSdk);
public static Logger Http => new Logger(Subsystem.Http);
public static Logger OrderMan2 => new Logger(Subsystem.OrderMan2);
internal static void log_at(this Logger logger, Level level, string message) {
switch (level) {
+1 -1
View File
@@ -62,7 +62,7 @@
</ItemGroup>
<ItemGroup>
<None Include="spark_excel_example_2018.xlsm"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></None>
<None Include="spark_excel_example_2019.xlsm"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></None>
</ItemGroup>
<!-- <Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
Binary file not shown.
+21 -11
View File
@@ -62,35 +62,45 @@ include: "http://location:8000/config/"
* Make sure you can connect to a running server
* run spark_sdk.exe with no parameters to see help
```
spark_sdk\bin\Debug\net471> spark_sdk.exe
spark_sdk\bin\Debug\net471> spark_sdk.exe -ConfigServer http://location:8000/config
BTS Spark SDK
Usages: spark_sdk [command] [arguments]
Commands:
md <exchange> <security_type> <symbol> [<security_desc>]
ui <exchange> <security_type> <symbol> <security_desc> <poll_interval_in_ms>
order <exchange> <security_type> <symbol> <security_desc> <signed_quantity> [<price>]
order <account> <exchange> <security_type> <symbol> <security_desc> <signed_quantity> [<price>]
Arguments:
--user=<bts user name>
--pass=<password>
--pump=<pump_interval_in_ms=100 default>
Example:
To print simulated market data to the screen:
spark_sdk.exe md SIM FUTURE ES SIM:ESU9 --user=bts
```
```
* To print simulated market data to the screen:
```spark_sdk.exe md SIM FUTURE ES SIM:ESU9 --user=bts --pass= -ConfigServer http://location:8000/config```
* To send a 1 lot sell order for ES in account ACC A:
```spark_sdk.exe order "ACC A" SIM FUTURE ES SIM:ESU9 -1 4000.5 --user=bts --pass= -ConfigServer http://location:8000/config ```
You should see an order status stream print to the screen after running this command
* Check out sample code
* [Market Data](src/spark_sdk/samples/MarketDataSample.cs)
* [Orders](src/spark_sdk/samples/OrderSample.cs)
* [Driver](src/spark_sdk/samples/SDKMain.cs)
```
### Excel
```
spark_sdk\bin\Debug\net471> start spark_excel-addin64.xll
* Most BTS Client API calls can be made through Excel 2016, load the example spreadsheet to see how
```
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
* From excel, open ```spark_sdk\bin\Debug\net471\spark_excel_example_2019.xlsm``` to get started
* Check the [```excel```](excel/) directory for other example spreadsheets
+2 -2
View File
@@ -58,7 +58,7 @@
<ItemGroup Condition= " '$(SparkRoot)' != '' ">
<None Include="README.md" pack="true" PackagePath="." />
<None Include="$(OutputPath)\net471\spark_excel_example_2018.xlsm" pack="true" PackagePath=".\excel\spark_excel_example_2018.xlsm" />
<None Include="$(OutputPath)\net471\spark_excel_example_2019.xlsm" pack="true" PackagePath=".\excel\spark_excel_example_2019.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\" />
@@ -96,7 +96,7 @@
<Target Name="copy_lib_deployed471" AfterTargets="PostBuildEvent" Condition= " '$(SparkRoot)' == '' and '$(TargetFramework)' == 'net471'" >
<Copy SourceFiles="..\..\lib\net471\spark_excel.dll" DestinationFolder="$(OutputPath)\" SkipUnchangedFiles="true" />
<Copy SourceFiles="..\..\excel\spark_excel_example_2018.xlsm" DestinationFolder="$(OutputPath)\" SkipUnchangedFiles="true" />
<Copy SourceFiles="..\..\excel\spark_excel_example_2019.xlsm" DestinationFolder="$(OutputPath)\" SkipUnchangedFiles="true" />
<Copy SourceFiles="..\..\excel\spark_excel-addin64-packed.xll" DestinationFolder="$(OutputPath)\" SkipUnchangedFiles="true" />
<Copy SourceFiles="..\..\excel\spark_excel-addin64.dna" DestinationFolder="$(OutputPath)\" SkipUnchangedFiles="true" />
</Target>
+1 -1
View File
@@ -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/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MoneyFileService.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/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.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/keycode.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/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.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/sod.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/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.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/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.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;orLine 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/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MoneyFileService.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/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.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/keycode.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/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.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/sod.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/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.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/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.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/FillStore.cpp;orderman/actors/GLBXExecutionGateway.cpLine truncated
+52 -50
View File
@@ -3,9 +3,9 @@
# source: tools/cpp_helper/generate-cpps.ps1
#
CppConfig
{
value
CppConfig
{
value
{
cpp_entry { key: "098" value: 2000 }
cpp_entry { key: "0A" value: 100 }
@@ -354,6 +354,7 @@ CppConfig
cpp_entry { key: "BOB" value: 1000 }
cpp_entry { key: "BOO" value: 6350 }
cpp_entry { key: "BOS" value: 250 }
cpp_entry { key: "BPU" value: 1000 }
cpp_entry { key: "BR7" value: 1000 }
cpp_entry { key: "BSF" value: 25 }
cpp_entry { key: "BTC" value: 5 }
@@ -442,12 +443,12 @@ CppConfig
cpp_entry { key: "D3L" value: 80 }
cpp_entry { key: "D4L" value: 5 }
cpp_entry { key: "D7L" value: 80 }
cpp_entry { key: "DAB" value: 1000 }
cpp_entry { key: "DAX" value: 5 }
cpp_entry { key: "DAZ" value: 80 }
cpp_entry { key: "DBB" value: 1000 }
cpp_entry { key: "DBI" value: 1000 }
cpp_entry { key: "DBL" value: 100 }
cpp_entry { key: "DBR" value: 1000 }
cpp_entry { key: "DBT" value: 100 }
cpp_entry { key: "DC" value: 2000 }
cpp_entry { key: "DCB" value: 1000 }
@@ -458,14 +459,13 @@ CppConfig
cpp_entry { key: "DDE" value: 1000 }
cpp_entry { key: "DDI" value: 1000 }
cpp_entry { key: "DDO" value: 1000 }
cpp_entry { key: "DEB" value: 744 }
cpp_entry { key: "DEB" value: 720 }
cpp_entry { key: "DEN" value: 250 }
cpp_entry { key: "DEP" value: 264 }
cpp_entry { key: "DEP" value: 252 }
cpp_entry { key: "DFL" value: 100 }
cpp_entry { key: "DFN" value: 100 }
cpp_entry { key: "DG2" value: 100 }
cpp_entry { key: "DG3" value: 100 }
cpp_entry { key: "DGH" value: 1000 }
cpp_entry { key: "DGI" value: 100 }
cpp_entry { key: "DGS" value: 100 }
cpp_entry { key: "DGT" value: 100 }
@@ -473,19 +473,13 @@ CppConfig
cpp_entry { key: "DHI" value: 1000 }
cpp_entry { key: "DJR" value: 100 }
cpp_entry { key: "DKR" value: 1000 }
cpp_entry { key: "DMB" value: 100 }
cpp_entry { key: "DOB" value: 1000 }
cpp_entry { key: "DOP" value: 1000 }
cpp_entry { key: "DRB" value: 1000 }
cpp_entry { key: "DRI" value: 100 }
cpp_entry { key: "DRS" value: 100 }
cpp_entry { key: "DRT" value: 100 }
cpp_entry { key: "DSD" value: 1000 }
cpp_entry { key: "DSE" value: 1000 }
cpp_entry { key: "DSG" value: 1000 }
cpp_entry { key: "DTR" value: 2 }
cpp_entry { key: "DTT" value: 2 }
cpp_entry { key: "DUA" value: 6350 }
cpp_entry { key: "DUP" value: 1000 }
cpp_entry { key: "DVE" value: 200 }
cpp_entry { key: "DVT" value: 200 }
@@ -530,8 +524,11 @@ CppConfig
cpp_entry { key: "EP1" value: 1000 }
cpp_entry { key: "EPN" value: 1000 }
cpp_entry { key: "EPZ" value: 500000 }
cpp_entry { key: "EQ1" value: 50 }
cpp_entry { key: "ERL" value: 5 }
cpp_entry { key: "ES" value: 50 }
cpp_entry { key: "ES1" value: 50 }
cpp_entry { key: "ES2" value: 50 }
cpp_entry { key: "ESB" value: 1000 }
cpp_entry { key: "ESK" value: 125000 }
cpp_entry { key: "ESQ" value: 50 }
@@ -733,8 +730,8 @@ CppConfig
cpp_entry { key: "IPO" value: 10 }
cpp_entry { key: "IPT" value: 10 }
cpp_entry { key: "IS" value: 50 }
cpp_entry { key: "ITB" value: 744 }
cpp_entry { key: "ITP" value: 264 }
cpp_entry { key: "ITB" value: 720 }
cpp_entry { key: "ITP" value: 252 }
cpp_entry { key: "IW" value: 50 }
cpp_entry { key: "J4L" value: 80 }
cpp_entry { key: "J7" value: 6250000 }
@@ -748,7 +745,7 @@ CppConfig
cpp_entry { key: "JKB" value: 10000 }
cpp_entry { key: "JKF" value: 10000 }
cpp_entry { key: "JKM" value: 10000 }
cpp_entry { key: "JML" value: 480 }
cpp_entry { key: "JML" value: 240 }
cpp_entry { key: "JNC" value: 1000 }
cpp_entry { key: "JNG" value: 10000 }
cpp_entry { key: "JNL" value: 80 }
@@ -776,6 +773,7 @@ CppConfig
cpp_entry { key: "K5" value: 20 }
cpp_entry { key: "K5K" value: 20 }
cpp_entry { key: "K5N" value: 20 }
cpp_entry { key: "KC" value: 375 }
cpp_entry { key: "KE" value: 50 }
cpp_entry { key: "KET" value: 50 }
cpp_entry { key: "KQ" value: 20 }
@@ -1005,6 +1003,7 @@ CppConfig
cpp_entry { key: "OAD" value: 1 }
cpp_entry { key: "ODO" value: 1000 }
cpp_entry { key: "OFF" value: 5 }
cpp_entry { key: "OJ" value: 150 }
cpp_entry { key: "OML" value: 5 }
cpp_entry { key: "OMM" value: 80 }
cpp_entry { key: "OOD" value: 5 }
@@ -1147,7 +1146,7 @@ CppConfig
cpp_entry { key: "SBT" value: 50 }
cpp_entry { key: "SD" value: 1000 }
cpp_entry { key: "SDA" value: 250 }
cpp_entry { key: "SDD" value: 1760 }
cpp_entry { key: "SDD" value: 1600 }
cpp_entry { key: "SDG" value: 250 }
cpp_entry { key: "SDI" value: 1000 }
cpp_entry { key: "SDM" value: 100 }
@@ -1186,7 +1185,7 @@ CppConfig
cpp_entry { key: "SR3" value: 2500 }
cpp_entry { key: "SR5" value: 1000 }
cpp_entry { key: "SRB" value: 1000 }
cpp_entry { key: "SRT" value: 1760 }
cpp_entry { key: "SRT" value: 1600 }
cpp_entry { key: "SSI" value: 1000 }
cpp_entry { key: "SSP" value: 5000 }
cpp_entry { key: "SSW" value: 1000 }
@@ -1197,27 +1196,28 @@ CppConfig
cpp_entry { key: "STY" value: 1000 }
cpp_entry { key: "SU" value: 250 }
cpp_entry { key: "SUT" value: 250 }
cpp_entry { key: "T01" value: 800 }
cpp_entry { key: "T02" value: 800 }
cpp_entry { key: "T03" value: 800 }
cpp_entry { key: "T04" value: 800 }
cpp_entry { key: "T06" value: 800 }
cpp_entry { key: "T07" value: 800 }
cpp_entry { key: "T08" value: 800 }
cpp_entry { key: "T09" value: 800 }
cpp_entry { key: "T10" value: 800 }
cpp_entry { key: "T11" value: 800 }
cpp_entry { key: "T12" value: 800 }
cpp_entry { key: "T13" value: 800 }
cpp_entry { key: "T14" value: 800 }
cpp_entry { key: "T15" value: 800 }
cpp_entry { key: "T16" value: 800 }
cpp_entry { key: "T17" value: 800 }
cpp_entry { key: "T18" value: 800 }
cpp_entry { key: "T19" value: 800 }
cpp_entry { key: "T1U" value: 1000 }
cpp_entry { key: "T20" value: 800 }
cpp_entry { key: "T21" value: 800 }
cpp_entry { key: "T22" value: 800 }
cpp_entry { key: "T23" value: 800 }
cpp_entry { key: "T24" value: 800 }
cpp_entry { key: "T25" value: 800 }
cpp_entry { key: "T26" value: 800 }
cpp_entry { key: "T27" value: 800 }
cpp_entry { key: "T28" value: 800 }
cpp_entry { key: "T29" value: 800 }
cpp_entry { key: "T2B" value: 1000 }
cpp_entry { key: "T2D" value: 1000 }
cpp_entry { key: "T2M" value: 100 }
@@ -1276,7 +1276,7 @@ CppConfig
cpp_entry { key: "TT" value: 50000 }
cpp_entry { key: "TTD" value: 24 }
cpp_entry { key: "TTE" value: 10000 }
cpp_entry { key: "TTF" value: 744 }
cpp_entry { key: "TTF" value: 720 }
cpp_entry { key: "TUB" value: 1000 }
cpp_entry { key: "TUF" value: 1000 }
cpp_entry { key: "TUL" value: 1000 }
@@ -1295,12 +1295,11 @@ CppConfig
cpp_entry { key: "UDL" value: 80 }
cpp_entry { key: "UFB" value: 100 }
cpp_entry { key: "UFE" value: 100 }
cpp_entry { key: "UFG" value: 100 }
cpp_entry { key: "UFN" value: 100 }
cpp_entry { key: "UFU" value: 100 }
cpp_entry { key: "UFV" value: 100 }
cpp_entry { key: "UGG" value: 42000 }
cpp_entry { key: "UKG" value: 310 }
cpp_entry { key: "UKG" value: 300 }
cpp_entry { key: "ULB" value: 42000 }
cpp_entry { key: "UMB" value: 1000 }
cpp_entry { key: "UMD" value: 1000 }
@@ -1308,6 +1307,9 @@ CppConfig
cpp_entry { key: "UN" value: 1000 }
cpp_entry { key: "UNB" value: 1000 }
cpp_entry { key: "UNS" value: 1000 }
cpp_entry { key: "UP5" value: 1000 }
cpp_entry { key: "UPB" value: 1000 }
cpp_entry { key: "UPM" value: 1000 }
cpp_entry { key: "UR" value: 1000 }
cpp_entry { key: "USC" value: 1000 }
cpp_entry { key: "USDBRL" value: 1 }
@@ -1455,12 +1457,12 @@ CppConfig
cpp_entry { key: "ZT" value: 2000 }
cpp_entry { key: "ZW" value: 50 }
cpp_entry { key: "ZWT" value: 50 }
}
}
}
}
CmeSymbolMics
{
value
CmeSymbolMics
{
value
{
cme_mic { key: "098" value: CBT }
cme_mic { key: "0A" value: NYMEX }
@@ -1809,6 +1811,7 @@ CmeSymbolMics
cme_mic { key: "BOB" value: CBT }
cme_mic { key: "BOO" value: NYMEX }
cme_mic { key: "BOS" value: CME }
cme_mic { key: "BPU" value: NYMEX }
cme_mic { key: "BR7" value: NYMEX }
cme_mic { key: "BSF" value: CBT }
cme_mic { key: "BTC" value: CME }
@@ -1897,12 +1900,12 @@ CmeSymbolMics
cme_mic { key: "D3L" value: NYMEX }
cme_mic { key: "D4L" value: NYMEX }
cme_mic { key: "D7L" value: NYMEX }
cme_mic { key: "DAB" value: NYMEX }
cme_mic { key: "DAX" value: NYMEX }
cme_mic { key: "DAZ" value: NYMEX }
cme_mic { key: "DBB" value: NYMEX }
cme_mic { key: "DBI" value: DME }
cme_mic { key: "DBL" value: NYMEX }
cme_mic { key: "DBR" value: DME }
cme_mic { key: "DBT" value: NYMEX }
cme_mic { key: "DC" value: CME }
cme_mic { key: "DCB" value: NYMEX }
@@ -1920,7 +1923,6 @@ CmeSymbolMics
cme_mic { key: "DFN" value: CBT }
cme_mic { key: "DG2" value: CBT }
cme_mic { key: "DG3" value: CBT }
cme_mic { key: "DGH" value: DME }
cme_mic { key: "DGI" value: CBT }
cme_mic { key: "DGS" value: CBT }
cme_mic { key: "DGT" value: CBT }
@@ -1928,19 +1930,13 @@ CmeSymbolMics
cme_mic { key: "DHI" value: DME }
cme_mic { key: "DJR" value: CBT }
cme_mic { key: "DKR" value: DME }
cme_mic { key: "DMB" value: DME }
cme_mic { key: "DOB" value: DME }
cme_mic { key: "DOP" value: DME }
cme_mic { key: "DRB" value: DME }
cme_mic { key: "DRI" value: CBT }
cme_mic { key: "DRS" value: CBT }
cme_mic { key: "DRT" value: CBT }
cme_mic { key: "DSD" value: DME }
cme_mic { key: "DSE" value: DME }
cme_mic { key: "DSG" value: DME }
cme_mic { key: "DTR" value: CBT }
cme_mic { key: "DTT" value: CBT }
cme_mic { key: "DUA" value: DME }
cme_mic { key: "DUP" value: DME }
cme_mic { key: "DVE" value: CME }
cme_mic { key: "DVT" value: CME }
@@ -1985,8 +1981,11 @@ CmeSymbolMics
cme_mic { key: "EP1" value: NYMEX }
cme_mic { key: "EPN" value: NYMEX }
cme_mic { key: "EPZ" value: CME }
cme_mic { key: "EQ1" value: CME }
cme_mic { key: "ERL" value: NYMEX }
cme_mic { key: "ES" value: CME }
cme_mic { key: "ES1" value: CME }
cme_mic { key: "ES2" value: CME }
cme_mic { key: "ESB" value: NYMEX }
cme_mic { key: "ESK" value: CME }
cme_mic { key: "ESQ" value: CME }
@@ -2652,27 +2651,28 @@ CmeSymbolMics
cme_mic { key: "STY" value: NYMEX }
cme_mic { key: "SU" value: CME }
cme_mic { key: "SUT" value: CME }
cme_mic { key: "T01" value: NYMEX }
cme_mic { key: "T02" value: NYMEX }
cme_mic { key: "T03" value: NYMEX }
cme_mic { key: "T04" value: NYMEX }
cme_mic { key: "T06" value: NYMEX }
cme_mic { key: "T07" value: NYMEX }
cme_mic { key: "T08" value: NYMEX }
cme_mic { key: "T09" value: NYMEX }
cme_mic { key: "T10" value: NYMEX }
cme_mic { key: "T11" value: NYMEX }
cme_mic { key: "T12" value: NYMEX }
cme_mic { key: "T13" value: NYMEX }
cme_mic { key: "T14" value: NYMEX }
cme_mic { key: "T15" value: NYMEX }
cme_mic { key: "T16" value: NYMEX }
cme_mic { key: "T17" value: NYMEX }
cme_mic { key: "T18" value: NYMEX }
cme_mic { key: "T19" value: NYMEX }
cme_mic { key: "T1U" value: CBT }
cme_mic { key: "T20" value: NYMEX }
cme_mic { key: "T21" value: NYMEX }
cme_mic { key: "T22" value: NYMEX }
cme_mic { key: "T23" value: NYMEX }
cme_mic { key: "T24" value: NYMEX }
cme_mic { key: "T25" value: NYMEX }
cme_mic { key: "T26" value: NYMEX }
cme_mic { key: "T27" value: NYMEX }
cme_mic { key: "T28" value: NYMEX }
cme_mic { key: "T29" value: NYMEX }
cme_mic { key: "T2B" value: NYMEX }
cme_mic { key: "T2D" value: NYMEX }
cme_mic { key: "T2M" value: NYMEX }
@@ -2750,7 +2750,6 @@ CmeSymbolMics
cme_mic { key: "UDL" value: NYMEX }
cme_mic { key: "UFB" value: CBT }
cme_mic { key: "UFE" value: CBT }
cme_mic { key: "UFG" value: CBT }
cme_mic { key: "UFN" value: CBT }
cme_mic { key: "UFU" value: CBT }
cme_mic { key: "UFV" value: CBT }
@@ -2763,6 +2762,9 @@ CmeSymbolMics
cme_mic { key: "UN" value: NYMEX }
cme_mic { key: "UNB" value: NYMEX }
cme_mic { key: "UNS" value: NYMEX }
cme_mic { key: "UP5" value: NYMEX }
cme_mic { key: "UPB" value: NYMEX }
cme_mic { key: "UPM" value: NYMEX }
cme_mic { key: "UR" value: NYMEX }
cme_mic { key: "USC" value: NYMEX }
cme_mic { key: "USDBRL" value: CME }
@@ -2910,5 +2912,5 @@ CmeSymbolMics
cme_mic { key: "ZT" value: CBT }
cme_mic { key: "ZW" value: CBT }
cme_mic { key: "ZWT" value: CBT }
}
}
}
+29
View File
@@ -31,4 +31,33 @@ OrdermanCfg {
hosted_actor: "*"
}
}
}
OrderManThreadingCfg {
value {
thread {
name: "om_1"
poll: true
actor: { name: "order_manager" }
}
thread {
name: "om_2"
poll: true
actor: { name: "order_manager" }
}
thread {
name: "gw_1"
poll: true
actor: { name: "gateway" arg: "sim" }
actor: { name: "gateway" arg: "cme_mc5_99" }
}
thread {
name: "om_slow"
actor: {name: "storage"}
actor: {name: "service_bridge"}
}
}
}
+2 -2
View File
@@ -7,11 +7,11 @@ message JetFIX {
required string name = 10;
enum JetFIXPlatform {
GLBX = 1;
CBOE = 6;
GLBX = 1;
SIM = 2;
ICE = 3;
SIMICE = 4;
CBOE = 6;
}
optional JetFIXPlatform platform = 15 [default = GLBX];
+16
View File
@@ -10,3 +10,19 @@ message OrdermanCfg {
repeated Executor executor = 1;
optional uint32 default_iceberg_pause_secs = 2 [default = 0];
}
message OrderManThreadingCfg {
message Actor {
required string name = 1;
repeated string arg = 2;
}
message Thread {
required string name = 1;
optional bool poll = 2 [default = false];
optional uint32 slow_worker_period = 3 [default = 100000];
repeated Actor actor = 4;
}
repeated Thread thread= 1;
}
+3 -3
View File
@@ -11,7 +11,7 @@ inline int d_toa(double n, char *buffer, size_t buffer_size, int decimal_digits=
static double_conversion::DoubleToStringConverter const &c =
double_conversion::DoubleToStringConverter::EcmaScriptConverter();
bts_assert(buffer_size);
bts_assert_d(buffer_size);
if (pad == -1) {
// no padding, return the smallest number that contains all the
@@ -34,8 +34,8 @@ inline int d_toa(double n, char *buffer, size_t buffer_size, int decimal_digits=
// padding, return something with a fixed size
std::array<char, 128> pre_buffer;
bts_assert((int)buffer_size > pad);
bts_assert((int)pre_buffer.size() >= pad);
bts_assert_d((int)buffer_size > pad);
bts_assert_d((int)pre_buffer.size() >= pad);
double_conversion::StringBuilder builder(&pre_buffer[0], pre_buffer.size());
+10 -10
View File
@@ -22,7 +22,7 @@ size_t extract(char *start, char *end,
std::vector<InMsgBuffer> *msgs) {
auto first_unprocessed_byte = 0;
auto current = start;
for (;;) {
// consume prefix
auto this_msg_begin = current;
@@ -143,20 +143,20 @@ void AsyncReader::dispatch() {
// see what we can parse with the just read bytes
framed_msgs.clear();
// extract as many messages as we can from the last unprocess
// byte to the current write cursor, return offset of first
// byte in the buffer that we could not process (possibly the
// first byte of an incomplete msg)
auto first_unprocessed_offset = extract(
&((*me->working_buffer)[me->first_pending_msg]),
&((*me->working_buffer)[me->write_cursor]), me->working_buffer,
&framed_msgs);
// extract as many messages as we can from the last
// unprocessed byte to the current write cursor, return
// offset of first byte in the buffer that we could not
// process (possibly the first byte of an incomplete msg)
auto first_unprocessed_offset =
extract(&((*me->working_buffer)[me->first_pending_msg]),
&((*me->working_buffer)[me->write_cursor]),
me->working_buffer, &framed_msgs);
me->first_pending_msg += first_unprocessed_offset;
for (auto &msg : framed_msgs) {
trace.sn = msg.get_seq_num();
socket_read_time.shift_ns(1);
me->perf_log.log(trace, socket_read_time,"fix_msg_r");
me->perf_log.log(trace, socket_read_time, "fix_msg_r");
msg.set_trace(trace);
me->sink.in_msg_raw(msg);
}
+28 -71
View File
@@ -27,12 +27,12 @@ namespace jetfix {
enum class CoreGateway::State {
OFF,
PAUSED,
CONNECTING,
READY,
WREADER_DISCONNECT,
WSESSION_TERMINATE
};
PAUSED,
CONNECTING,
READY,
WREADER_DISCONNECT,
WSESSION_TERMINATE
};
struct CoreGateway::SessionInfo {
SessionInfo() : connection(), store(), reader(), session() {}
@@ -47,21 +47,21 @@ struct CoreGateway::EventData {
typedef void (CoreGateway::*Handler)(EventData const &ev);
EventData(const EventData &src)
: handler(src.handler), out_msgs(src.out_msgs), in_msg(src.in_msg),
trace(src.trace), ts(src.ts) {}
: handler(src.handler), out_msgs(src.out_msgs), in_msg(src.in_msg),
trace(src.trace), ts(src.ts) {}
EventData() : handler(), out_msgs(), in_msg(), trace(), ts() {}
EventData(Handler handler)
: handler(handler), out_msgs(), in_msg(), trace(), ts() {}
: handler(handler), out_msgs(), in_msg(), trace(), ts() {}
EventData(Handler handler, trace::CorID const &trace,
OutFIXPtr const &out_msgs)
: handler(handler), out_msgs(out_msgs), in_msg(), trace(trace), ts() {}
: handler(handler), out_msgs(out_msgs), in_msg(), trace(trace), ts() {}
EventData(Handler handler, InMsgBuffer const &in_msg)
: handler(handler), out_msgs(), in_msg(in_msg), trace(), ts() {}
: handler(handler), out_msgs(), in_msg(in_msg), trace(), ts() {}
EventData(Handler handler, std::shared_ptr<std::string> const &ts)
: handler(handler), out_msgs(), in_msg(), trace(), ts(ts) {}
: handler(handler), out_msgs(), in_msg(), trace(), ts(ts) {}
EventData &operator=(EventData &src) {
handler = src.handler;
@@ -91,11 +91,11 @@ struct CoreGateway::PImpl {
PImpl(config::JetFIX::Connection const &cfg, ICoreGatewayObserver &observer,
ConnectionFactory const &conn_factory,
StoreFactory const &store_factory, trace::PerfLog &l)
: cfg(cfg), observer(observer), make_connection(conn_factory),
make_store(store_factory), state(State::OFF), start_of_pause(),
session_info(), event_queue(), timer_thread(), destroy(false),
is_on(false), has_replayed(false), send_batch(), recv_batch(),
connection_attempts(0), perf_log(l) {
: cfg(cfg), observer(observer), make_connection(conn_factory),
make_store(store_factory), state(State::OFF), start_of_pause(),
session_info(), event_queue(), timer_thread(), destroy(false),
is_on(false), has_replayed(false), send_batch(), recv_batch(),
connection_attempts(0), perf_log(l) {
send_batch.reserve(1024);
recv_batch.reserve(1024);
}
@@ -130,7 +130,7 @@ CoreGateway::CoreGateway(config::JetFIX::Connection const &cfg,
ConnectionFactory const &conn_factory,
StoreFactory const &store_factory,
trace::PerfLog &perf_trace)
: me(new PImpl(cfg, observer, conn_factory, store_factory, perf_trace)) {
: me(new PImpl(cfg, observer, conn_factory, store_factory, perf_trace)) {
me->timer_thread = make_timer_thread();
}
@@ -148,14 +148,6 @@ void CoreGateway::send(OutFIXPtr const &fix, trace::CorID trace) {
me->event_queue.push(EventData(&CoreGateway::sync_send, trace, fix));
}
void CoreGateway::send_hb() {
me->event_queue.push(EventData(&CoreGateway::sync_send_hb));
}
void CoreGateway::send_test_request() {
me->event_queue.push(EventData(&CoreGateway::sync_send_test_request));
}
void CoreGateway::start() {
me->event_queue.push(EventData(&CoreGateway::sync_start));
}
@@ -198,7 +190,7 @@ void CoreGateway::dispatch_events() {
if (me->send_batch.size() || me->recv_batch.size()) {
for (auto &ev : me->send_batch)
(this->*ev.handler)(ev);
for (auto &ev : me->recv_batch)
for (auto &ev : me->recv_batch)
(this->*ev.handler)(ev);
me->send_batch.clear();
me->recv_batch.clear();
@@ -209,7 +201,7 @@ void CoreGateway::call_time() {
while (!me->destroy) {
std::this_thread::sleep_for(10ms);
auto ts = std::make_shared<std::string>(
datetime::FIX_timestamp(datetime::now()));
datetime::FIX_timestamp(datetime::now()));
me->event_queue.push(EventData(&CoreGateway::sync_time, ts)); // NOLINT
}
}
@@ -276,42 +268,6 @@ void CoreGateway::sync_send(EventData const &ev) {
}
}
void CoreGateway::sync_send_hb(EventData const &) {
switch (me->state) {
case State::OFF:
bts_assert(false);
break;
case State::PAUSED:
case State::CONNECTING:
case State::WREADER_DISCONNECT:
case State::WSESSION_TERMINATE:
break;
case State::READY:
me->session_info->session->send_hb();
break;
default:
bts_assert(false);
}
}
void CoreGateway::sync_send_test_request(EventData const &) {
switch (me->state) {
case State::OFF:
bts_assert(false);
break;
case State::PAUSED:
case State::CONNECTING:
case State::WREADER_DISCONNECT:
case State::WSESSION_TERMINATE:
break;
case State::READY:
me->session_info->session->send_test_request();
break;
default:
bts_assert(false);
}
}
void CoreGateway::sync_session_ready(EventData const &) {
switch (me->state) {
case State::OFF:
@@ -443,7 +399,8 @@ void CoreGateway::sync_time(EventData const &ev) {
if (!me->has_replayed) {
auto msgs_to_replay = me->session_info->store->replay();
LOG(Jetfix, Warn, "Replaying {} FIX msgs", msgs_to_replay.size());
LOG(Jetfix, Warn, "Replaying {} FIX msgs",
msgs_to_replay.size());
me->observer.replay(msgs_to_replay);
me->has_replayed = true;
}
@@ -468,13 +425,13 @@ void CoreGateway::sync_time(EventData const &ev) {
me->cfg.name());
me->session_info->session.reset(new Session(
me->cfg, *me->session_info->connection,
*me->session_info->store, *this,
[]() { return utils::TimeStamp::now(); }, me->perf_log));
me->cfg, *me->session_info->connection,
*me->session_info->store, *this,
[]() { return utils::TimeStamp::now(); }, me->perf_log));
me->session_info->reader.reset(new AsyncReader(
*me->session_info->connection, me->cfg.name(), *this,
me->perf_log, me->cfg.msg_buffer_sz(),
me->cfg.msg_high_water_mark()));
*me->session_info->connection, me->cfg.name(), *this,
me->perf_log, me->cfg.msg_buffer_sz(),
me->cfg.msg_high_water_mark()));
me->session_info->reader->start();
me->session_info->session->start();
transition(State::CONNECTING);
-6
View File
@@ -35,10 +35,6 @@ public:
void send (OutFIXPtr const &msgs, trace::CorID trace);
void dispatch_events ();
// for certification use only
void send_hb ();
void send_test_request ();
private:
enum class State;
struct SessionInfo;
@@ -56,8 +52,6 @@ private:
void sync_start (EventData const &);
void sync_stop (EventData const &);
void sync_send (EventData const &);
void sync_send_hb (EventData const&);
void sync_send_test_request (EventData const&);
void sync_session_ready (EventData const&) ;
void sync_session_terminated (EventData const&);
void sync_reader_disconnected (EventData const&) ;
-4
View File
@@ -67,10 +67,6 @@ public:
DispatcherTuple>::value> (_dispatchers).handler;
}
// for CERT purposes
void send_hb () {_core.send_hb ();}
void send_test_request () {_core.send_test_request ();}
private:
struct IDispatcher
{
+1
View File
@@ -7,6 +7,7 @@
namespace bts {
namespace jetfix {
class InMsgBuffer;
class IFIXStore
+167 -92
View File
@@ -5,136 +5,211 @@
namespace bts {
namespace jetfix {
boost::gregorian::greg_weekday parse_weekday (std::string weekday_str)
{
boost::to_lower (weekday_str);
boost::gregorian::greg_weekday parse_weekday(std::string weekday_str) {
boost::to_lower(weekday_str);
for (int i = 0; i < 7; i++) {
auto gw_day = boost::gregorian::greg_weekday (i);
auto prefix = std::string (gw_day.as_short_string ());
boost::to_lower (prefix);
if (weekday_str.find (prefix) == 0)
auto gw_day = boost::gregorian::greg_weekday(i);
auto prefix = std::string(gw_day.as_short_string());
boost::to_lower(prefix);
if (weekday_str.find(prefix) == 0)
return gw_day;
}
bts_assert (false);
return boost::gregorian::greg_weekday (0);
bts_assert(false);
return boost::gregorian::greg_weekday(0);
}
boost::posix_time::time_duration parse_time (std::string const &time_str)
{
boost::posix_time::time_duration parse_time(std::string const &time_str) {
try {
return boost::posix_time::duration_from_string (time_str);
}
catch (boost::bad_lexical_cast &)
{
bts_assert (false);
return boost::posix_time::time_duration ();
return boost::posix_time::duration_from_string(time_str);
} catch (boost::bad_lexical_cast &) {
bts_assert(false);
return boost::posix_time::time_duration();
}
}
datetime::PTime closest_before (datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday,
boost::posix_time::time_duration time_of_day)
{
if (ref_date.date ().day_of_week () == weekday) {
if (time_of_day < ref_date.time_of_day ())
return datetime::PTime (ref_date.date (),time_of_day);
datetime::PTime closest_before(datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday,
boost::posix_time::time_duration time_of_day) {
if (ref_date.date().day_of_week() == weekday) {
if (time_of_day < ref_date.time_of_day())
return datetime::PTime(ref_date.date(), time_of_day);
else {
return datetime::PTime (ref_date.date () - boost::gregorian::date_duration (7),
time_of_day);
return datetime::PTime(
ref_date.date() - boost::gregorian::date_duration(7), time_of_day);
}
} else {
auto distance =
ref_date.date ().day_of_week ().as_number () -
weekday.as_number ();
ref_date.date().day_of_week().as_number() - weekday.as_number();
if (distance < 0)
distance += 7;
return datetime::PTime (ref_date.date () - boost::gregorian::date_duration (distance),
time_of_day);
return datetime::PTime(ref_date.date() -
boost::gregorian::date_duration(distance),
time_of_day);
}
}
bool in_session (datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end)
{
auto t = ref_date.time_of_day ();
bool in_session(datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end) {
auto t = ref_date.time_of_day();
if (time_of_day_start < time_of_day_end)
return t >= time_of_day_start && t <= time_of_day_end;
else
return t >= time_of_day_start || t <= time_of_day_end;
}
bool in_session (datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday_start,
boost::posix_time::time_duration time_of_day_start,
boost::gregorian::greg_weekday weekday_end,
boost::posix_time::time_duration time_of_day_end)
{
auto closest_earlier_start = closest_before (ref_date,weekday_start,time_of_day_start);
auto closest_earlier_end = closest_before (ref_date,weekday_end,time_of_day_end);
return closest_earlier_end<closest_earlier_start;
bool in_session(datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday_start,
boost::posix_time::time_duration time_of_day_start,
boost::gregorian::greg_weekday weekday_end,
boost::posix_time::time_duration time_of_day_end) {
auto closest_earlier_start =
closest_before(ref_date, weekday_start, time_of_day_start);
auto closest_earlier_end =
closest_before(ref_date, weekday_end, time_of_day_end);
return closest_earlier_end < closest_earlier_start;
}
std::string session_name_from_ptime (datetime::PTime t,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end)
{
std::string result (10,' ');
std::string
session_name_from_ptime(datetime::PTime t,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end) {
std::string result(10, ' ');
auto start_of_session = t;
if (time_of_day_start > time_of_day_end &&
start_of_session.time_of_day () <= time_of_day_end)
start_of_session -= boost::gregorian::date_duration (1);
sprintf (&result[0], "%04d-%02d-%02d",
(unsigned short) start_of_session.date ().year (),
start_of_session.date ().month ().as_number (),
start_of_session.date ().day ().as_number ());
if (time_of_day_start > time_of_day_end &&
start_of_session.time_of_day() <= time_of_day_end)
start_of_session -= boost::gregorian::date_duration(1);
sprintf(&result[0], "%04d-%02d-%02d",
(unsigned short)start_of_session.date().year(),
start_of_session.date().month().as_number(),
start_of_session.date().day().as_number());
return result;
}
std::string session_name (datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday_start,
boost::posix_time::time_duration time_of_day_start,
boost::gregorian::greg_weekday weekday_end,
boost::posix_time::time_duration time_of_day_end)
{
if (in_session (ref_date,weekday_start,time_of_day_start,weekday_end,time_of_day_end))
return session_name_from_ptime (closest_before (ref_date,weekday_start,time_of_day_start),
boost::posix_time::time_duration(0, 0, 0),
boost::posix_time::time_duration(0, 0, 1));
std::string session_name(datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday_start,
boost::posix_time::time_duration time_of_day_start,
boost::gregorian::greg_weekday weekday_end,
boost::posix_time::time_duration time_of_day_end) {
if (in_session(ref_date, weekday_start, time_of_day_start, weekday_end,
time_of_day_end))
return session_name_from_ptime(
closest_before(ref_date, weekday_start, time_of_day_start),
boost::posix_time::time_duration(0, 0, 0),
boost::posix_time::time_duration(0, 0, 1));
else
return std::string ();
return std::string();
}
std::string session_name (datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end)
{
if (in_session (ref_date,time_of_day_start,time_of_day_end))
return session_name_from_ptime (ref_date, time_of_day_start, time_of_day_end);
std::string session_name(datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end) {
if (in_session(ref_date, time_of_day_start, time_of_day_end))
return session_name_from_ptime(ref_date, time_of_day_start,
time_of_day_end);
else
return "";
}
std::string session_name (config::JetFIX::Connection const &session_cfg)
{
auto now = datetime::local_now ();
std::string session_name(config::JetFIX::Connection const &session_cfg) {
return session_name(datetime::local_now(), session_cfg);
}
std::string session_name(datetime::PTime const&now,
config::JetFIX::Connection const &session_cfg) {
if (session_cfg.has_start_day()) {
bts_assert(session_cfg.has_end_day());
return session_name(now, parse_weekday(session_cfg.start_day()),
parse_time(session_cfg.start_time()),
parse_weekday(session_cfg.end_day()),
parse_time(session_cfg.end_time()));
} else
return session_name(now, parse_time(session_cfg.start_time()),
parse_time(session_cfg.end_time()));
}
SessionSpan session_span(datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday_start,
boost::posix_time::time_duration time_of_day_start,
boost::gregorian::greg_weekday weekday_end,
boost::posix_time::time_duration time_of_day_end) {
auto one_week = boost::gregorian::date_duration(7);
auto closest_earlier_start =
closest_before(ref_date, weekday_start, time_of_day_start);
auto closest_earlier_end =
closest_before(ref_date, weekday_end, time_of_day_end);
if (closest_earlier_end < closest_earlier_start)
// we are in the session
return {closest_earlier_start, closest_earlier_end + one_week };
else
// need to wait for the next session
return {closest_earlier_start+one_week, closest_earlier_end + one_week };
}
SessionSpan session_span(datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end) {
auto t = ref_date.time_of_day();
auto today = ref_date.date() ;
auto tomorrow = today + boost::gregorian::date_duration(1) ;
auto yesterday = today - boost::gregorian::date_duration(1) ;
if (session_cfg.has_start_day ()) {
bts_assert (session_cfg.has_end_day ());
return session_name (now,
parse_weekday (session_cfg.start_day ()),
parse_time (session_cfg.start_time ()),
parse_weekday (session_cfg.end_day ()),
parse_time (session_cfg.end_time ()));
} else
return session_name (now,
parse_time (session_cfg.start_time ()),
parse_time (session_cfg.end_time ()));
if (time_of_day_start < time_of_day_end) {
// scheduled start/scheduled end do not span midnight
if (t <= time_of_day_end) {
// we are inside the schedule
return {
datetime::PTime(today,time_of_day_start),
datetime::PTime(today,time_of_day_end)
};
}
else {
// too late for today, tomorrow is the time for the session
return {
datetime::PTime(tomorrow,time_of_day_start),
datetime::PTime(tomorrow,time_of_day_end)
};
}
} else {
// the start/stop span over midnight
if (t <= time_of_day_end) {
// we are inside the the schedule
return {
datetime::PTime(yesterday,time_of_day_start),
datetime::PTime(today,time_of_day_end)
};
}
else {
// too late, skip to next session
return {
datetime::PTime(today,time_of_day_start),
datetime::PTime(tomorrow,time_of_day_end)
};
}
}
}
SessionSpan session_span(datetime::PTime const&now,config::JetFIX::Connection const&session_cfg)
{
if (session_cfg.has_start_day()) {
bts_assert(session_cfg.has_end_day());
return session_span(now, parse_weekday(session_cfg.start_day()),
parse_time(session_cfg.start_time()),
parse_weekday(session_cfg.end_day()),
parse_time(session_cfg.end_time()));
} else
return session_span(now, parse_time(session_cfg.start_time()),
parse_time(session_cfg.end_time()));
}
SessionSpan session_span(config::JetFIX::Connection const &session_cfg) {
return session_span(datetime::local_now(), session_cfg);
}
}}
} // namespace jetfix
} // namespace bts
+10
View File
@@ -4,6 +4,7 @@
#include <string>
#include "lib/utils/datetime.h"
#include "lib/config/protos/jetfix.pb.h"
#include <boost/date_time/posix_time/posix_time.hpp>
namespace boost {
namespace gregorian {
@@ -45,5 +46,14 @@ std::string session_name (datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_end);
std::string session_name (config::JetFIX::Connection const &session_cfg);
std::string session_name (datetime::PTime const &ref_date,
config::JetFIX::Connection const &session_cfg);
struct SessionSpan {
datetime::PTime start;
datetime::PTime stop;
};
SessionSpan session_span(config::JetFIX::Connection const&session_cfg);
SessionSpan session_span(datetime::PTime const&local_now,config::JetFIX::Connection const&session_cfg);
}}
+1
View File
@@ -120,6 +120,7 @@ void configure_logging(bts::config::Logging const&cfg, bts::config::ThreadGroupC
{log::Plugin,"Plugin"},
{log::ClientSdk,"ClientSdk"},
{log::Http,"Http"},
{log::OrderMan2,"OrderMan2"},
};
real_cfg.sinks["console"] =
+3 -1
View File
@@ -24,7 +24,8 @@ constexpr log::Level Sys {log::Level::Max-1};
namespace log {
// Please keep this list in sync with Log.cs
// Please keep this list in sync with Log.cs and make sure
// to replicate the change in logging.cpp
constexpr log::Subsystem Gen {0 };
constexpr log::Subsystem Cfg {Gen.ordinal+1 };
constexpr log::Subsystem QBus {Cfg.ordinal+1 };
@@ -46,6 +47,7 @@ constexpr log::Subsystem DataFlow {Latency.ordinal+1 };
constexpr log::Subsystem Plugin {DataFlow.ordinal+1 };
constexpr log::Subsystem ClientSdk {Plugin.ordinal+1 };
constexpr log::Subsystem Http {ClientSdk.ordinal+1 };
constexpr log::Subsystem OrderMan2 {Http.ordinal+1 };
struct LoggerHandle {
LoggerHandle(LoggerHandle const&) = delete;
-7
View File
@@ -6,9 +6,7 @@
#include "ExchangeOrderKey.h"
#include "MDProducerHandle.h"
#ifndef _WIN32
#include "google/btree/btree_map.h"
#endif
#include <vector>
#include <memory>
@@ -109,13 +107,8 @@ struct MBOWorkingState {
// Used for 'change' messages which update price
std::unordered_map<ExchangeOrderKey, key_t> orderid_index;
#ifdef _WIN32
std::map<key_t,Data,LessBid> bid;
std::map<key_t,Data> ask;
#else
btree::btree_map<key_t,Data,LessBid> bid;
btree::btree_map<key_t,Data> ask;
#endif
};
+34 -27
View File
@@ -13,6 +13,7 @@
#include "lib/utils/sane_algorithm.h"
#include <tbb/queuing_mutex.h>
#include <google/btree/btree_map.h>
#include <string>
#include <map>
#include <set>
@@ -21,6 +22,7 @@
using namespace std;
using namespace bts::api;
using namespace btree;
namespace bts {
namespace md {
@@ -158,32 +160,36 @@ public:
return false;
}
void search_handles(map<security_key, MDConsumerHandle>& handles) {
btree_map<security_key, tuple<const ColdEntry*,const void*>> search_handles(const std::set<security_key>& keys) {
btree_map<security_key, tuple<const ColdEntry*, const void*>> result;
// Walk hot and cold lists and fill in any found handles
if (!_cold.is_initialized()) return;
if (!_cold.is_initialized()) return result;
_cold.all_entries([&](const ColdEntry& entry) {
auto iter = handles.find(entry.security.key);
if (iter != handles.end()) {
iter->second.set_cold(&cold_header(), &entry);
if (keys.find(entry.security.key) != keys.end()) {
result.insert(
std::make_pair(
entry.security.key,
make_tuple(&entry,nullptr)));
}
});
// Do the same for hot
if (_hot_depth) {
_hot_depth->all_entries([&](const HotDepthEntry& entry) {
auto iter = handles.find(entry.key);
if (iter != handles.end() && iter->second.is_initialized()) {
iter->second.set_hot(&entry);
auto iter = result.find(entry.key);
if (iter != result.end()) {
iter->second = make_tuple(get<0>(iter->second), &entry);
}
});
}
else if (_hot){
_hot->all_entries([&](const HotEntry& entry) {
auto iter = handles.find(entry.key);
if (iter != handles.end() && iter->second.is_initialized()) {
iter->second.set_hot(&entry);
auto iter = result.find(entry.key);
if (iter != result.end()) {
iter->second = make_tuple(get<0>(iter->second), &entry);
}
});
}
return result;
}
template <typename CB>
@@ -661,24 +667,24 @@ public:
map<security_key, MDConsumerHandle> get_handles(const set<security_key>& keys) {
map<security_key, MDConsumerHandle> result;
if (keys.empty()) return result;
// Initialize the result to match the input
for (security_key key : keys) {
result.insert(std::make_pair(key, MDConsumerHandle()));
}
for (auto& inst : _instances) {
inst->search_handles(result);
}
// Erase anything that wasn't found from the resulting map
// Set the mbo pointer on anything else
for (auto it = result.begin(); it != result.end(); ) {
if (!it->second.is_initialized()) {
it = result.erase(it);
}
else {
it->second.set_mbo(_mbo);
++it;
auto found = inst->search_handles(keys);
for (const auto& t : found) {
// auto [cold,hot] = t.second;
auto cold = get<0>(t.second);
auto hot = get<1>(t.second);
if (cold && hot) {
result.insert(
make_pair(
cold->security.key,
MDConsumerHandle {
inst->cold_header(),
*cold,
hot,
_mbo
}));
}
}
}
@@ -719,6 +725,7 @@ public:
vector<MutSecurityPtr> legs;
legs.reserve(handles.size());
for (const auto& pair : handles) {
bts_assert_d(pair.second.is_initialized());
if (pair.second.is_initialized()) {
legs.push_back(make_shared<Security>(pair.second.get_normalized_security()));
}
+3
View File
@@ -32,6 +32,9 @@ MDConsumerHandle::MDConsumerHandle(const MDConsumerHandle& other) {
*this = other;
}
MDConsumerHandle::MDConsumerHandle(const ColdHeader& cheader, const ColdEntry& centry, const void* pvhot, const MBOReader* mbo)
{init(cheader,centry,pvhot,mbo);}
MDConsumerHandle::~MDConsumerHandle() {}
void MDConsumerHandle::init(const ColdHeader& cheader, const ColdEntry& centry, const void* pvhot, const MBOReader* mbo) {
+1 -3
View File
@@ -156,6 +156,7 @@ public:
explicit MDConsumerHandle(const std::shared_ptr<const SyntheticStrategy>&);
~MDConsumerHandle();
MDConsumerHandle(const MDConsumerHandle& other);
MDConsumerHandle(const ColdHeader&, const ColdEntry&, const void* hot, const MBOReader*);
void init(const ColdHeader&, const ColdEntry&, const void* hot, const MBOReader*);
@@ -297,9 +298,6 @@ public:
std::unique_ptr<MBOSnapshot,std::function<void(MBOSnapshot*)>> get_mbo() const;
private:
friend class MDConsumerInst;
friend class MDConsumerImpl;
template <class Read>
HandleReadResult get_book(Read read, TimeStamp& time, uint32_t copydepth, PriceSize* bids, PriceSize* asks) const {
bts_assert_d(copydepth <= COCONUT_MAX_DEPTH);
+4 -1
View File
@@ -92,7 +92,7 @@ size_t load_securities(
api::Venue venue = (api::Venue)(int) select_stmt.getColumn("venue");
auto type = (api::SecurityType)(int) select_stmt.getColumn("type");
UserSymbol us(symbol, venue, type);
if (symbols.find(us) != symbols.end()) {
if (symbols.empty() || symbols.find(us) != symbols.end()) {
auto blob = select_stmt.getColumn("security_blob");
if (security.ParseFromArray(blob, blob.getBytes())) {
apply_compatibilit_mutations(security);
@@ -108,6 +108,9 @@ size_t load_securities(
return count;
}
size_t load_securities(const std::function<void(const api::Security&)>& callback) {
return load_securities({}, callback);
}
SecurityPtr find_security(SecurityKey key) {
try {
+1
View File
@@ -27,6 +27,7 @@ struct SecurityDB;
size_t load_securities(
const std::set<UserSymbol>& symbols,
const std::function<void(const api::Security&)>& callback);
size_t load_securities(const std::function<void(const api::Security&)>& callback);
SecurityPtr find_security(SecurityKey);
+3 -7
View File
@@ -80,9 +80,9 @@ class BrokerProxy : public ILocalBroker {
send(m);
}
void do_work(trace::PerfLog& log) {
void do_work(trace::PerfLog& ) {
_cycles++;
_outgoing.consume_all([this,&log](BrokerMsg *m) {
_outgoing.consume_all([this](BrokerMsg *m) {
switch (m->msg_type) {
case BrokerMsgType::ADD_NEIGHBOUR:
_real_broker.add_neighbour(*m->neighbour);
@@ -102,13 +102,9 @@ class BrokerProxy : public ILocalBroker {
case BrokerMsgType::UNSUBSCRIBE:
_real_broker.unsubscribe(m->broker_id, m->sub_id, m->stream_id);
break;
case BrokerMsgType::NOTIFY: {
LOG(Latency, Diag, "Notify broker {}. Cycles: {}", _id.value(),
_cycles);
auto scoped_do_work = trace::log_scope(log, {}, "BrokerProxy::notify");
case BrokerMsgType::NOTIFY:
_real_broker.notify(m->broker_id, m->stream_id, m->sub_id,
m->notification);
}
break;
case BrokerMsgType::LOCAL_SUBSCRIBE:
_real_broker.local_subscribe(m->local_sub_id, m->filter,
+14 -21
View File
@@ -1,45 +1,38 @@
#include "lib/mercury/executor/Executor.h"
#include "lib/mercury/broker/Broker.h"
#include "lib/mercury/broker/BrokerProxy.h"
#include "lib/mercury/actors/Actor.h"
#include "lib/mercury/actors/IPollableActor.h"
#include "lib/mercury/broker/Broker.h"
#include "lib/mercury/broker/BrokerProxy.h"
namespace bts {
namespace mercury {
Executor::Executor() :
_broker(),
_incoming_proxies(),
_my_proxy(make_proxy()),
_actor_broker(_my_proxy),
_actors() {}
Executor::Executor()
: _broker(), _incoming_proxies(), _my_proxy(make_proxy()),
_actor_broker(_my_proxy), _actors() {}
Executor::~Executor() {
for (auto &a : _actors)
a->deactivate();
}
void Executor::init_neighbours(std::vector<Executor*> const&neighbours)
{
void Executor::init_neighbours(std::vector<Executor *> const &neighbours) {
for (auto e : neighbours)
if (e != this)
if (e != this)
_outgoing_proxies.push_back(&e->make_proxy());
for (auto n : _outgoing_proxies)
_broker.add_neighbour(*n);
}
void Executor::activate(Actor *actor)
{
_actors.push_back(std::unique_ptr<Actor> (actor));
auto pollable = dynamic_cast<IPollableActor*> (actor);
void Executor::activate(Actor *actor) {
_actors.push_back(std::unique_ptr<Actor>(actor));
auto pollable = dynamic_cast<IPollableActor *>(actor);
if (pollable)
_pollable_actors.push_back(pollable);
actor->activate(_actor_broker);}
actor->activate(_actor_broker);
}
BrokerProxy& Executor::make_proxy()
{
BrokerProxy &Executor::make_proxy() {
_incoming_proxies.push_back(std::make_unique<BrokerProxy>(_broker));
return *_incoming_proxies.back();
}
+7 -59
View File
@@ -58,12 +58,10 @@ void FillStore::init() {
fill.set_fill_kind(Fill::FILL_KIND_SOD);
auto sec = me->oracle.get_security(SecurityKey(fill.security_key()));
if (sec) {
if (config::get<config::toggles::FilterExpiredFills>().enabled() &&
securities::is_expired(*sec))
continue;
else {
auto fk = kvp.first;
me->known_fills.insert(fk);
auto fk = kvp.first;
me->known_fills.insert(fk);
if (!config::get<config::toggles::FilterExpiredFills>().enabled() ||
!securities::is_expired(*sec)) {
stored_batch.emplace_back(fill, *sec);
}
} else
@@ -99,8 +97,7 @@ void FillStore::on_execution_report(
to_str(er.exchange_fill_id));
auto is_known = me->known_fills.count(fk);
if (er.exec_type == api::orderman::EXEC_TYPE_PARTIAL_FILL ||
er.exec_type == api::orderman::EXEC_TYPE_FILL ||
er.exec_type == api::orderman::EXEC_TYPE_TRADE_CORRECT) {
er.exec_type == api::orderman::EXEC_TYPE_FILL) {
api::orderman::Fill fill;
if (!is_known) {
@@ -144,60 +141,11 @@ void FillStore::on_execution_report(
} // if partial_fill or fill
}
for (auto const &ev : *u.events)
{
auto &er = *ev.data;
auto efi = to_str(er.exchange_fill_id);
if(std::count(efi.begin(), efi.end(), ':') > 0)
{
auto cpos = efi.find_last_of(':');
efi = efi.substr(0, cpos);
ExchangeFillID temp;
str_to(efi, &temp);
efi = to_str(temp);
}
if(efi == "")
continue;
auto fk = fmt::format("{}:{}", er.order_key.value(), efi);
auto is_known = me->known_fills.count(fk);
if(er.exec_type == api::orderman::EXEC_TYPE_TRADE_CANCEL)
{
auto data = me->store->retrieve_one(fills_ns, fk);
Fill existing_fill;
if(is_known && data.first && utils::pb::from_string(data.second, &existing_fill))
{
existing_fill.set_fill_status(api::orderman::Fill::FILL_STATUS_BUSTED);
auto fv = utils::pb::to_string(existing_fill);
me->store->update(fills_ns, fk, fv);
publish(me->fill_stream, existing_fill, *er.security);
}
else
LOG(OrderMan, Warn, "Received bust for unknown fill {}", fk);
}
else if(er.exec_type == api::orderman::EXEC_TYPE_TRADE_CORRECT)
{
auto data = me->store->retrieve_one(fills_ns, fk);
Fill existing_fill;
if(is_known && data.first && utils::pb::from_string(data.second, &existing_fill))
{
existing_fill.set_fill_status(api::orderman::Fill::FILL_STATUS_CORRECTED);
existing_fill.set_last_price(er.last_price.value());
existing_fill.set_avg_price(er.avg_price.value());
existing_fill.set_side(er.side);
existing_fill.set_last_shares(er.last_shares.value());
auto fv = utils::pb::to_string(existing_fill);
me->store->update(fills_ns, fk, fv);
publish(me->fill_stream, existing_fill, *er.security);
}
else
LOG(OrderMan, Warn, "Received correction for unknown fill {}", fk);
}
} // for loop
} // if u.events
}
void FillStore::on_order_definition_update(
mercury::Update<OrderDefinitionUpdateEvent> const &u) {
if (u.events)
@@ -264,6 +264,7 @@ void GLBXExecutionGateway::on_exe_report(
str_to(msg.get<fix::TransactTimeStr>(), &data->transact_time);
data->cfg = &me->cfg;
data->msg = text_msg;
data->exchange = api::Venue::VENUE_GLBX;
me->on_exe_report(*data, msg.trace());
}
}
+2 -2
View File
@@ -7,7 +7,6 @@
#include "lib/md/cme/MDP3Utils.h"
#include "lib/mercury/actors/Actor.h"
#include "lib/mercury/actors/IPollableActor.h"
#include "lib/mercury/events/TimerEvent.h"
#include "lib/orderman/events/BookUpdateEvent.h"
#include "lib/orderman/events/MDRequestEvent.h"
#include "lib/orderman/events/TickerUpdateEvent.h"
@@ -25,7 +24,8 @@ namespace orderman {
// polls a md consumer and publishes BookUpdate events when new MD is
// available. To avoid the overhead of maintaing synopsis as well as
// polling only relevant MD, observes a MDRequestEvent and limits
// updates to requested securities.
// updates to requested securities. Also provides trade and security
// status events in a similar on demand fashion.
class MDSource : public mercury::Actor, public mercury::IPollableActor {
public:
-1
View File
@@ -3,7 +3,6 @@
#include "lib/api/services/OrderService.pb.h"
#include "lib/mercury/actors/Actor.h"
#include "lib/orderman/events/StoredFillEvent.h"
#include "lib/md/SecurityOracle.h"
using namespace bts::api::orderman;
+1 -1
View File
@@ -42,7 +42,7 @@ class DynamicOrderRegistry;
} // namespace bts
// end fwds
// Provides a threading bridge between the quickbux/service world and
// Provides a threading bridge between the quickbus/service world and
// the mercury event broker.
namespace bts {
namespace orderman {
@@ -5,8 +5,8 @@
#include "lib/orderman/actors/order_manager/OrderServices.h"
#include "lib/orderman/actors/order_manager/OrderServicesData.h"
#include "lib/orderman/events/AccountPnLUpdateEvent.h"
#include "lib/orderman/events/FilledPositionEvent.h"
#include "lib/orderman/events/ExcessLiquidityUpdateEvent.h"
#include "lib/orderman/events/FilledPositionEvent.h"
#include "lib/orderman/events/NewAdminDataEvent.h"
#include "lib/orderman/events/NewSecuritiesEvent.h"
#include "lib/orderman/events/OrderManagerReadyEvent.h"
@@ -111,7 +111,8 @@ void OrderManager::on_excess_liquidity_update(
const mercury::Update<ExcessLiquidityUpdateEvent> &u) {
if (u.events)
for (auto ev : *u.events)
me->services_data.limiter.set_excess_liquidity(ev.account_id, ev.excess_liquidity);
me->services_data.limiter.set_excess_liquidity(ev.account_id,
ev.excess_liquidity);
}
void OrderManager::on_securities(
@@ -541,7 +542,7 @@ void OrderManager::init_order_services() {
std::make_unique<ContentSubscription<TickerUpdateEvent>>(
*this, on_ticker_sub, log);
me->services_data.status_subs =
std::make_unique<ContentSubscription<StatusUpdateEvent>>(
std::make_unique<ContentSubscription<StatusUpdateEvent>>(
*this, on_status_sub, log);
me->services_data.settlement_subs =
std::make_unique<ContentSubscription<SettlementUpdateEvent>>(
@@ -581,10 +582,7 @@ void OrderManager::reload_fix_buffer(SessionServicesData &osd) {
}
}
void OrderManager::on_poll(trace::PerfLog &log) {
auto scoped_do_work =
trace::log_scope(log, {}, "OrderManager::dispatch_incoming_fix_messages",
utils::TimeStamp::Interval::from_microseconds(2));
void OrderManager::on_poll(trace::PerfLog &) {
for (auto &osd : me->services_data.sessions)
osd->gw->dispatch_incoming_fix_messages();
}
@@ -2,9 +2,9 @@
#include "lib/config/protos/jetfix.pb.h"
#include "lib/jetfix/common/OutFIXPtr.h"
#include "lib/md/SecurityOracle.h"
#include "lib/mercury/actors/Actor.h"
#include "lib/mercury/actors/IPollableActor.h"
#include "lib/md/SecurityOracle.h"
#include "lib/orderman/events/ActivateOrderEvent.h"
#include "lib/orderman/events/CancelOrderEvent.h"
#include "lib/orderman/events/DetachOrderEvent.h"
@@ -64,8 +64,9 @@ namespace orderman {
class OrderManager : public mercury::Actor, public mercury::IPollableActor {
public:
OrderManager(DynamicOrderRegistry const &dyn_order_builder, trace::PerfLog &, md::SecurityOracle);
OrderManager(DynamicOrderRegistry const &, trace::PerfLog &,
md::SecurityOracle);
~OrderManager();
void init() override;
@@ -86,8 +87,9 @@ class OrderManager : public mercury::Actor, public mercury::IPollableActor {
void on_timer(const mercury::Update<mercury::TimerEvent> &);
void on_admin_data(const mercury::Update<NewAdminDataEvent> &);
void on_pnl_update(const mercury::Update<AccountPnLUpdateEvent> &);
void on_excess_liquidity_update(const mercury::Update<ExcessLiquidityUpdateEvent> &);
void on_poll(trace::PerfLog& log) override;
void on_excess_liquidity_update(
const mercury::Update<ExcessLiquidityUpdateEvent> &);
void on_poll(trace::PerfLog &log) override;
// end external events
void init_order_services();
@@ -97,8 +99,8 @@ class OrderManager : public mercury::Actor, public mercury::IPollableActor {
void after_event() override;
void add_child_order(OrderServices &parent, Order &child);
Order* lookup_order(OrderKey k);
Order *lookup_order(OrderKey k);
void publish_order_def_update(
OrderKey k,
std::shared_ptr<api::orderman::OrderDefinition const> const &def);
-65
View File
@@ -1,65 +0,0 @@
** Attach/Detach semantics
*** Semantics
- An order base definition can include a list of running orders to attach
to
- Each custom definition can have parameters that allow configuration
of the specific order type with respect to the attachment
list. Obvious configuration alternatives are:
- Attach to each of the listed orders directly or
- Forward attachment list to children
- Only orders with no parent or parents in a terminal state can be
attached to
- a detach(order_key) message can be sent to any order, even if that
order was not started through attachment to an existing order. the
expected semantics is for the order in question to stop managing the
child order and transition to completed.
*** API
- IOrderServices:
- attach_to_order(ok, std::function<void(Result,ChildOrder)>
on_attach_complete);
- detach(ChildOrder)
- Order
- on_detach(order_key)
- on_attached();
- on_detached();
message OrderDefinition {
CTICode cti_code = 9;
l CUSTOMERORFIRM customer_or_firm = 10;
OrderSubType sub_type = 12;
+ repeated uint32 attach_to_order = 13;
CustomOrderDefinition custom_def = 11;
}
* Order fields
| Field | Group | Muttable | on_attach |
|------------------------+--------------+----------+-------------|
| security_key | standard def | N | from child |
| side | | N | from child |
| user | | N | from parent |
| user_id | | Y | from parent |
| account | | Y | from parent |
| account_id | | Y | from parent |
| time_in_force | | N | from child |
| manual_order_indicator | | Y | from parent |
| cti_code | | N | from child |
| customer_or_firm | | N | from child |
| sub_type | | N | |
| attach_order | | N | |
|------------------------+--------------+----------+-------------|
| custom_def | custom_def | Y | from child |
| | | | |
|------------------------+--------------+----------+-------------|
| key | order_record | N | |
| parent_key | | Y | from parent |
|------------------------+--------------+----------+-------------|
| status | order_state | Y | |
| price | | Y | |
| quantity | | Y | |
| filled_quantity | | Y | |
| last_price | | Y | |
| avg_price | | Y | |
| last_msg | | Y | |
| created | | Y | |
| last_change | | Y | |
| custom_state | custom_state | Y | |
Binary file not shown.
@@ -5,9 +5,22 @@
| completed | O | | | |
| canceled | canceled | | | |
| error | X | | | |
| disconnected | | | | |
| disconnected | | | | |
| rejected by spark | X | | | |
* References
** Timmings
| thing | cost | note |
|-------------------------+------+----------------------|
| lock/unlock | 8 | test_and_set |
| shared_ptr cpy | 14 | |
| binary_search_int64/8 | 7 | |
| binary_search_int64/512 | 13 | |
| mem_copy/8 | 5 | |
| mem_copy/64 | 5 | |
| mem_copy/512 | 14 | |
| new/delete | 58 | |
| boost pool new/delete | 2 | no synchronizatio |
| boost pool new/delete | 19 | with synchronization |
** To Exchange
- [[https://www.cmegroup.com/confluence/display/EPICSANDBOX/New+Order][NewOrderSingle]]
- [[https://www.cmegroup.com/confluence/display/EPICSANDBOX/Order%2BCancel-Replace%2BRequest][CancelReplace]]
@@ -22,25 +35,29 @@
- Trade Correction
- [[https://www.cmegroup.com/confluence/display/EPICSANDBOX/Execution+Report+-+Trade+Correction][Msg]]
- [[https://www.cmegroup.com/confluence/display/EPICSANDBOX/Execution+Report+-+Trade+Correction][Discussion]]
* Order Chain trace
** NewOrder
** Order Chain trace
*** NewOrder
=-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-=
BeginString = FIX.4.2 8=FIX.4.2
BodyLength = 271 9=271
MsgType = NewOrderSingle 35=D
MsgSeqNum = 8026 34=8026
SenderCompID = DT9238N 49=DT9238N
SenderSubID = ROR 50=ROR
SendingTime = 20161102-20:36:47.620 52=20161102-20:36:47.620
TargetCompID = CME 56=CME
TargetSubID = 64 57=64
SenderLocationID = US,IL 142=US,IL
LastMsgSeqNumProcessed = 7374 369=7374
Account = X8CM1 1=X8CM1
ClOrdID = 2KjMkw-1C22h9-001v8Q 11=2KjMkw-1C22h9-001v8Q
HandlInst = 1 21=1
OrderQty = 1 38=1
OrdType = 2 40=2
Price = 209075 44=209075
SecurityID = 2928 48=2928
Side = 1 54=1
@@ -95,7 +112,7 @@ ExpireDate = 20161102 432=20161102
5979 = 1478119007620967425 5979=1478119007620967425
7928 = 8056218 7928=8056218
CheckSum = 038 10=038
** Cancel
*** Cancel
=-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-=
BeginString = FIX.4.2 8=FIX.4.2
BodyLength = 327 9=327
@@ -169,7 +186,7 @@ ExpireDate = 20161102 432=20161102
7928 = 8056218 7928=8056218
9717 = 2KjMkw-1C22h9-001v8Q 9717=2KjMkw-1C22h9-001v8Q
CheckSum = 033 10=033
** Cancel/Replace
*** Cancel/Replace
=-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-=
BeginString = FIX.4.2 8=FIX.4.2
BodyLength = 344 9=344
@@ -247,7 +264,7 @@ ExpireDate = 20161102 432=20161102
9717 = 2KjMkw-1C22gp-001v8P 9717=2KjMkw-1C22gp-001v8P
CheckSum = 151 10=151
** Trade Correction
*** Trade Correction
=-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-=
BeginString = FIX.4.2 8=FIX.4.2
BodyLength = 000234 9=000234
@@ -401,35 +418,7 @@ CheckSum = 207 10=207
37711 = MDTradeEntryID
ExecRefID
* Open Issues
- Re-Connection is done on the fast thread, slowing everything down
- Need to make sure there are no duplicate order state update events
- Once we have multiple OM's we will need to guarantee that they can
see each others order, which means we need to use some sort of
synopsis or other mechanism to ensure that they are synchronized
- fill mitigation
- should cancel on disconnect be on
- handling of reject
- garbage collection of orders
- garbage collection of fills
- consider including restatement reason
- see if handling of cancel rejects is any good
- impossible to shutdown orderservice at the moment
* Timmings
- 10.96.25.35
| thing | cost | note |
|-------------------------+------+----------------------|
| lock/unlock | 8 | test_and_set |
| shared_ptr cpy | 14 | |
| binary_search_int64/8 | 7 | |
| binary_search_int64/512 | 13 | |
| mem_copy/8 | 5 | |
| mem_copy/64 | 5 | |
| mem_copy/512 | 14 | |
| new/delete | 58 | |
| boost pool new/delete | 2 | no synchronizatio |
| boost pool new/delete | 19 | with synchronization |
* Notes on "A guide to spread trading futures"
** Notes on "A guide to spread trading futures"
- Correlations are discovered by traders
- Spread trading exploits correlations between securities and mean
reversion
@@ -471,47 +460,28 @@ ExecRefID
- Strategies
- Mean Reversion
* Open Issues
- Re-Connection is done on the fast thread, slowing everything down
- Need to make sure there are no duplicate order state update events
- Once we have multiple OM's we will need to guarantee that they can
see each others order, which means we need to use some sort of
synopsis or other mechanism to ensure that they are synchronized
- consider including restatement reason
- see if handling of cancel rejects is any good
- impossible to shutdown orderservice at the moment
* Event Flow
#+begin_src dot :file event_flow.pdf :cmdline -Kdot -Tpdf
digraph G {
bgcolor="transparent";
subgraph cluster_fast {
label="Fast Core";
GW
OMan
MDSrc
}
subgraph cluster_slow {
label="Slow Core";
FillStore
SecSrc
UI
OrderStore
Factory
}
OMan -> Factory [label=req]
Factory -> OMan [label=rep]
SecSrc -> GW [label=psec]
SecSrc -> OrderStore [label=psec]
SecSrc -> OMan [label=psec]
GW -> FillStore [label=xmsgs]
GW -> OMan [label=xmsgs]
OMan -> GW [label=fix]
OMan -> OrderStore [label=oupdate]
OrderStore -> OMan [label=rec_orders]
OrderStore -> UI [label=orecs]
FillStore-> UI [label=frecs]
UI -> OMan [label="crud"]
MDSrc -> OMan [label="md"]
}
#+END_SRC
#+RESULTS:
[[file:event_flow.pdf]]
| | MDSource | OManager | Timer | AsyncF | OrderStore | FillStore | SecSrc | MdSup | Bridge |
|------------+----------+----------+-------+--------+------------+-----------+--------+-------+--------|
| MSource | | | | | | | | | |
| OManager | | | | | | | | | |
| Timer | | | | | | | | | |
| AsyncF | | | | | | | | | |
| OrderStore | | | | | | | | | |
| FillStore | | | | | | | | | |
| SecSrc | | | | | | | | | |
| MdSup | | | | | | | | | |
| Bridge | | | | | | | | | |
|------------+----------+----------+-------+--------+------------+-----------+--------+-------+--------|
* Better event broker:
** unbundle events from topics and synopsis.
- develop Channels = Channel<Event,Tag,Synopsis>
@@ -560,3 +530,4 @@ digraph G {
- Recovery from disk
- Jetfix gateway threading model is wrong, cannot take one thread for
each session
* Rewrite <2019-09-23 Mon>
-25
View File
@@ -1,25 +0,0 @@
#pragma once
#include <memory>
#include "lib/mercury/events/Event.h"
#include "lib/orderman/orderman_utils/orderman_common.h"
#include "lib/tracing/PerfLog.h"
namespace bts {
namespace orderman {
class DetachOrderEvent : public mercury::Event<DetachOrderEvent> {
public:
using SynopsisPolicy = mercury::NoSynopsis;
DetachOrderEvent(uint32_t req_id, OrderKey k)
: req_id(req_id), k(k) {}
uint32_t req_id;
// used by ContentSubscription
OrderKey key() const { return k; }
OrderKey k;
};
} // namespace orderman
} // namespace bts
+34 -23
View File
@@ -1,48 +1,59 @@
#pragma once
#include <memory>
#include "lib/utils/bts_chrono.h"
#include <memory>
namespace bts {
namespace orderman {
class Governor
{
public:
Governor(uint32_t max_msgs_window,
uint32_t window_duration_msecs,
TimeStamp now = Timer::now()) :
_max_msgs_window(max_msgs_window),
_window_duration_msecs(window_duration_msecs),
_start_of_window(now),
_msgs_in_window(0)
{}
bool can_send(TimeStamp now = Timer::now()) const
{
class Governor {
public:
Governor() {
init(std::numeric_limits<uint32_t>::max(),
std::numeric_limits<uint32_t>::max(), Timer::now());
}
Governor(uint32_t max_msgs_window, uint32_t window_duration_msecs,
TimeStamp now = Timer::now()) {
init(max_msgs_window, window_duration_msecs, now);
}
void init(uint32_t max_msgs_window, uint32_t window_duration_msecs,
TimeStamp now) {
_max_msgs_window = max_msgs_window;
_window_duration_msecs = window_duration_msecs;
_start_of_window = now;
}
bool can_send(TimeStamp now = Timer::now()) const {
if (in_window(now))
return _msgs_in_window < _max_msgs_window;
else
return true;
}
void record_sent(TimeStamp now = Timer::now()) {
void record_sent(bool rate_limited, TimeStamp now = Timer::now()) {
if (!in_window(now)) {
_start_of_window = now;
_msgs_in_window = 0;
}
_msgs_in_window++;
_msgs_in_window += rate_limited;
}
private:
bool in_window(TimeStamp now) const {
return ms_diff (now, _start_of_window) <= _window_duration_msecs;
void record_sent(TimeStamp now = Timer::now()) {
record_sent(true, now);
}
private:
bool in_window(TimeStamp now) const {
return ms_diff(now, _start_of_window) <= _window_duration_msecs;
}
uint32_t _max_msgs_window;
uint32_t _window_duration_msecs;
TimeStamp _start_of_window;
uint64_t _msgs_in_window;
};
}}
} // namespace orderman
} // namespace bts
+4 -2
View File
@@ -5,7 +5,9 @@ namespace orderman {
LimitStore::LimitStore(const bts::api::admin::AdminData &admin_data,
const std::map<uint32_t, api::Security const *> &sec_map)
: _admin_data(bts::admin::AdminServiceUtils::sort_limits(admin_data)) {
: _admin_data(bts::admin::AdminServiceUtils::sort_limits(admin_data)),
_margin_enabled(config::get<bts::config::SpanMargin>().enabled())
{
for (const auto& acct : _admin_data.accounts())
_account_data_map.insert(std::pair<uint32_t,AccountData>(
acct.id(),AccountData(acct)));
@@ -110,4 +112,4 @@ LimitStore::test_only_func_find_product_node(AccountID account_id,
return nullptr;
}
} // namespace orderman
} // namespace bts
} // namespace bts
+2 -1
View File
@@ -72,6 +72,7 @@ private:
// this is passed over to the SecurityLimitTree
// entried (above)
std::vector<ProductLimitTree> _prod_map;
bool _margin_enabled;
const bts::api::admin::AccountProductPositionLimitUnit _zero_product_limit;
public:
LimitStore(const bts::api::admin::AdminData& admin_data,
@@ -298,7 +299,7 @@ private:
if(account_ptr != nullptr){
const auto& account_data = *account_ptr;
const auto& account = account_data.account;
if(config::get<bts::config::SpanMargin>().enabled()) {
if(_margin_enabled) {
if (account.has_margin_limit() && account.margin_limit().enforce_margin()){
double ex_liq = account_data.excess_liquidity;
if(os::is_nan(ex_liq)){
@@ -18,12 +18,6 @@ struct DynamicOrderRegistry::PImpl {
DynamicOrderRegistry::DynamicOrderRegistry() : me(new PImpl()) {}
DynamicOrderRegistry::~DynamicOrderRegistry() {}
void DynamicOrderRegistry::register_dynamic_order(
api::orderman::DynamicOrderDescriptor const &desc,
DynamicOrderBuilder const &b) {
me->dyn_orders[desc.dynamic_order_type()] = std::make_pair(b, desc);
}
void DynamicOrderRegistry::register_dynamic_algo_order(
api::orderman::DynamicOrderDescriptor const &desc,
DynamicAlgoBuilder const &b) {
@@ -13,11 +13,6 @@ class DynamicOrderRegistry {
DynamicOrderRegistry();
~DynamicOrderRegistry();
// deprecated
void
register_dynamic_order(api::orderman::DynamicOrderDescriptor const &desc,
DynamicOrderBuilder const &builder);
void register_dynamic_algo_order(
api::orderman::DynamicOrderDescriptor const &desc,
DynamicAlgoBuilder const &builder);
@@ -15,6 +15,14 @@ namespace orderman {
class DynamicOrderRegistry;
class OrderOpResultEvent;
// Inputs:
// - order maintenance rpc calls from the shell
// - admin data from the admin service
// - position data from the position service
// - margin data from the margin service
// Outputs:
// - order state
// - fills
class OrderServiceServer : public api::orderman::OrderServiceBase {
public:
OrderServiceServer(bts::api::ServiceContext &context,
+122
View File
@@ -0,0 +1,122 @@
// #include "lib/orderman_v2/OrderManEngine.h"
// #include "lib/config/protos/orderman_cfg.pb.h"
// #include "lib/md/MDConsumer.h"
// #include "lib/orderman_v2/Thread.h"
// #include "lib/orderman_v2/components.h"
// #include <fmt/format.h>
// namespace bts {
// namespace orderman_v2 {
// struct ThreadRec {
// ThreadRec(config::OrderManThreadingCfg::Thread const &t_cfg)
// : thread(t_cfg.name(), t_cfg.poll()), cfg(t_cfg) {}
// Thread thread;
// config::OrderManThreadingCfg::Thread cfg;
// };
// struct MDSourceOM {
// MDSourceOM(md::MDConsumer &md) : md_source(md), manager() {}
// MDSource md_source;
// OrderManager manager;
// };
// struct OrderManEngine::PImpl {
// PImpl(md::MDConsumer &md) : md_consumer(md) {}
// std::map<std::string, std::unique_ptr<ThreadRec>> threads;
// Component<ServiceBridge> service_bridge;
// Component<Storage> storage;
// std::vector<Component<MDSourceOM>> order_managers;
// std::vector<Component<Gateway>> gateways;
// md::MDConsumer &md_consumer;
// };
// OrderManEngine::OrderManEngine(md::MDConsumer &md,
// config::OrderManThreadingCfg const &cfg)
// : me(new PImpl(md)) {
// init_threads(cfg);
// init_components();
// }
// void OrderManEngine::init_threads(config::OrderManThreadingCfg const &cfg) {
// for (auto const &t_cfg : cfg.thread()) {
// auto &thread_ptr = me->threads[t_cfg.name()];
// bts_assert_msg(
// !thread_ptr,
// fmt::format("Duplicate thread name {} in OrderManThreading "
// "configuration key",
// t_cfg.name()));
// thread_ptr = std::make_unique<ThreadRec>(t_cfg);
// }
// bts_assert("No threads in OrderManThreading configuration key");
// }
// void OrderManEngine::init_components() {
// for (auto const &p : me->threads) {
// auto const &tr = p.second;
// for (auto const &c : tr->cfg.component()) {
// if (c.name() == "service_bridge") {
// bts_assert_msg(!me->service_bridge.component,
// "Duplicate service_bridge component found in "
// "OrderManThreading configuration key");
// me->service_bridge.thread = &tr->thread;
// me->service_bridge.component = std::make_unique<ServiceBridge>();
// continue;
// }
// if (c.name() == "storage") {
// bts_assert_msg(!me->storage.component,
// "Duplicate storage component found in "
// "OrderManThreading configuration key");
// me->storage.thread = &tr->thread;
// me->storage.component = std::make_unique<Storage>();
// continue;
// }
// if (c.name() == "order_manager") {
// auto md_om = std::make_unique<MDSourceOM>(me->md_consumer);
// Component<MDSourceOM> c{std::move(md_om), &tr->thread};
// me->order_managers.emplace_back(std::move (c));
// continue;
// }
// if (c.name() == "gateway") {
// bts_assert_msg(
// c.arg_size() == 1,
// "Gateway component should have a single jetfix session "
// "name (arg: jf_session_name) in OrderManThreading"
// "configuration key");
// auto gw = std::make_unique<Gateway>(c.arg(0));
// Component<Gateway> c{std::move(gw), &tr->thread};
// me->gateways.emplace_back(std::move(c));
// continue;
// }
// }
// bts_assert_msg(me->service_bridge.component,
// "Missing service_bridge component in OrderManThreading "
// "configuration key");
// bts_assert_msg(
// me->storage.component,
// "Missing storage component in OrderManThreading configuration key");
// bts_assert_msg(
// me->order_managers.size(),
// "At least a order_manager component is required in OrderManThreading"
// "configuration key");
// bts_assert_msg(me->order_managers.size(),
// "At least a gateway component is required in "
// "OrderManThreading configuration key");
// }
// }
// } // namespace orderman_v2
// } // namespace bts
+27
View File
@@ -0,0 +1,27 @@
#pragma once
#include <memory>
#include <vector>
namespace bts {
namespace config {class OrderManThreadingCfg;}
namespace orderman_v2 {
class Thread;
class OrderManEngine {
public:
OrderManEngine(config::OrderManThreadingCfg const&);
~OrderManEngine();
void start();
void stop ();
private:
struct PImpl;
std::unique_ptr<PImpl> me;
void init_threads(config::OrderManThreadingCfg const&cfg);
void init_components();
void link_components();
};
}}
+126
View File
@@ -0,0 +1,126 @@
// #include "lib/orderman_v2/OrderManScheduler.h"
// #include "lib/config/protos/orderman_cfg.pb.h"
// #include "lib/md/MDConsumer.h"
// #include "lib/orderman_v2/Thread.h"
// #include "lib/orderman_v2/components.h"
// #include <fmt/format.h>
// namespace bts {
// namespace orderman_v2 {
// struct ThreadRec {
// ThreadRec(config::OrderManThreadingCfg::Thread const &t_cfg)
// : thread(t_cfg.name(), t_cfg.poll()), cfg(t_cfg) {}
// Thread thread;
// config::OrderManThreadingCfg::Thread cfg;
// };
// struct MDSourceOM {
// MDSourceOM(md::MDConsumer &md) : md_source(md), manager() {}
// MDSource md_source;
// OrderManager manager;
// };
// template <class C> struct Component {
// std::unique_ptr<C> component;
// Thread *thread;
// };
// struct OrderManScheduler::PImpl {
// PImpl(md::MDConsumer &md) : md_consumer(md) {}
// std::map<std::string, std::unique_ptr<ThreadRec>> threads;
// Component<ServiceBridge> service_bridge;
// Component<Storage> storage;
// std::vector<Component<MDSourceOM>> order_managers;
// std::vector<Component<Gateway>> gateways;
// md::MDConsumer &md_consumer;
// };
// OrderManScheduler::OrderManScheduler(md::MDConsumer &md,
// config::OrderManThreadingCfg const &cfg)
// : me(new PImpl(md)) {
// init_threads(cfg);
// init_components();
// }
// void OrderManScheduler::init_threads(config::OrderManThreadingCfg const &cfg) {
// for (auto const &t_cfg : cfg.thread()) {
// auto &thread_ptr = me->threads[t_cfg.name()];
// bts_assert_msg(
// !thread_ptr,
// fmt::format("Duplicate thread name {} in OrderManThreading "
// "configuration key",
// t_cfg.name()));
// thread_ptr = std::make_unique<ThreadRec>(t_cfg);
// }
// bts_assert("No threads in OrderManThreading configuration key");
// }
// void OrderManScheduler::init_components() {
// for (auto const &p : me->threads) {
// auto const &tr = p.second;
// for (auto const &c : tr->cfg.component()) {
// if (c.name() == "service_bridge") {
// bts_assert_msg(!me->service_bridge.component,
// "Duplicate service_bridge component found in "
// "OrderManThreading configuration key");
// me->service_bridge.thread = &tr->thread;
// me->service_bridge.component = std::make_unique<ServiceBridge>();
// continue;
// }
// if (c.name() == "storage") {
// bts_assert_msg(!me->storage.component,
// "Duplicate storage component found in "
// "OrderManThreading configuration key");
// me->storage.thread = &tr->thread;
// me->storage.component = std::make_unique<Storage>();
// continue;
// }
// if (c.name() == "order_manager") {
// auto md_om = std::make_unique<MDSourceOM>(me->md_consumer);
// Component<MDSourceOM> c{std::move(md_om), &tr->thread};
// me->order_managers.emplace_back(std::move (c));
// continue;
// }
// if (c.name() == "gateway") {
// bts_assert_msg(
// c.arg_size() == 1,
// "Gateway component should have a single jetfix session "
// "name (arg: jf_session_name) in OrderManThreading"
// "configuration key");
// auto gw = std::make_unique<Gateway>(c.arg(0));
// Component<Gateway> c{std::move(gw), &tr->thread};
// me->gateways.emplace_back(std::move(c));
// continue;
// }
// }
// bts_assert_msg(me->service_bridge.component,
// "Missing service_bridge component in OrderManThreading "
// "configuration key");
// bts_assert_msg(
// me->storage.component,
// "Missing storage component in OrderManThreading configuration key");
// bts_assert_msg(
// me->order_managers.size(),
// "At least a order_manager component is required in OrderManThreading"
// "configuration key");
// bts_assert_msg(me->order_managers.size(),
// "At least a gateway component is required in "
// "OrderManThreading configuration key");
// }
// }
// } // namespace orderman_v2
// } // namespace bts
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include <memory>
#include <vector>
namespace bts {
namespace md {class MDConsumer;}
namespace config {class OrderManThreadingCfg;}
namespace orderman_v2 {
class Thread;
class OrderManScheduler {
public:
OrderManScheduler(md::MDConsumer &,config::OrderManThreadingCfg const&);
~OrderManScheduler();
void start();
void stop ();
private:
struct PImpl;
std::unique_ptr<PImpl> me;
void init_threads(config::OrderManThreadingCfg const&cfg);
void init_components();
void link_components();
};
}}
+14
View File
@@ -0,0 +1,14 @@
#include "Actor.h"
#include "lib/orderman_v2/interconnect/Thread.h"
namespace bts {
namespace orderman_v2 {
Actor::~Actor() {}
Queue* Actor::get_target_queue(Actor &target_actor) {
return target_actor._owner_thread->get_queue(*_owner_thread);
}
}}
+25
View File
@@ -0,0 +1,25 @@
#pragma once
namespace bts {
namespace orderman_v2 {
class Queue;
class Thread;
class Actor {
public:
virtual ~Actor() ;
virtual void init() {}
virtual void finit() {}
private:
friend class Thread;
template <class A> friend class Signal;
// Returns nullptr is the this actor and the target are on the same thread
Queue* get_target_queue(Actor &target_actor);
void set_owner_thread(Thread &owner) { _owner_thread = &owner; }
Thread *_owner_thread = nullptr;
};
} // namespace orderman_v2
} // namespace bts
+10
View File
@@ -0,0 +1,10 @@
#include "MDSource.h"
namespace bts {
namespace orderman_v2 {
MDSource::MDSource(md::MDConsumer &)
: on_book(this), on_ticker(this), on_sec_status(this) {}
} // namespace orderman_v2
} // namespace bts
+27
View File
@@ -0,0 +1,27 @@
#pragma once
#include "Actor.h"
#include "lib/orderman_v2/events/events.h"
#include "lib/orderman_v2/common.h"
#include "lib/orderman_v2/interconnect/Signal.h"
namespace bts {
namespace md {class MDConsumer;}
namespace orderman_v2 {
class MDSource : public Actor {
public:
MDSource(md::MDConsumer &consumer) ;
// Inputs
void on_md_request(MDRequest const&) {};
// Signals
Signal<BookUpdate> on_book;
Signal<TickerUpdate> on_ticker;
Signal<SecurityStatusUpdate> on_sec_status;
};
}}
@@ -0,0 +1,11 @@
#include "OrderManager.h"
namespace bts {
namespace orderman_v2 {
OrderManager::OrderManager()
: on_gw_op(this), on_order_update(this), on_om_reply(this),
on_md_request(this), on_om_bootstrap_orders(this) {}
} // namespace orderman_v2
} // namespace bts
+36
View File
@@ -0,0 +1,36 @@
#pragma once
#include "Actor.h"
#include "lib/orderman_v2/events/events.h"
#include "lib/orderman_v2/common.h"
#include "lib/orderman_v2/interconnect/Signal.h"
namespace bts {
namespace orderman_v2 {
class OrderManager : public Actor {
public:
OrderManager();
// Inputs
void on_bootstrap_orders(BootstrapOrders) {}
void on_native_order_update (GW_OrderReport const&) {}
void on_unknown_native_order_update(GW_UnknownOrderExeReport const&) {}
void on_create_order (CreateOrderRequest const&) {}
void on_update_order (UpdateOrderRequest const&) {}
void on_cancel_order (CancelOrderRequest const&) {}
void on_detach_order (DetachOrderRequest const&) {}
void on_book(BookUpdate const&) {}
void on_ticker(TickerUpdate const&) {}
void on_sec_status(SecurityStatusUpdate const&) {}
void on_admin_data(const AdminDataUpdate &) {}
// Signals
Signal<GW_Op_Batch> on_gw_op;
Signal<OM_OrderUpdate> on_order_update;
Signal<OM_Reply> on_om_reply;
Signal<MDRequest> on_md_request;
Signal<OM_BootstrapOrders> on_om_bootstrap_orders;
};
}}
@@ -0,0 +1,18 @@
#include "ServiceBridge.h"
namespace bts {
namespace orderman_v2 {
ServiceBridge::ServiceBridge() :
on_create_order(this),
on_update_order(this),
on_cancel_order(this),
on_detach_order(this),
on_admin_data(this),
on_excess_liquidity(this),
on_account_pnl(this),
on_position(this)
{}
} // namespace orderman_v2
} // namespace bts
@@ -0,0 +1,37 @@
#pragma once
#include "Actor.h"
#include "lib/orderman_v2/events/events.h"
#include "lib/orderman_v2/common.h"
#include "lib/orderman_v2/interconnect/Signal.h"
namespace bts {
namespace orderman_v2 {
class ServiceBridge : public Actor {
public:
ServiceBridge();
// Inputs
void on_bootstrap_orders(BootstrapOrders) {}
void on_bootstrap_fills(BootstrapFills) {}
void on_new_stored_order(api::orderman::OrderRecord const*) {}
void on_new_stored_fill(api::orderman::Fill const*) {}
void on_gw_status(GW_Status const&) {}
void on_gw_error(GW_Error const&) {}
void on_om_reply(OM_Reply const&) {}
// Signals
Signal<CreateOrderRequest> on_create_order;
Signal<UpdateOrderRequest> on_update_order;
Signal<CancelOrderRequest> on_cancel_order;
Signal<DetachOrderRequest> on_detach_order;
Signal<AdminDataUpdate> on_admin_data;
Signal<ExcessLiquidityUpdate> on_excess_liquidity;
Signal<AccountPnLUpdate> on_account_pnl;
Signal<PositionUpdate> on_position;
};
}}
+12
View File
@@ -0,0 +1,12 @@
#include "Storage.h"
namespace bts {
namespace orderman_v2 {
Storage::Storage()
: on_bootstrap_orders(this), on_venue_checkpoint(this),
on_bootstrap_fills(this), on_new_stored_order(this),
on_new_stored_fill(this) {}
} // namespace orderman_v2
} // namespace bts
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include "Actor.h"
#include "lib/orderman_v2/events/events.h"
#include "lib/orderman_v2/common.h"
#include "lib/orderman_v2/interconnect/Signal.h"
namespace bts {
namespace orderman_v2 {
class Storage : public Actor {
public:
Storage();
// Inputs
void on_order_update (OM_OrderUpdate const&) {}
// Signals
Signal<BootstrapOrders> on_bootstrap_orders;
Signal<VenueCheckpointNotice> on_venue_checkpoint;
Signal<BootstrapFills> on_bootstrap_fills;
Signal<api::orderman::OrderRecord const*> on_new_stored_order;
Signal<api::orderman::Fill const*> on_new_stored_fill;
};
}}
@@ -0,0 +1,25 @@
#pragma once
#include "lib/orderman_v2/common.h"
#include "lib/orderman_v2/actors/gateway/fix/VenueCheckpoint.h"
namespace bts {
namespace orderman_v2 {
class IFullExeReportMsg;
class ExecReport {
public:
OrderKey order_key;
Quantity quantity;
Quantity total_fills;
Quantity last_fills;
Price price;
Price avg_price;
Price last_price;
OrderStatus status;
VenueCheckpoint checkpoint;
IFullExeReportMsg const *msg;
};
}}
@@ -0,0 +1,608 @@
#include "Gateway.h"
#include "lib/logging/logging.h"
#include "lib/orderman/limiter/Limiter.h"
#include "lib/orderman_v2/actors/gateway/ICancelMsg.h"
#include "lib/orderman_v2/actors/gateway/ICancelReplaceMsg.h"
#include "lib/orderman_v2/actors/gateway/ILimiter.h"
#include "lib/orderman_v2/actors/gateway/INewOrderSingleMsg.h"
#include "lib/orderman_v2/actors/gateway/IRouter.h"
#include "lib/orderman_v2/actors/gateway/IVenue.h"
#include "lib/orderman_v2/actors/gateway/UserAccountVenue.h"
#include "lib/orderman_v2/utils/FAFStore.h"
#include "lib/utils/bts_chrono.h"
#include <boost/pool/object_pool.hpp>
#include <unordered_map>
namespace bts {
namespace orderman_v2 {
// utilities
template <class Req> GW_Op_Ack make_ack(Req const &r) {
return GW_Op_Ack{GW_OP_Result::OK, r.req_id, nullptr};
}
struct Gateway::OrderRec {
OrderRec() = default;
OrderRec(OM_ID om_id, GW_BoundOrder const &order)
: order(order), originator(om_id), last_ack(), routing_record(nullptr) {}
GW_BoundOrder order;
OM_ID originator;
GW_Op_Ack last_ack;
api::orderman::RoutingRecord const *routing_record;
bool is_routable() const { return routing_record != nullptr; }
void mark_non_routable() { routing_record = nullptr; }
};
class Gateway::OrderMap {
public:
OrderRec *lookup(OrderKey k) { return _store.lookup(k.value); }
OrderRec *make_and_store(OM_ID om_id, GW_BoundOrder const &bo) {
return _store.make_and_index(bo.key.value, om_id, bo);
}
void remove(OrderKey k) { _store.remove(k.value); }
std::vector<OrderRec *> get_all() { return _store.get_all(); }
private:
FAFStore<OrderRec> _store;
};
enum class Gateway::State {
W_BOOTSTRAP,
W_SCHEDULE,
PAUSED,
W_LOGON,
READY,
};
struct Gateway::Hot {
using RoutingRecordsMap =
std::unordered_map<UserAccountVenue, api::orderman::RoutingRecord,
UserAccountVenueHash>;
Hot(IVenue &v, ILimiter &l)
: state(State::W_BOOTSTRAP), venue(v), limiter(l), working_orders(),
routing_records() {}
State state;
IVenue &venue;
ILimiter &limiter;
// TODO: Separate orders that cannot be routed from working orders
// to avoid the if is_routable() on order events
OrderMap working_orders;
RoutingRecordsMap routing_records;
};
struct Gateway::Cold {
Cold(IRouter &r, IClock &c, GatewayCfg const &cfg)
: router(r), clock(c), admin_data(), cfg(cfg), start_of_pause(),
current_exponential_backoff(0), bootstrap_orders(),
interned_strings() {}
IRouter &router;
IClock &clock;
api::admin::AdminData const *admin_data;
GatewayCfg cfg;
TimeStamp start_of_pause;
size_t current_exponential_backoff;
SessionSpan session_span;
std::map<OM_ID, std::vector<GW_OrderBind> *> bootstrap_orders;
std::set<std::string> interned_strings;
};
struct Gateway::PImpl {
PImpl(IVenue &v, ILimiter &l, IRouter &r, IClock &c, GatewayCfg const &cfg)
: hot(v, l), cold(r, c, cfg) {}
Hot hot;
Cold cold;
};
Gateway::Gateway(IVenue &v, ILimiter &l, IRouter &r, IClock &c,
GatewayCfg const &cfg)
: on_order_report(this), on_unknown_native_order_update(this),
on_gw_error(this), me(new PImpl(v, l, r, c, cfg)) {
me->hot.venue.set_observer(*this);
}
Gateway::~Gateway() {}
void Gateway::do_slow_work() {
switch (me->hot.state) {
case State::W_BOOTSTRAP:
if (has_bootstrap_data()) {
setup_bootstrap_orders();
transition(State::W_SCHEDULE);
}
break;
case State::W_SCHEDULE:
me->cold.session_span = me->hot.venue.get_current_session_span();
if (in_active_schedule()) {
me->cold.start_of_pause = me->cold.clock.now();
transition(State::PAUSED);
}
break;
case State::PAUSED: {
auto now = me->cold.clock.now();
if (sec_diff(now, me->cold.start_of_pause) >
(me->cold.cfg.pause_seconds
<< me->cold.current_exponential_backoff)) {
transition(State::W_LOGON);
me->hot.venue.login();
}
break;
}
case State::READY: {
break;
}
case State::W_LOGON:
break;
}
me->hot.venue.do_work();
}
void Gateway::on_om_bootstrap_orders(OM_BootstrapOrders const &orders) {
bts_assert(me->hot.state == State::W_BOOTSTRAP);
auto &bso_map = me->cold.bootstrap_orders;
bts_assert(bso_map.size() < me->cold.cfg.om_count);
bts_assert(bso_map.count(orders.originator) == 0);
bts_assert(orders.target == me->cold.cfg.my_id);
bts_assert(orders.originator.value < me->cold.cfg.om_count);
bso_map[orders.originator] = orders.orders;
}
void Gateway::on_gw_ops(const GW_Op_Batch &op_batch) {
op_batch.visit(*this);
me->hot.venue.send_queued_msgs();
}
void Gateway::on_account_pnl(const AccountPnLUpdate &pnl) {
me->hot.limiter.update(pnl);
}
void Gateway::on_position(const PositionUpdate &pos) {
me->hot.limiter.update(pos);
}
void Gateway::on_excess_liquidity(const ExcessLiquidityUpdate &l) {
me->hot.limiter.update(l);
}
void Gateway::on_admin_data(AdminDataUpdate const &admin) {
me->hot.limiter.update(*me->cold.admin_data);
me->cold.router.update(*me->cold.admin_data);
me->hot.routing_records.clear();
switch (me->hot.state) {
case State::W_BOOTSTRAP:
me->cold.admin_data = admin.admin_data;
break;
default:
rebuild_routing_records();
}
}
void Gateway::on_venue_checkpoint(const VenueCheckpointNotice &notice) {
me->hot.venue.set_checkpoint(notice.checkpoint);
}
void Gateway::on_venue_login_success(std::vector<ExecReport> const &recovered) {
bts_assert(me->hot.state == State::W_LOGON);
me->cold.current_exponential_backoff = 0;
transition(State::READY);
for (auto const &er : recovered)
on_venue_exe_report(er);
}
void Gateway::on_venue_login_failure() {
bts_assert(me->hot.state == State::W_LOGON);
if (in_active_schedule()) {
me->cold.current_exponential_backoff++;
transition(State::PAUSED);
} else {
me->cold.current_exponential_backoff = 0;
transition(State::W_SCHEDULE);
}
}
void Gateway::on_venue_disconnect() {
bts_assert(me->hot.state == State::READY);
auto all_working = me->hot.working_orders.get_all();
for (auto orec : all_working) {
GW_Error error;
error.gw = me->cold.cfg.my_id;
error.error_code = GW_Error::DISCONNECT;
error.error_msg = "Venue disconnected";
error.order_key = orec->order.key;
on_gw_error(error);
}
}
void Gateway::on_venue_exe_report(const ExecReport &report) {
bts_assert(me->hot.state == State::READY);
auto r = me->hot.working_orders.lookup(report.order_key);
if (r) {
// This is an order we have seen before. This is the normal
// path.
r->order.last_exe_report = report;
// If the order is no longer working then we remove it from the
// working index.
if (report.status != OrderStatus::WORKING)
me->hot.working_orders.remove(report.order_key);
on_order_report(make_order_report(r));
} else if (report.status == OrderStatus::WORKING) {
auto sec = me->hot.venue.resolve_security(report);
if (sec)
on_unknown_native_order_update({sec, me->cold.cfg.my_id, report});
}
}
void Gateway::on_venue_error(VenueError const &v_error) {
GW_Error gw_error;
switch (v_error.error_code) {
case VenueError::CANCEL_REJECT:
gw_error.error_code = GW_Error::CANCEL_REJECT;
break;
case VenueError::BUSINESS_REJECT:
gw_error.error_code = GW_Error::BUSINESS_REJECT;
break;
case VenueError::SESSION_REJECT:
gw_error.error_code = GW_Error::SESSION_REJECT;
break;
default:
gw_error.error_code = GW_Error::OTHER;
break;
}
gw_error.error_msg = intern_string(v_error.error_msg);
gw_error.order_key = v_error.order_key;
on_gw_error(gw_error);
}
void Gateway::on_gw_op(OM_ID om_id, const GW_OrderCreate &create) {
bts_assert_d(me->hot.working_orders.lookup(create.bound_order.key) ==
nullptr);
// Construct new order record
auto gw_rec =
me->hot.working_orders.make_and_store(om_id, create.bound_order);
auto &order = gw_rec->order;
auto &ack = gw_rec->last_ack;
ack = make_ack(create);
switch (me->hot.state) {
case State::READY: {
// Validate route
auto it = me->hot.routing_records.find(order.uav);
if (it == me->hot.routing_records.end()) {
ack.result = GW_OP_Result::ERROR_NO_ROUTE;
break;
} else
gw_rec->routing_record = &it->second;
// Validate risk limit
auto lqt = me->hot.limiter.can_send_new_order(
order.uav.account, *order.security, order.side, order.quantity);
if (lqt.error()) {
ack.result = lqt.result;
ack.message = lqt.message;
break;
}
// Validate messaging limits
if (!me->hot.venue.under_messaging_limit()) {
ack.result = GW_OP_Result::ERROR_MESSAGING_BREACH;
break;
}
// TODO: Replace the chained ifs with accumulated error flags
// and check them once, to avoid pressure on the branch
// predictor.
// All is good. Queue for send.
me->hot.venue.queue_send(gw_rec->order, *gw_rec->routing_record);
// For speed we do not send acks for the operation until we hear
// from the exchange.
return;
}
default:
ack.result = GW_OP_Result::ERROR_GATEWAY_DISCONNECTED;
break;
}
// If we got to this point something went wrong and the creation of
// the order failed. Since the order is already indexed we need to
// remove it from the store. Additionally, because we will never
// hear from the exchange on this order we have to send our ack
// now. This is an exceptional path, it should almost never happen.
bts_assert_d(ack.result != GW_OP_Result::OK);
auto report = make_order_report(gw_rec);
me->hot.working_orders.remove(order.key);
on_order_report(report);
}
// When an order is recovered from disk or from the exchange (meaning
// the exchange sends a report for an order we do not have a record of
// creating) we are left in a situation where we have to create the
// order record that represents the order but we do not have to
// actually send the order to the exchange. This is what the bind
// order operation is for.
void Gateway::on_gw_op(OM_ID om_id, const GW_OrderBind &bind) {
bts_assert_d(me->hot.working_orders.lookup(bind.bound_order.key) == nullptr);
// Construct new order record
auto gw_rec = me->hot.working_orders.make_and_store(om_id, bind.bound_order);
auto &order = gw_rec->order;
auto &ack = gw_rec->last_ack;
ack = make_ack(bind);
// Find the routing record for this order
auto it = me->hot.routing_records.find(order.uav);
if (it == me->hot.routing_records.end())
ack.result = GW_OP_Result::ERROR_NO_ROUTE;
else
gw_rec->routing_record = &it->second;
// In this case we have to send a reply to the bind operation
// because there is no guarantee that we will be able to piggy back
// the reply on the next exchange acknowledgement (which may never
// come).
on_order_report(make_order_report(gw_rec));
}
// A quick update is an update of just price and quantity. This is the
// most common type of order change so we special case it so that we
// can re-use the update message fields that will not change (which is
// everything but quantity and price)
void Gateway::on_gw_op(OM_ID, const GW_OrderQuickUpdate &quick_update) {
auto gw_rec = me->hot.working_orders.lookup(quick_update.order_key);
auto &ack = gw_rec->last_ack;
ack = make_ack(quick_update);
switch (me->hot.state) {
case State::READY: {
// Do we know about this order?
if (!gw_rec) {
ack.result = GW_OP_Result::ERROR_ORDER_IS_NOT_ACTIVE;
break;
}
// Can we route it?
if (!gw_rec->is_routable()) {
ack.result = GW_OP_Result::ERROR_NO_ROUTE;
break;
}
auto &order = gw_rec->order;
// Validate trading limits
auto delta_q = quick_update.quantity.value - order.quantity.value;
auto lqr = me->hot.limiter.can_update_order(
order.uav.account, *order.security, order.side, delta_q);
if (lqr.error()) {
ack.result = lqr.result;
ack.message = lqr.message;
break;
}
// Validate messaging limits
if (!me->hot.venue.under_messaging_limit()) {
ack.result = GW_OP_Result::ERROR_MESSAGING_BREACH;
break;
}
order.price = quick_update.price;
order.quantity = quick_update.quantity;
me->hot.venue.queue_update(gw_rec->order, *gw_rec->routing_record);
// We do not send out a order report for performance
// reasons. Instead we delay the report until the exchange
// reponds our order update.
return;
}
default:
ack.result = GW_OP_Result::ERROR_GATEWAY_DISCONNECTED;
break;
}
// If we got here something went wrong and the update failed. This
// is the exceptional path and it should almost never happen. In
// this case we send out a new order report detailing the reasons
// for the failure.
bts_assert(ack.result != GW_OP_Result::OK);
on_order_report(make_order_report(gw_rec));
}
// The difference between a full update and a quick update is that in
// a full update we allow for any change including the account/user
// associated with the order. This could change the routing of the
// order so we need to retrieve a (possibly new) routing record.
void Gateway::on_gw_op(OM_ID om_id, const GW_OrderFullUpdate &full_update) {
auto gw_rec = me->hot.working_orders.lookup(full_update.order_key);
auto &ack = gw_rec->last_ack;
ack = make_ack(full_update);
switch (me->hot.state) {
case State::READY: {
// Do we know about this order?
if (!gw_rec) {
ack.result = GW_OP_Result::ERROR_ORDER_IS_NOT_ACTIVE;
break;
}
// Can we route it?
if (!gw_rec->is_routable()) {
ack.result = GW_OP_Result::ERROR_NO_ROUTE;
break;
}
auto &order = gw_rec->order;
auto it = me->hot.routing_records.find(order.uav);
if (it == me->hot.routing_records.end()) {
gw_rec->mark_non_routable();
ack.result = GW_OP_Result::ERROR_NO_ROUTE;
break;
} else
gw_rec->routing_record = &it->second;
// Update existing record with the non quick parts of the full
// order update. There is a bit of inconsistency here. We are
// already setting the message templates, uav, moi and tif
// fields below, even though the quick update might later fail
// to set the quantity and price. This could leave the order in
// a half-updated half not-updated state. This should be rare
// and benign enough so we live with it to avoid duplicating the
// update logic from quick update here.
gw_rec->order.uav = full_update.uav;
gw_rec->order.moi = full_update.moi;
gw_rec->order.tif = full_update.tif;
// Fake a quick update, now that we already set the other fields
GW_OrderQuickUpdate quick_update;
quick_update.order_key = full_update.order_key;
quick_update.quantity = full_update.quantity;
quick_update.price = full_update.price;
quick_update.req_id = full_update.req_id;
on_gw_op(om_id, quick_update);
break;
}
default:
ack.result = GW_OP_Result::ERROR_GATEWAY_DISCONNECTED;
break;
}
// If we got to this point something went wrong and the update of
// the order failed. This should be very rare. In this case we send
// a reply right away.
bts_assert(ack.result != GW_OP_Result::OK);
on_order_report(make_order_report(gw_rec));
}
void Gateway::on_gw_op(OM_ID, const GW_OrderCancel &cancel) {
auto gw_rec = me->hot.working_orders.lookup(cancel.order_key);
auto &ack = gw_rec->last_ack;
ack = make_ack(cancel);
switch (me->hot.state) {
case State::READY: {
// Do we know about this order?
if (!gw_rec) {
ack.result = GW_OP_Result::ERROR_ORDER_IS_NOT_ACTIVE;
break;
}
// Can we route it?
if (!gw_rec->is_routable()) {
ack.result = GW_OP_Result::ERROR_NO_ROUTE;
break;
}
me->hot.venue.queue_cancel(gw_rec->order, *gw_rec->routing_record);
// We do not send out a order report yet for performance
// reasons. Instead we delay the report until the exchange
// reponds to our cancel
return;
}
default:
ack.result = GW_OP_Result::ERROR_GATEWAY_DISCONNECTED;
break;
}
// If we got here something went wrong and the cancel failed. This
// is the exceptional path and it should almost never happen. In
// this case we send out a new order report detailing the reasons
// for the failure.
bts_assert(ack.result != GW_OP_Result::OK);
on_order_report(make_order_report(gw_rec));
}
const char *Gateway::intern_string(std::string const &str) {
return me->cold.interned_strings.insert(str).first->data();
}
bool Gateway::has_bootstrap_data() const {
return me->cold.bootstrap_orders.size() == me->cold.cfg.om_count &&
me->cold.admin_data != nullptr;
}
bool Gateway::in_active_schedule() const {
auto now = me->cold.clock.ptime_local_now();
return now >= me->cold.session_span.start &&
now < me->cold.session_span.stop;
}
void Gateway::transition(State state) {
LOG(OrderMan, Info, "Transitioning gateway {} from {} to {}",
me->cold.cfg.my_id.value, state_name(me->hot.state), state_name(state));
me->hot.state = state;
}
void Gateway::rebuild_routing_records() {
// First just rebuild our template cache
me->hot.routing_records.clear();
auto all_uav = me->hot.limiter.get_all_user_account_venue();
for (auto const &uav : all_uav) {
auto rq = me->cold.router.get_route(uav);
if (rq.has_route)
me->hot.routing_records[uav] = rq.routing_record;
}
// Now go through every order and update its messages
auto working = me->hot.working_orders.get_all();
for (auto &orec : working) {
if (auto it = me->hot.routing_records.find(orec->order.uav);
it != me->hot.routing_records.end()) {
orec->routing_record = &it->second;
} else {
LOG(OrderMan, Error, "Order {} can no longer be routed. {}",
orec->order.key, orec->order.uav.to_str());
orec->mark_non_routable();
}
}
}
void Gateway::setup_bootstrap_orders() {
bts_assert(me->hot.state == State::W_BOOTSTRAP);
for (auto [om_id, order_vec] : me->cold.bootstrap_orders)
for (auto &bind_order : *order_vec)
on_gw_op(om_id, bind_order);
me->cold.bootstrap_orders.clear();
}
GW_OrderReport Gateway::make_order_report(OrderRec *gw_rec) {
GW_OrderReport report;
report.last_exe_report = gw_rec->order.last_exe_report;
report.last_ack = gw_rec->last_ack;
report.target = gw_rec->originator;
return report;
}
log::CharPtrWrapper Gateway::state_name(State state) {
switch (state) {
case State::W_BOOTSTRAP:
return {"W_BOOTSTRAP"};
case State::W_SCHEDULE:
return {"W_SCHEDULE"};
case State::PAUSED:
return {"PAUSED"};
case State::W_LOGON:
return {"W_LOGON"};
case State::READY:
return {"READY"};
}
return {""};
}
} // namespace orderman_v2
} // namespace bts
@@ -0,0 +1,78 @@
#pragma once
#include "lib/logging/logging.h"
#include "lib/orderman_v2/actors/Actor.h"
#include "lib/orderman_v2/common.h"
#include "lib/orderman_v2/events/events.h"
#include "lib/orderman_v2/interconnect/ISlowWorker.h"
#include "lib/orderman_v2/interconnect/Signal.h"
#include "lib/orderman_v2/actors/gateway/IVenueObserver.h"
namespace bts {
namespace orderman_v2 {
class IVenue;
class ILimiter;
class IRouter;
class IClock;
struct GatewayCfg;
class Gateway : public Actor, ISlowWorker, IGW_Op_Visitor, IVenueObserver {
public:
Gateway(IVenue &, ILimiter &, IRouter &, IClock &c, GatewayCfg const &);
~Gateway();
// Inputs
void on_om_bootstrap_orders(OM_BootstrapOrders const &);
void on_gw_ops(const GW_Op_Batch &);
void on_account_pnl(const AccountPnLUpdate &);
void on_position(const PositionUpdate &);
void on_excess_liquidity(const ExcessLiquidityUpdate &);
void on_admin_data(const AdminDataUpdate &);
void on_venue_checkpoint(const VenueCheckpointNotice &);
// Signals
Signal<GW_OrderReport> on_order_report;
Signal<GW_UnknownOrderExeReport> on_unknown_native_order_update;
Signal<GW_Error> on_gw_error;
// ISlowWorker
void do_slow_work() override;
private:
enum class State;
class OrderMap;
struct OrderRec;
struct PImpl;
struct Hot;
struct Cold;
std::unique_ptr<PImpl> me;
// IVenueObserver
void on_venue_login_success(std::vector<ExecReport> const&) override;
void on_venue_login_failure() override;
void on_venue_disconnect() override;
void on_venue_exe_report(const ExecReport &) override;
void on_venue_error(VenueError const&) override;
// IGW_Op_visitor
void on_gw_op(OM_ID, const GW_OrderCreate &) override;
void on_gw_op(OM_ID, const GW_OrderBind &) override;
void on_gw_op(OM_ID, const GW_OrderQuickUpdate &) override;
void on_gw_op(OM_ID, const GW_OrderCancel &) override;
void on_gw_op(OM_ID, const GW_OrderFullUpdate &) override;
const char* intern_string (std::string const&);
void send_pending_msgs();
bool has_bootstrap_data() const;
bool in_active_schedule() const;
void transition(State);
void rebuild_routing_records();
void setup_bootstrap_orders();
GW_OrderReport make_order_report(OrderRec *);
static log::CharPtrWrapper state_name(State);
};
} // namespace orderman_v2
} // namespace bts
@@ -0,0 +1 @@
#include "ICancelMsg.h"
@@ -0,0 +1,19 @@
#pragma once
#include <memory>
#include "lib/orderman_v2/actors/gateway/IVenueMsg.h"
namespace bts {
namespace orderman_v2 {
struct GW_BoundOrder;
class ICancelMsg : public IVenueMsg {
public:
virtual ~ICancelMsg() {}
// These are very performance sensitive calls
virtual ICancelMsg& clone() const = 0;
virtual void update(GW_BoundOrder const&) const = 0;
};
}}
@@ -0,0 +1 @@
#include "ICancelReplaceMsg.h"
@@ -0,0 +1,19 @@
#pragma once
#include <memory>
#include "lib/orderman_v2/actors/gateway/IVenueMsg.h"
namespace bts {
namespace orderman_v2 {
struct GW_BoundOrder;
class ICancelReplaceMsg : public IVenueMsg {
public:
virtual ~ICancelReplaceMsg() {}
// These are very performance sensitive calls
virtual void update(GW_BoundOrder const&) = 0;
virtual ICancelReplaceMsg& clone() const = 0;
};
}}
@@ -0,0 +1 @@
#include "ILimiter.h"
@@ -0,0 +1,42 @@
#pragma once
#include <vector>
#include <string>
#include "lib/orderman_v2/common.h"
namespace bts {
namespace api {namespace admin { class AdminData; }}
namespace orderman_v2 {
struct AccountPnLUpdate;
struct PositionUpdate;
struct ExcessLiquidityUpdate;
struct UserAccountVenue;
class ILimiter {
public:
struct LimiterQueryResult {
GW_OP_Result result;
char const*message;
bool ok() const { return result == GW_OP_Result::OK; }
bool error() const { return !ok(); }
};
virtual LimiterQueryResult can_send_new_order(AccountID account,
api::Security const &sec,
Side side, Quantity quantity);
virtual LimiterQueryResult can_update_order(AccountID account,
api::Security const &sec,
Side side, double delta);
virtual void update(api::admin::AdminData const &admin);
virtual void update(AccountPnLUpdate const &) = 0;
virtual void update(PositionUpdate const &) = 0;
virtual void update(ExcessLiquidityUpdate const &) = 0;
virtual std::vector<UserAccountVenue> get_all_user_account_venue() const = 0;
};
}}
@@ -0,0 +1 @@
#include "INewOrderSingleMsg.h"
@@ -0,0 +1,19 @@
#pragma once
#include <memory>
#include "lib/orderman_v2/actors/gateway/IVenueMsg.h"
namespace bts {
namespace orderman_v2 {
struct GW_BoundOrder;
class INewOrderSingleMsg : public IVenueMsg {
public:
virtual ~INewOrderSingleMsg() {}
// These are very performance sensitive calls
virtual INewOrderSingleMsg & clone() const = 0;
virtual void set_order_params(GW_BoundOrder const&) =0;
};
}}
@@ -0,0 +1 @@
#include "IRouter.h"
@@ -0,0 +1,24 @@
#pragma once
#include <memory>
#include "lib/api/services/OrderService.pb.h"
namespace bts {
namespace api {namespace admin {class AdminData;}}
namespace orderman_v2 {
struct UserAccountVenue;
class IRouter {
public:
virtual void update(api::admin::AdminData const &admin);
struct RouteQueryResult {
bool has_route;
std::string error_msg;
api::orderman::RoutingRecord routing_record;
};
virtual RouteQueryResult get_route(UserAccountVenue const &) = 0;
};
}}
@@ -0,0 +1 @@
#include "IVenue.h"
@@ -0,0 +1,69 @@
#pragma once
#include "lib/utils/datetime.h"
#include <boost/date_time/posix_time/posix_time.hpp>
namespace bts {
namespace api {
class Security;
namespace orderman {
class RoutingRecord;
}
} // namespace api
namespace orderman_v2 {
class INewOrderSingleMsg;
class ICancelReplaceMsg;
class ICancelMsg;
class IVenueMsg;
class IVenueObserver;
class ExecReport;
class VenueCheckpoint;
struct GW_BoundOrder;
struct SessionSpan {
datetime::PTime start;
datetime::PTime stop;
};
class IVenue {
public:
// call this before any of the below
virtual void set_observer(IVenueObserver &) = 0;
// Return the current (or next) time interval when this venue is
// active
virtual SessionSpan get_current_session_span() = 0;
// Logon to the venue. This can only be called if the caller knows that the
// venue is in the idle state.
virtual void login() = 0;
// Check to to see if the venue is currently able to receive new
// messages without breaching messaging limits
virtual bool under_messaging_limit() = 0;
virtual void queue_send(GW_BoundOrder const &,
api::orderman::RoutingRecord const &) = 0;
virtual void queue_update(GW_BoundOrder const &,
api::orderman::RoutingRecord const &) = 0;
virtual void queue_cancel(GW_BoundOrder const &,
api::orderman::RoutingRecord const &) = 0;
virtual void send_queued_msgs() = 0;
// Resolved the security in the execution report. This is only
// needed for disaster recovery. Null should be returned in case of
// failure.
virtual api::Security const *resolve_security(ExecReport const &) = 0;
// Tell the venue the last message that had its effects commited to
// disk
virtual void set_checkpoint(VenueCheckpoint const &) = 0;
// call this periodically to allow the venue to process its
// internal timers
virtual void do_work() = 0;
};
} // namespace orderman_v2
} // namespace bts
@@ -0,0 +1,2 @@
#include "IVenueMsg.h"
@@ -0,0 +1,12 @@
#pragma once
namespace bts {
namespace orderman_v2 {
class IVenueMsg {
public:
virtual ~IVenueMsg() {}
};
}}
@@ -0,0 +1,15 @@
#include "IVenueObserver.h"
namespace bts {
namespace orderman_v2 {
struct SilentVenueObserver : public IVenueObserver {
void on_venue_login_success(std::vector<ExecReport> const &) override { }
void on_venue_login_failure() override { }
void on_venue_disconnect() override { }
void on_venue_exe_report(const ExecReport &) override { }
void on_venue_error(VenueError const &) override { }
};
IVenueObserver& default_venue_observer() {
static SilentVenueObserver svo;
return svo;
}
}}
Loaded 100 of 276 files, more files were not shown because too many files have changed in this diff. Show more