Compare commits

...
Author SHA1 Message Date
Taha Afzal e3cd9da308 SpreaderChildOrderState cleaned up a bit, comments, function ordering in the heder 2019-07-22 10:33:23 -04:00
Taha Afzal 41bcfe727d logs 2019-07-18 19:30:23 -04:00
Taha Afzal 07a059fb5d Added enums for usage of quote order for hedging and hooke dup the code to it 2019-07-18 19:25:53 -04:00
Taha Afzal 05ca21d517 When the hedger is using the quoting order, and ends up being underfilled (ie the quoting order went to a terminal state before the qty increase request by the hedger was inacted), it sends another hedging order 2019-07-18 11:18:52 -04:00
Taha Afzal 0586df2434 Common case works, need to deal with underfill and overfill of hedges 2019-07-17 16:17:08 -04:00
Taha Afzal e9571664f5 Merge branch 'master' into SP-44-speed-up-hedging-2 2019-07-16 11:49:02 -04:00
Taha Afzal a91c2d9bc6 SP-146 (Limiter will not accept unresolved fills) 2019-07-16 11:20:15 -04:00
Taha Afzal ca69cdec2a Hedger allows start->working 2019-07-15 12:47:45 -04:00
Taha Afzal 6500b8047d First badge of changes for using quoting order as hedging (machine crashed over the weekend, so rushing this in) 2019-07-15 10:10:21 -04:00
Kevin Darby c9c93b3cf0 Merged in fix_span1 (pull request #300)
fix crash when acct names are > 12 chars

Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-07-12 18:58:13 +00:00
Kevin Darby 5c1965f534 fix crash when acct names are > 12 chars 2019-07-11 14:07:31 -04:00
Pedro Pinto 8553229119 Merge branch 'master' into prod 2019-07-11 10:45:10 -04:00
Pedro Pinto 4903c12533 _index.md edited online with Bitbucket 2019-07-11 14:23:13 +00:00
Jake Norbut 88f23530c6 Merged in SP-119 (pull request #298)
RTM - SP-119 Ladder settings NullRef

Approved-by: John Colvin <john.colvin@bluetradesys.com>
Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-07-11 14:18:45 +00:00
Taha Afzal 630ecae681 SpreaderChildOrderState can now be queried to check for inflight cancels and modfications 2019-07-10 17:02:05 -04:00
Jake Norbut 76ff36e514 Merge branch 'master' of bitbucket.org:bluetradesys/spark into SP-119 2019-07-09 11:54:46 -05:00
Jake Norbut 740c14c261 add LadderSettings santization on paths to VM instantiation 2019-07-09 11:52:41 -05:00
Jake Norbut 33a71f5f47 Merged in SP-105_account-in-ladder (pull request #294)
RTM - SP-105 selected account in ladder

Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-07-08 22:21:46 +00:00
Pedro Pinto 2940601f4b Updated release notes 2019-07-08 18:15:31 -04:00
Pedro Pinto 1f7939f49a Merge branch 'SP-105_account-in-ladder' of bitbucket.org:bluetradesys/spark into SP-105_account-in-ladder 2019-07-08 18:14:45 -04:00
Pedro Pinto 48e273a607 Merge remote-tracking branch 'origin' into SP-105_account-in-ladder 2019-07-08 17:50:43 -04:00
John Colvin e35634020d Merged in SP-89-offset-algo (pull request #286)
RTM SP-89 offset algo

Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-07-08 21:49:12 +00:00
Pedro Pinto 1ede053f59 Merged with master 2019-07-08 17:48:16 -04:00
Pedro Pinto 93824786c7 Updated release notes. 2019-07-08 17:32:33 -04:00
Pedro Pinto 25b8c0a728 Merged with master 2019-07-08 17:31:22 -04:00
Jake Norbut 0e4fe1b47e filter the SelectorProperty source for updates that actually have items; this keeps the currently selected account through server restarts 2019-07-08 16:29:19 -05:00
Jake Norbut cd744963ff Revert "don't revert to default selected setter when server reboots"
This reverts commit d5fdcc6796.
2019-07-08 16:21:46 -05:00
Kevin Darby fb9d877938 Merged in dme (pull request #293)
RTM add mic for DME

Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-07-08 21:08:53 +00:00
Pedro Pinto 087b001510 Updated release notes. 2019-07-08 17:03:56 -04:00
Pedro Pinto 02a7c0ddca Merge branch 'master' into dme 2019-07-08 17:01:50 -04:00
Kevin Darby 6afa1d581d Merged in span (pull request #263)
RTM: Span

Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-07-08 21:01:01 +00:00
Taha Afzal 5e04abe573 Combining the account lookup for loss_limitm and span 2019-07-08 16:50:30 -04:00
Pedro Pinto 3422a44c87 Updated release notes. 2019-07-08 16:49:32 -04:00
Jake Norbut d5fdcc6796 don't revert to default selected setter when server reboots 2019-07-08 15:37:38 -05:00
Kevin Darby f12217d76c Remove mapping of DME mic per Pedro 2019-07-08 20:12:47 +00:00
Pedro Pinto d85a914046 Merge branch 'master' into span 2019-07-08 15:58:06 -04:00
Pedro Pinto 4fdc890cb5 Merged in ticks_off (pull request #296)
RTM Added ticks_off to top algo server side.

Approved-by: Kevin Darby <kevin.darby@bluetradesys.com>
2019-07-08 19:55:01 +00:00
Pedro Pinto 3ed0bd9052 Merged with master 2019-07-08 15:54:39 -04:00
Jake Norbut dbdc915ff2 populating mini_ob (LadderMiniOrderBookSettings) in LadderSettings.Default 2019-07-08 14:24:36 -05:00
Jake Norbut 10476c6662 null ref check on LadderSettings.mini_ob.value 2019-07-08 14:22:55 -05:00
Kevin Darby 05e09cb977 Merge branch 'master' of bitbucket.org:bluetradesys/spark into span 2019-07-08 14:33:37 -04:00
Eric Harding dab4f5acbb Merged in SP-104-HCL (pull request #289)
[RTM] SP-104 HCL

Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-07-08 18:28:44 +00:00
Eric Harding a20c53b23d Merged in SP-68-crash (pull request #292)
[RTM] SP-68 Fix crash on exit by not touching queue on windows.  insert_or_replace() is a no-op on windows anyway.

Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-07-08 18:27:59 +00:00
Pedro Pinto 8206f457b5 Updated release notes. 2019-07-08 14:27:37 -04:00
Pedro Pinto d4e6d6293d Merge branch 'master' into SP-68-crash 2019-07-08 14:26:48 -04:00
Kevin Darby d1a2197ba4 Merged in fix_auth_tests2 (pull request #297)
RTM fix auth tests to respect difference betwen admin and trader login
2019-07-08 18:20:09 +00:00
Kevin Darby 369fb55e90 fix auth tests to respect difference betwen admin and trader login 2019-07-08 14:20:14 -04:00
Pedro Pinto 37dacff74d Fixed a bug in top update 2019-07-08 14:09:37 -04:00
Pedro Pinto d297b703c7 Merge branch 'master' into ticks_off 2019-07-08 13:36:53 -04:00
Kevin Darby 33f533af9b set span to default off, hook up admin boolean to enforce span behind config key 2019-07-08 13:08:18 -04:00
Kevin Darby 085d6402f4 Merged in SPARK-2524-keycode_fixes (pull request #290)
RTM fixed SPARK-2524, allowing admin logins to not require a keycode session

Approved-by: Eric Harding <eric.harding@bluetradesys.com>
Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-07-08 16:26:51 +00:00
Pedro Pinto f4395ef833 Updated release notes. 2019-07-08 12:26:27 -04:00
Pedro Pinto e7a9412124 Updated release notes. 2019-07-08 12:21:39 -04:00
Pedro Pinto da4ee38abd Merge branch 'master' into SPARK-2524-keycode_fixes 2019-07-08 12:20:50 -04:00
Pedro Pinto af39fac368 Merge branch 'master' into SPARK-2524-keycode_fixes 2019-07-08 11:18:39 -04:00
Michael Harding 4f997505f3 Enforce Margin Limit in Spark Admin 2019-07-08 11:12:55 -04:00
Jake Norbut fcbb66361d Merged in SP-103_no_reset_on_agg_side_change (pull request #288)
RTM - SP-103 don't reset last when aggressor side changes

Approved-by: Eric Harding <eric.harding@bluetradesys.com>
Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-07-08 14:46:17 +00:00
Pedro Pinto fa16321691 Updated release notes. 2019-07-08 10:45:56 -04:00
Pedro Pinto ceb3542e15 Merge branch 'master' into SP-103_no_reset_on_agg_side_change 2019-07-08 10:30:25 -04:00
Jake Norbut 32e55d07ee Merged in SP-110_volume_tooltip_nit (pull request #295)
RTM - display tooltip again when re-entering same cell where tooltip was previouly closed

Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-07-08 14:28:34 +00:00
Pedro Pinto e079acf91f Updated release notes. 2019-07-08 10:28:18 -04:00
Pedro Pinto fecedb203a Merge branch 'master' into SP-110_volume_tooltip_nit 2019-07-08 10:26:59 -04:00
Jake Norbut 6ac05a47e1 Merged in SP-103_bars_not_req (pull request #291)
RTM - SP-103 bars not required to show last text

Approved-by: Pedro Pinto <pedro.pinto+atlassian@bluetradesys.com>
2019-07-08 14:15:36 +00:00
Pedro Pinto 36ed80dc87 Updated release notes. 2019-07-08 10:15:14 -04:00
John Colvin f5bbc4245f SP-111 / SP-113 Add ticks off parameter to top algo UI 2019-07-05 16:12:32 -05:00
Pedro Pinto 96fc54ff0f Added ticks_off to top algo server side. 2019-07-05 14:35:18 -04:00
Kevin Darby 25b69e4f7d fix small bug and add manual test 2019-07-05 13:29:22 -04:00
Kevin Darby d871ffca6d temporarily tie span enforcement to config while michael works 2019-07-05 12:59:41 -04:00
Jake Norbut 213567bcdb display tooltip again when re-entering same cell where tooltip was previouly closed 2019-07-05 11:49:34 -05:00
Kevin Darby b7e5c3a374 Merge branch 'span' of bitbucket.org:bluetradesys/spark into span 2019-07-05 12:30:10 -04:00
Kevin Darby ae4a8bbf46 more span 2019-07-05 12:28:58 -04:00
Taha Afzal 850386c1d4 Margin enforced in the limiter 2019-07-05 12:05:16 -04:00
Kevin Darby 2d4e94a636 Types.fs edited online with Bitbucket 2019-07-05 15:39:35 +00:00
Pedro Pinto e447096733 Routed excess liquidity to OrderManager. 2019-07-05 11:00:42 -04:00
Jake Norbut cd68b95a3e add a mechanism for ignoring InlineUserProperty's force_override property 2019-07-05 08:19:05 -05:00
Michael Harding ebad5b389f Fix Save button 2019-07-03 16:01:50 -04:00
John Colvin 160c49514a Merge remote-tracking branch 'origin/master' into SP-89-offset-algo 2019-07-03 14:38:50 -05:00
Michael Harding 4f7fcc5634 Move loss limits to the top of the limits page 2019-07-03 14:54:40 -04:00
Michael Harding 500e5b5fe4 Polling and commas 2019-07-03 14:19:51 -04:00
Michael Harding 9d924fa4ba Margin table formatting 2019-07-03 10:14:01 -04:00
John Colvin 092e63e300 OffsetAlgo attach impl (take 2) 2019-07-03 00:07:23 -05:00
Kevin Darby 4654cd4739 changes in margin workflow for webui 2019-07-02 18:29:10 -04:00
Kevin Darby f2f06d76de PR feedback 2019-07-02 17:43:28 -04:00
Kevin Darby 6bc293a58e add mic for DME 2019-07-02 17:35:29 -04:00
Kevin Darby fdb462eda4 simplify margin server states 2019-07-02 17:34:46 -04:00
Kevin Darby cc579034b2 fix bug in margin service 2019-07-02 17:05:22 -04:00
John Colvin 4b76e91757 SP-89 (pr edit) - 'can_consume_attachment()' returns false for 'Offset' 2019-07-02 15:48:24 -05:00
Eric Harding 8d34279ab0 SP-68 Fix crash on exit by not touching queue on windows. insert_or_replace() is a no-op on windows anyway. 2019-07-02 16:26:34 -04:00
John Colvin 7973b927a2 SP-89 (pr edit) - fwd price updates to child; cache update qty 2019-07-02 15:22:54 -05:00
Kevin Darby 6997aed9bd fixed SPARK-2524, allowing admin logins to not require a keycode session 2019-07-02 15:05:23 -04:00
Michael Harding b5d7d98098 Add DayPnL to SA Margin tab 2019-07-02 15:04:55 -04:00
Jake Norbut 8f22a326ab last on volume foreground text is now white 2019-07-02 14:01:50 -05:00
Jake Norbut b2c3488c5e draw volume numbers when bars not present 2019-07-02 14:01:07 -05:00
Michael Harding 23f10eac70 Add accountPnl to emptyMargin 2019-07-02 14:10:27 -04:00
Kevin Darby cb31269a70 added pnl impact to margin 2019-07-02 13:14:46 -04:00
Jake Norbut 5b75b8718a updating comment to reflect change 2019-07-02 11:14:01 -05:00
Eric Harding 5a256d4634 SP-104 PEBKAC buy with negative mult is nonsense 2019-07-02 11:55:55 -04:00
Jake Norbut db2de3e8c4 remove last_side; change StructLayout Size accordingly 2019-07-02 10:53:11 -05:00
Jake Norbut b9dcad9549 don't reset last trade size when aggressor changes 2019-07-02 10:52:21 -05:00
Jake Norbut ce104479e1 removing last_side; incrementing shm_version 2019-07-02 10:51:06 -05:00
Eric Harding 2d56eedf3e Bugfix in synthetic_book_merge_tests 2019-07-02 10:37:47 -04:00
Eric Harding 049381908c update gitignore 2019-07-02 10:34:28 -04:00
John Colvin 0067e52155 SP-89 (pr edit) - wait 4 mkt 2 launch; attach impl 2019-07-02 00:07:17 -05:00
Kevin Darby 8ed6d297a9 Merge branch 'master' of bitbucket.org:bluetradesys/spark into span 2019-07-01 18:01:34 -04:00
Michael Harding 5d53492ab5 Merged SP-38-span-admin into span 2019-07-01 14:53:52 -04:00
Michael Harding 90fd5bd382 Handle save errors better 2019-07-01 14:52:40 -04:00
Michael Harding beff060a4f Update unchanged margin values 2019-07-01 14:27:44 -04:00
Michael Harding bc3418734f Span Columns and Formatting 2019-07-01 13:22:27 -04:00
Michael Harding ab255c8777 update ui.fsproj 2019-07-01 12:51:17 -04:00
Michael Harding cc2bde1064 Merged span into SP-38-span-admin 2019-07-01 12:43:16 -04:00
Michael Harding 94d66a8e99 Add Margin tab to Spark Admin 2019-07-01 12:40:16 -04:00
John Colvin 4ada322c56 bring back OffsetOrder gui in ladder/ticket 2019-06-30 12:56:59 -05:00
John Colvin 7de7f6e496 remove old OffsetOrder.cpp/h, replace with new OffsetAlgo in CMakeDeps 2019-06-30 12:47:05 -05:00
John Colvin 0700e9e80d SP-89 Port Offset order to new api 2019-06-29 16:10:34 -05:00
Kevin Darby e47af3d7bd update api docs 2019-06-20 10:34:06 -04:00
Kevin Darby c3c427742d Merge branch 'master' of bitbucket.org:bluetradesys/spark into span 2019-06-19 13:34:52 -04:00
Kevin Darby 685e69adcc Merge branch 'key_codes' of bitbucket.org:bluetradesys/spark into span 2019-06-18 15:21:10 -04:00
Kevin Darby e9f61dc3c0 added get_excess_liquidity_report rpc for adminui 2019-06-17 18:15:05 -04:00
Kevin Darby f329470165 added spreadsheet to help test span 2019-06-17 16:49:21 -04:00
Kevin Darby d7d319f1e3 fixed span timing 2019-06-17 10:43:27 -04:00
Kevin Darby 419833d398 slight timing issue with span 2019-06-14 18:10:41 -04:00
Kevin Darby 9883553fb5 MarginService 2019-06-14 11:21:09 -04:00
Kevin Darby be5d037ca9 span works again 2019-06-13 17:52:47 -04:00
Kevin Darby 159e8fba23 beginnings of span, should't be long 2019-06-12 18:17:09 -04:00
139 changed files with 2351 additions and 774 deletions

No files matched your search

+1
View File
@@ -32,3 +32,4 @@ trace_data/
/src/lib/orderman/perf_analysis/last_pretty_log.csv
/src/lib/orderman/perf_analysis/log.csv
/doc/user/public/*
.ionide/*
+3 -3
View File
@@ -135,13 +135,13 @@
"name": "Spreader Tests",
"type": "cppdbg",
"request": "launch",
"program": "/home/bts/spark/build/ninja_debug/src/server/sparkd/sparkd",
"program": "/home/bts/spark/build/ninja_debug/server/sparkd",
"args": [
"test",
"[spreader]"
],
"stopAtEntry": false,
"cwd": "/home/bts/spark/build/ninja_debug/src/server/sparkd/",
"cwd": "/home/bts/spark/build/ninja_debug/server",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
@@ -288,7 +288,7 @@
"name": "SparkVM attach",
"type": "cppdbg",
"request": "attach",
"program": "/home/bts/spark/build/ninja_debug/src/server/sparkd/sparkd",
"program": "/home/bts/spark/build/ninja_debug/server/sparkd",
"processId": "${command:pickRemoteProcess}",
"MIMode": "gdb",
"pipeTransport": {
+20 -1
View File
@@ -4,6 +4,24 @@ weight = 3
sort_by = "weight"
insert_anchor_links = "right"
+++
## 2.6.1
### User Visible Changes
- Fixed an issue in the ladder where an error could occur when trying to change ladder settings for the first time
## 2.6.0
### User Visible Changes
- In the ladder made last trade more distinctive when overlayed on the volumn column
- In the ladder, corrected display of volume tool tip
- In the ladder, changed the consolidation of last trade to consider only the price ignoring aggressor changes
- Added an option for the Top Algo to delete itself if within N ticks from top of book
- Address a rare issue that could lead to an error report on UI exit
- Added margin risk limits
- Added the "Offset" algo. Offset prices a child algo at a parameterizable distance from the top of the book
- Avoided switching the current account and order type on open ladders when limits are changed
### Internal Changes
- Ensure that admin logins are always allowed to login, regardless of keycode status.
## 2.5.0
### User Visible Changes
- Added loss limit risk check
@@ -398,7 +416,8 @@ insert_anchor_links = "right"
- This is configurable from a ladder's settings as well
### Customized settings in all windows
- All windows now contain a settings page where grid settings (font color, size, etc) are applied
- These settings can be saved on a per-window basis or as a Default for newly-launched windows␍
- These settings can be saved on a per-window basis or as a Default for newly-launched windows
## 1.3.1 Through 1.3.4
@@ -339,6 +339,7 @@ namespace mbts.spark {
zoom_slider_visible = false,
zoom_factor = _default_zoom_factor,
net_change = NetChangeTerms.None,
mini_ob = new LadderMiniOrderBookSettings(bts.shell.orderbook.OrderBookStartupData.default_mini_grid.general),
};
rv.row_height = LadderRender.measure_row_height(rv);
return rv;
@@ -113,7 +113,7 @@ namespace bts.shell {
});
});
// vm
vm = LadderVM.create(_bus, model, last_value ?? _settings_hub.current.ladder, settings_source);
vm = LadderVM.create(_bus, model, LadderSettings.sanitize(last_value ?? _settings_hub.current.ladder), settings_source);
vm.settings_invalidated += on_settings_invalidated;
vm.order_properties_vm.open_algo_popup_on_select = _ladder_conf.open_algo_popup_on_select;
vm.order_properties_vm.use_algo_param_grid = _ladder_conf.use_algo_param_grid;
@@ -363,7 +363,9 @@ namespace mbts.spark {
} else {
clone = SparkUtils.clone_proto(_current);
#pragma warning disable CS0612 // Type or member is obsolete
clone.mini_ob = new LadderMiniOrderBookSettings(mini_ob.create().with(sorting_criterion: _current.mini_ob.value.sorting_criterion));
clone.mini_ob = new LadderMiniOrderBookSettings(_current.mini_ob.value != null ?
mini_ob.create().with(sorting_criterion: _current.mini_ob.value.sorting_criterion) :
mini_ob.create());
#pragma warning restore CS0612 // Type or member is obsolete
}
clone.badge_style = badge_style;
@@ -51,7 +51,7 @@ namespace mbts.spark {
LadderVM.create_readonly(_bus,
new LadderModel(security_md.Value, _model, _model.mbo_service,
new Func<OrderSecurity, bool>(osec => _selected_order_tree.Contains(osec.order.Key))),
Observable.Return(LadderSettings.Default)) : null);
Observable.Return(LadderSettings.sanitize(LadderSettings.Default))) : null);
RaisePropertyChanged(nameof(value));
}
}
@@ -694,12 +694,14 @@ namespace mbts.spark {
// At any rate, we need this part hiding the tooltip so that we don't leave random tooltips around
// and we have to reset to old row so that when we go back to what could be our preivous row, the tooltip gets drawn again
//System.Diagnostics.Debug.WriteLine(" Tooltip - Volume is 0");
_old_tooltip_row = int.MaxValue;
_hide_tool_tip();
//_old_tooltip_row = Int32.MaxValue;
}
}
} else {
//System.Diagnostics.Debug.WriteLine(" Tooltip - not over Volume column");
_old_tooltip_row = int.MaxValue;
_hide_tool_tip();
}
}
@@ -215,16 +215,16 @@ namespace mbts.spark {
Brush total_brush = null;
if (settings.total.bars.result.HasValue) {
total_brush = new SolidColorBrush(settings.total.bars.result.Value);
} else if (components.Count == 0) {
} else if (components.Count == 0 && !settings.show_ltq) {
_clear_visual(dv);
return;
}
// inflate the max so that the graph never fills the available space
double max = data.Max(v => v.Volume) * 1.1;
Brush text_brush = settings.general.foreground.rgb_brush();
_render_cells(dv, row_height, data.Select(d => (d.Price, d)), settings.general, prices, spec, render_cell);
/// local methods
void render_cell(DrawingContext dc, int r, VolumeAtPriceLevelImmutable vap) {
Brush text_brush = settings.general.foreground.rgb_brush();
double y = row_height * r;
var last_trade_here = r == last_index;
@@ -259,6 +259,7 @@ namespace mbts.spark {
if (settings.show_ltq && last_trade_here) {
numbers_text.Clear();
numbers_text.Add(last_size_and_direction);
text_brush = BTSCoreColors.white;
}
if (numbers_text.Count > 0) {
string str = string.Join("/", numbers_text);
@@ -994,11 +994,13 @@ namespace mbts.spark {
var join = config.Configuration.get<bts.config.JoinAttachUIOptions>();
var lean = config.Configuration.get<bts.config.LeanAttachUIOptions>();
var top = config.Configuration.get<bts.config.TopAttachUIOptions>();
var offset = config.Configuration.get<bts.config.OffsetAttachUIOptions>();
_algo_type_conf = new Dictionary<CustomOrderDefinition.CustomOneofCase, (bool, bool)> {
{ CustomOrderDefinition.CustomOneofCase.Cover, (cover.show_price, cover.show_quantity) },
{ CustomOrderDefinition.CustomOneofCase.Join, (join.show_price, join.show_quantity) },
{ CustomOrderDefinition.CustomOneofCase.Lean, (lean.show_price, lean.show_quantity) },
{ CustomOrderDefinition.CustomOneofCase.Top, (top.show_price, top.show_quantity) }
{ CustomOrderDefinition.CustomOneofCase.Top, (top.show_price, top.show_quantity) },
{ CustomOrderDefinition.CustomOneofCase.Offset, (offset.show_price, offset.show_quantity) }
};
}
+6 -4
View File
@@ -602,7 +602,8 @@ namespace mbts.spark.utilities {
CustomOrderDefinition.CustomOneofCase.Lean,
CustomOrderDefinition.CustomOneofCase.Join,
CustomOrderDefinition.CustomOneofCase.Cover,
CustomOrderDefinition.CustomOneofCase.Top
CustomOrderDefinition.CustomOneofCase.Top,
CustomOrderDefinition.CustomOneofCase.Offset
},
// The following spreader types are not yet ready for production use:
// CustomOrderDefinition.CustomOneofCase.Dynamic,
@@ -619,7 +620,8 @@ namespace mbts.spark.utilities {
CustomOrderDefinition.CustomOneofCase.Lean,
CustomOrderDefinition.CustomOneofCase.Join,
CustomOrderDefinition.CustomOneofCase.Cover,
CustomOrderDefinition.CustomOneofCase.Top
CustomOrderDefinition.CustomOneofCase.Top,
CustomOrderDefinition.CustomOneofCase.Offset
},
outright_order_types = new[] {
CustomOrderDefinition.CustomOneofCase.Market,
@@ -715,7 +717,7 @@ namespace mbts.spark.utilities {
!b.HasChild);
public static bool top_equals(TopOrderDefinitionImmutable a, TopOrderDefinitionImmutable b) =>
a.WatchLevelTickOffset == b.WatchLevelTickOffset &&
a.TicksOff == b.TicksOff &&
(a.HasTopThreshold ?
b.HasTopThreshold && quantity_measure_equals(a.TopThreshold, b.TopThreshold) :
!b.HasTopThreshold) &&
@@ -906,7 +908,7 @@ namespace mbts.spark.utilities {
add_component(_get_hash(_get_tick_child(tick)));
break;
case CustomOrderDefinition.CustomOneofCase.Top:
add_component(def.Top.WatchLevelTickOffset.GetHashCode());
add_component(def.Top.TicksOff.GetHashCode());
add_component(def.Top.HasTopThreshold ? def.Top.TopThreshold.GetHashCode() : 0);
add_component(_get_top_child(def.Top).GetHashCode());
break;
@@ -105,13 +105,18 @@ namespace mbts.spark {
var inline_account_src = order_properties.AggregateLatest(
model.factory.subscribe_accounts(),
(last, change, cache) => convert_inline_account(change.New.account, cache),
(last, props, change) => convert_inline_account(props.account, change.New),
(last, props, change) => convert_inline_account(props.account, change.New, false),
() => new InlineUserProperty<AccountTuple>(),
new InlineOrderProperties(),
DictionaryHelper.empty<uint, string>());
// Note that with the .Where on the account_tuples, we will ignore any
// updates for which all accounts have been removed.
// This was a safer change than changing SelectorProperty's IEnumberable.OnNext
// so that it would not reset the selected item on server reboots; i.e. this
// change only affects this IObservable.
_accounts = backing(
nameof(selected_account),
model.factory.subscribe_account_tuples(),
model.factory.subscribe_account_tuples().Where(items => items.Any()),
inline_account_src,
a => new AccountTuple?(a),
() => accounts.Cast<AccountTuple?>().FirstOrDefault(),
@@ -263,9 +268,18 @@ namespace mbts.spark {
break;
}
}
InlineUserProperty<AccountTuple> convert_inline_account(InlineUserProperty<uint> account_id, IReadOnlyDictionary<uint, string> account_map) =>
//
// Regarding the 3rd parameter, force_override_from_inline_property:
// When using an InlineUserProperty, in the context of assigning a default vs selected item,
// there is somewhat of a conflict between the IObserver<InlineUserProperty<TItem>> and the
// IObserver<IEnumerable<TItem>> OnNext methods. This 3rd paramter provides yet another override
// to say if the force_override should come from the inline property or if the force_override should
// be disbled, by way of the immediate return in ViewModelBase._try_auto_select when force_override
// is false. Our intent is then accomplished because we are no longer attempting to set a default/
// selected item when the account_tuples potentially changes
InlineUserProperty<AccountTuple> convert_inline_account(InlineUserProperty<uint> account_id, IReadOnlyDictionary<uint, string> account_map, bool force_override_from_inline_property = true) =>
account_id.has_value && account_map.TryGetValue(account_id.value, out string name) ?
new InlineUserProperty<AccountTuple>(new AccountTuple(account_id.value, name), account_id.force_override) :
new InlineUserProperty<AccountTuple>(new AccountTuple(account_id.value, name), force_override_from_inline_property ? account_id.force_override : false) :
new InlineUserProperty<AccountTuple>();
}
@@ -5,13 +5,16 @@ using TopDefi = bts.api.orderman.TopOrderDefinitionImmutable;
namespace mbts.spark {
static partial class OrderTypeVMFactory {
class TopOrderVM : OrderTypeVMBase<TopDef, TopDefi> {
readonly Property<uint?> _ticks_off;
readonly Property<QuantityMeasureImmutable?> _top_threshold;
public TopOrderVM(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions)
: base(key, display_name, editing_permissions) {
_ticks_off = add_nullable_property<uint>(nameof(ticks_off), TopDef.TicksOffFieldNumber);
_top_threshold = add_property<QuantityMeasure, QuantityMeasureImmutable>(nameof(top_threshold), TopDef.TopThresholdFieldNumber, new QuantityMeasureImmutable(new QuantityMeasure { Ratio = 1.0, Absolute = 1 }));
}
public uint? ticks_off { get => _ticks_off.Value; set => _ticks_off.set(value); }
public QuantityMeasureImmutable? top_threshold { get => _top_threshold.Value; set => _top_threshold.set(value); }
}
}
@@ -820,6 +820,11 @@ namespace mbts.ui.shell {
void _try_auto_select() {
if (_is_user_selected_item) {
// if we have a user-selected item and the _desired_item for which we might want to set as the selected item
// isn't force_override, then no change
if (!_desired_item.force_override) {
return;
}
if (desired_item_valid() && _desired_item.force_override && _try_match_item(_desired_item.value, out TValue match)) {
_set_selected_item(match, SelectionReason.SettingsMandatedSelection);
return;
@@ -489,6 +489,8 @@
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="{Binding Source={StaticResource VerticalPush1}}"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="{Binding Source={StaticResource VerticalPush3}}"/>
<RowDefinition Height="*"/>
@@ -503,9 +505,11 @@
<c:HelpButton Margin="{StaticResource Margin.LP1}" ToolTip="If the order is at the top of book, the quantity remaining below which the order will be canceled."/>
</StackPanel>
<uag:QuantityMeasureControl x:Name="PART_TopThreshold_QuantityMeasureControl" Grid.Column="2" QuantityMeasure="{Binding top_threshold}"/>
<TextBlock Grid.Row="2">Ticks Off</TextBlock>
<c:TickUpDownUInt Grid.Row="2" Grid.Column="2" Value="{Binding ticks_off}"/>
<uag:AlgoPickerNodeView
x:Name="PART_Child_AlgoPickerNodeView"
Grid.Row="2"
Grid.Row="4"
Grid.ColumnSpan="3"
ItemsSource="{Binding children_vm.child.algos_view}"
SelectedItem="{Binding children_vm.child.selected_algo}"
+1 -2
View File
@@ -253,14 +253,13 @@ namespace mbts.co2 {
}
}
[StructLayout(LayoutKind.Sequential, Size = 712)]
[StructLayout(LayoutKind.Sequential, Size = 704)]
internal struct ColdEntry {
public int exchange_status;
// Last trade
public AtomicPriceSize last_trade;
public ulong total_volume;
public utils.LLDateTime last_trade_time;
private AggressorSide last_side;
//// Settlement
public UInt64 misc_timestamp;
Binary file not shown.
@@ -13,6 +13,8 @@ namespace bts.excel.rtd
class JsonFormatter : IExcelFormatter
{
private object _data;
static Google.Protobuf.JsonFormatter _protoformatter =
new Google.Protobuf.JsonFormatter(Google.Protobuf.JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
public JsonFormatter(object data)
{
_data = data;
@@ -81,7 +83,7 @@ namespace bts.excel.rtd
{
string json = null;
if(data is IMessage imsg)
json = Google.Protobuf.JsonFormatter.Default.Format(imsg);
json = _protoformatter.Format(imsg);
else
json = JsonConvert.SerializeObject(data);
+4
View File
@@ -73,6 +73,10 @@ Commands:
order <exchange> <security_type> <symbol> <security_desc> <signed_quantity> [<price>]
Arguments:
--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
```
* Check out sample code
+1 -1
View File
@@ -108,7 +108,7 @@ where
session.session_start = event_view.session_start and
event_view.channel=trace.channel and event_view.sn=trace.sn and
event_type='hedge' and
entry_kind='NativeOrder::on_activate' and
entry_kind='NativeOrder::on_update' and
cor_event=0;
/* A view on requote events, identifying each order sent as part of the event*/
+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/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/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/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/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/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;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/MDSupplementarySource.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SODPosition.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderManager.cpp;orderman/actors/order_manager/OrderServices.cpp;orderman/actors/order_manLine 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/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.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/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/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/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/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/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;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/MDSupplementarySource.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SODPosition.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderMLine truncated
+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/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/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/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/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/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;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/catch_test_runner.cpp;utils/AuthSessionManager.cpp;utils/AuthToken.cpp;utils/Dispatcher.cpp;utils/GrowableSPSCQueue.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SecureLogon.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/crypto/CipherType.cpp;utils/crypto/CryptoInit.cpp;utils/crypto/Digest.cpp;utils/crypto/KeyCodeHelper.cpp;utils/crypto/PasswordCallback.cpp;utils/crypto/PrivateKey.cpp;utils/crypto/PublicKey.cpp;utils/crypto/iostreambio.cpp;utils/datetime.cpp;utils/download.cpp;utLine 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/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.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/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/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/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/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/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/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;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/catch_test_runner.cpp;utils/AuthSessionManager.cpp;utils/AuthToken.cpp;utils/Dispatcher.cpp;utils/GrowableSPSCQueue.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SecureLogon.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/crypto/CipherType.cpp;utils/crypto/CryptoInit.cpp;utils/crypto/Digest.cpp;utils/crypto/KeyCodeHelper.cpp;utils/crypto/PasswordCallback.cpp;utils/crypto/PrivateKey.cpp;utils/cryptoLine truncated
+3 -2
View File
@@ -50,6 +50,7 @@ message VoidMessage {}
message BytesMessage {
bytes buffer = 1;
}
message BoolResultMessage {
bool success = 1;
message ResultMessage {
bool success = 1;
string error_message = 2;
}
+67
View File
@@ -0,0 +1,67 @@
syntax="proto3";
package bts.api.position;
option csharp_namespace="bts.api.position";
import "lib/api/apioptions.proto";
import "lib/api/apicore.proto";
import "lib/api/services/PositionService.proto";
message MarginResult {
enum ResultStatus { NewValid = 0; CachedValid = 1; Error = 2; }
string account = 10 [(bts.api.key)=true];
ResultStatus status = 12;
string portfolio_id = 15;
string settle_indicator = 20;
string settle_qualifier = 30;
string as_of_time = 40;
string calculation_id = 50;
double opt_value = 100;
double nonopt_value = 110;
double maint_margin = 120;
double initial_margin = 130;
}
message ExcessLiquidityReport {
string account = 10 [(bts.api.key)=true];
uint32 account_id = 11;
double leverage_factor = 20;
double cash_balance = 30;
MarginResult margin_result = 40;
AccountPNL account_pnl = 50;
bool should_enforce_margin = 60;
double excess_liquidity = 100;
}
message MarginRequest {
string account = 10;
}
message CashFactorUpdate {
string account = 10;
double leverage_factor = 20;
}
message CashBalanceUpdate {
string account = 10;
double cash_balance = 20;
}
message EnforceUpdate {
string account = 10;
bool should_enforce_margin = 20;
}
service MarginService {
option (bts.api.service_description) = "Provides CME Margin Information per account";
rpc get_margin(MarginRequest) returns (MarginResult);
rpc get_excess_liquidity_report(MarginRequest) returns (ExcessLiquidityReport);
rpc set_should_enforce_margin(EnforceUpdate) returns (bts.api.ResultMessage);
rpc set_cash_factor(CashFactorUpdate) returns (bts.api.ResultMessage);
rpc set_cash_balance(CashBalanceUpdate) returns (bts.api.ResultMessage);
rpc margin_data(bts.api.VoidMessage) returns (stream MarginResult);
rpc excess_liquidity_report(bts.api.VoidMessage) returns (stream ExcessLiquidityReport);
}
+1 -1
View File
@@ -160,8 +160,8 @@ message JoinOrderDefinition {
CustomOrderDefinition child = 6;
}
message TopOrderDefinition {
uint32 watch_level_tick_offset = 1;
spark.QuantityMeasure top_threshold = 2;
uint32 ticks_off = 3;
CustomOrderDefinition child = 6;
}
message TriggerOrderDefinition {
@@ -32,6 +32,7 @@ message PNLUnit{
message AccountPNL{
uint32 account_id = 1 [(bts.api.key)=true];
string account_name = 10;
double day_pnl = 20;
}
+9
View File
@@ -0,0 +1,9 @@
SpanMargin {
value {
enabled: false
login: 'api_bts1'
password: 'Summer123'
url: 'https://cmecorenr.cmegroup.com/MarginServiceApi/1.4/'
}
}
+1 -1
View File
@@ -8,4 +8,4 @@ OrdersSoftCleanup {
value {
enabled: true
}
}
}
+5
View File
@@ -141,6 +141,11 @@ message TopAttachUIOptions {
optional bool show_quantity = 2 [default = false];
}
message OffsetAttachUIOptions {
optional bool show_price = 1 [default = false];
optional bool show_quantity = 2 [default = false];
}
message ManualFillsOptions {
optional bool modal_transactions = 1 [default = true];
}
+10
View File
@@ -0,0 +1,10 @@
syntax='proto2';
package bts.config;
message SpanMargin
{
optional bool enabled = 10;
optional string login = 20;
optional string password = 30;
optional string url = 40;
}
+1 -1
View File
@@ -53,4 +53,4 @@ message EnsureOnScreenWithWorkAreaRect {
// and the new ensure_onscreen code has only been tested with a single monitor arrangement.
// Should verify that the code works with every monitor arrangement before enabling by default.
optional bool enabled = 1 [default = false];
}
}
+8
View File
@@ -38,6 +38,8 @@ inline api::Side other_side(api::Side side) {
inline double market_epislon() { return 1e-10; }
// this tells which price is better from a market data
// standpoint, ie for buys the higher price is better
inline bool is_better(api::Side side, Price p1, Price p2) {
switch (side) {
case api::SIDE_BUY:
@@ -81,6 +83,12 @@ inline Price better_price (api::Side side, Price p1, Price p2){
return is_equal_or_better(side, p1, p2) ? p1 : p2;
}
// returns true if p1 is a better order price than p2
// ie lower when buying, higher when selling
inline bool same_or_better_order_price (api::Side side, Price p1, Price p2){
return is_equal_or_better(side, p2, p1);
}
inline Price decode_exchange_price(api::Security const &sec, Price in) {
return Price(in.value() * sec.contract_spec().price_multiplier());
}
+2 -3
View File
@@ -102,14 +102,13 @@ void MDProducerHandle::set_status(CoconutSecurityStatus status) {
}
void MDProducerHandle::add_trade(TimeStamp time, const PriceSize price, LLDateTime tradetime, co2::AggressorSide agside, uint32_t volume) {
// Add this trade to the last trade if price/side match
// Add this trade to the last trade if price match
auto current = std::get<PriceSize>(cdata().last_trade.load());
if (current.int_price() == price.int_price() && agside == cdata().last_side) {
if (current.int_price() == price.int_price()) {
cdata().last_trade.store(PriceSize { price.int_price(), price.size() + current.size() }, time);
}
else {
cdata().last_trade.store(price,time);
cdata().last_side = agside;
}
cdata().last_trade_time = tradetime;
cdata().total_volume = volume;
+2
View File
@@ -22,6 +22,7 @@ void SecurityCacheImpl::enqueue_update_db(const SecurityPtr& security) {
}
void SecurityCacheImpl::flush() {
#ifndef _WIN32
if (!update_queue.empty()) {
std::vector<SecurityPtr> work;
SecurityPtr temp;
@@ -33,6 +34,7 @@ void SecurityCacheImpl::flush() {
}
}
}
#endif
}
//////////////////
+1 -3
View File
@@ -26,7 +26,7 @@ namespace md {
using utils::TimeStamp;
const uint32_t shm_version = 101;
const uint32_t shm_version = 102;
struct ALIGNED_(CACHE_LINE) HotHeader {
size_t count;
@@ -214,7 +214,6 @@ struct ColdEntry {
last_trade(),
total_volume(0),
last_trade_time(),
last_side(co2::AggressorSide::AGGRESSOR_SIDE_NONE),
misc(),
deleted(false)
{
@@ -230,7 +229,6 @@ struct ColdEntry {
AtomicPriceSize last_trade;
size_t total_volume;
datetime::LLDateTime last_trade_time;
co2::AggressorSide last_side;
MiscData misc;
+110 -2
View File
@@ -111,7 +111,7 @@ tuple<shared_ptr<SyntheticStrategy>,vector<Co2TestInstrument>> make_securities(c
l->mutable_security()->mutable_contract_spec()->set_low_tick(tick_size);
l->mutable_security()->mutable_contract_spec()->set_high_tick(tick_size);
l->set_quantity(quantity);
l->set_price_multiplier(quantity * (side == api::SIDE_BUY ? 1.0 : -1));
l->set_price_multiplier(mult);
l->set_side(side);
synthetic->legs.push_back(instr.consumer());
legs.push_back(instr);
@@ -126,7 +126,8 @@ tuple<shared_ptr<SyntheticStrategy>,vector<Co2TestInstrument>> make_securities(c
double quantity, tick_size;
api::Side side;
std::tie(quantity, tick_size, side) = t;
legs.push_back({ quantity, quantity, tick_size, side });
double mult = quantity * (side == api::SIDE_BUY ? 1.0 : -1);
legs.push_back({ quantity, mult, tick_size, side });
}
return make_securities(legs);
}
@@ -457,6 +458,113 @@ TEST_CASE("Synthetic_net_change", "[md][synthetic]") {
}
}
TEST_CASE("HCL_SP_104", "[md][synthetic]") {
shared_ptr<SyntheticStrategy> synthetic;
vector<Co2TestInstrument> test_instr;
tie(synthetic, test_instr) = make_securities({
// (quantity, multiplier, tick_size, side)
{1.0, 1.0, 0.01, api::SIDE_BUY},
{1.0, 1.0, 0.01, api::SIDE_BUY},
{1.0, -1.0, 0.01, api::SIDE_SELL},
{1.0, -1.0, 0.01, api::SIDE_SELL }
});
auto leg1 = test_instr[0]; // CLQ9-CLU9
auto leg2 = test_instr[1]; // HCLQ9-CLQ9
auto leg3 = test_instr[2]; // HCLQ9-HCLU9
auto leg4 = test_instr[3]; // HCLU9-CLU9
setup_market(leg1.producer(),
{
{ -0.10, 3299 },
{ -0.11, 2885 },
{ -0.12, 2558 },
{ -0.13, 2447 },
{ -0.14, 1540 },
{ -0.15, 2334 },
{ -0.16, 1396 },
{ -0.17, 1190 },
{ -0.18, 1221 },
{ -0.19, 812 }
},
{
{ -0.09, 1318 },
{ -0.08, 2174 },
{ -0.07, 3057 },
{ -0.06, 2331 },
{ -0.05, 2543 },
{ -0.04, 2638 },
{ -0.03, 2232 },
{ -0.02, 3221 },
{ -0.01, 2863 },
{ 0.00, 3327 }
});
setup_market(leg2.producer(),
{
{ 4.06, 1 },
{ 4.05, 2 },
{ 4.04, 3 },
{ 4.03, 12 },
{ 4.02, 6 },
{ 4.01, 1 }
},
{
{ 4.07, 1 },
{ 4.08, 2 },
{ 4.10, 8 },
{ 4.11, 10 },
{ 4.12, 2 },
{ 4.14, 1 }
});
setup_market(leg3.producer(),
{
{ 0.20, 2 },
{ 0.19, 6 },
{ 0.18, 5 },
{ 0.17, 18 },
{ 0.16, 2 },
{ 0.15, 3 },
{ 0.14, 2 }
},
{
{ 0.22, 2 },
{ 0.23, 4 },
{ 0.24, 9 },
{ 0.25, 17},
{ 0.26, 5 },
{ 0.27, 5 },
{ 0.28, 4 },
{ 0.29, 2 },
{ 0.30, 2 }
});
setup_market(leg4.producer(),
{
{ 3.75, 1 },
{ 3.74, 3 },
{ 3.73, 4 },
{ 3.72, 12 },
{ 3.71, 1 },
{ 3.70, 3 }
},
{
{ 3.78, 1 },
{ 3.79, 2 },
{ 3.80, 6 },
{ 3.81, 1 },
{ 3.82, 10 },
{ 3.83, 1 }
});
MDConsumerHandle synthetic_handle(synthetic);
// dump_market(synthetic_handle);
expect_market(synthetic_handle,
{ { -0.04,1 },{ -0.06,1 },{ -0.07,1 },{ -0.09,3 },{ -0.11,3 },{ -0.12,1 },{ -0.13,5 },{ -0.14,3 },{ -0.15,2 },{ -0.16,1 } },
{ { 0.03,1 },{ 0.05,1 },{ 0.06,1 },{ 0.08,1 },{ 0.09,4 },{ 0.11,3 },{ 0.12,2 },{ 0.13,7 },{ 0.14,1 },{ 0.16,2 } }
);
}
//
// Benchmarks
+21 -4
View File
@@ -1,12 +1,14 @@
#include "ServiceBridge.h"
#include "lib/api/public/ServiceContext.h"
#include "lib/api/services/OrderService.pb.h"
#include "lib/api/services/PositionService.pb.h"
#include "lib/mercury/broker/BrokerProxy.h"
#include "lib/orderman/events/AccountPnLUpdateEvent.h"
#include "lib/orderman/events/ActivateOrderEvent.h"
#include "lib/orderman/events/CancelOrderEvent.h"
#include "lib/orderman/events/DetachOrderEvent.h"
#include "lib/orderman/events/ExcessLiquidityUpdateEvent.h"
#include "lib/orderman/events/NewAdminDataEvent.h"
#include "lib/orderman/events/OrderManagerReadyEvent.h"
#include "lib/orderman/events/OrderOpResultEvent.h"
@@ -15,13 +17,11 @@
#include "lib/orderman/events/UpdateOrderEvent.h"
#include "lib/orderman/order_factory/OrderFactory.h"
#include "lib/orderman/order_router/OrderRouter.h"
#include "lib/orderman/orderman_utils/orderman_common.h"
#include "lib/orderman/orders/Order.h"
#include "lib/orderman/securities/MapSecurityDB.h"
#include "lib/tracing/PerfLog.h"
#include "lib/utils/PBUtils.h"
#include "lib/api/services/OrderService.pb.h"
#include "lib/orderman/orderman_utils/orderman_common.h"
#include "lib/orderman/orders/Order.h"
#include <future>
namespace bts {
@@ -53,6 +53,7 @@ struct ServiceBridge::PImpl {
mercury::Stream<DetachOrderEvent> detach_order_pub;
mercury::Stream<NewAdminDataEvent> new_admin_data_pub;
mercury::Stream<AccountPnLUpdateEvent> account_pnl_pub;
mercury::Stream<ExcessLiquidityUpdateEvent> excess_liquidity_pub;
std::unordered_set<OrderKey> known_orders;
std::vector<std::shared_ptr<const api::admin::AdminData>> admin_data_updates;
mercury::BrokerProxy &service_call_marshaller;
@@ -85,6 +86,7 @@ void ServiceBridge::init() {
me->detach_order_pub = make_stream<DetachOrderEvent>();
me->new_admin_data_pub = make_stream<NewAdminDataEvent>();
me->account_pnl_pub = make_stream<AccountPnLUpdateEvent>();
me->excess_liquidity_pub = make_stream<ExcessLiquidityUpdateEvent>();
me->ready.set_value();
}
@@ -236,6 +238,21 @@ void ServiceBridge::update_account_pnl(
});
}
void ServiceBridge::update_excess_liquidity_report(
api::position::Excess_liquidity_reportUpdate const &elr) {
me->service_call_marshaller.schedule_action([this, elr]() {
for (auto const &elr : elr.added()) {
publish(me->excess_liquidity_pub, AccountID(elr->account_id()),
elr->excess_liquidity());
}
for (auto const &elr : elr.changed()) {
publish(me->excess_liquidity_pub,
AccountID(elr.current()->account_id()),
elr.current()->excess_liquidity());
}
});
}
bool ServiceBridge::is_ready() const {
return me->have_orders && me->order_manager_ready;
}
+3
View File
@@ -1,5 +1,6 @@
#pragma once
#include "lib/api/services/MarginService.client.pb.h"
#include "lib/api/services/PositionService.client.pb.h"
#include "lib/config/protos/jetfix.pb.h"
#include "lib/md/SecurityOracle.h"
@@ -77,6 +78,8 @@ class ServiceBridge : public mercury::Actor {
void
update_admin_data(std::shared_ptr<api::admin::AdminData const> const &admin);
void update_account_pnl(api::position::Pnl_account_dataUpdate const &);
void update_excess_liquidity_report(
api::position::Excess_liquidity_reportUpdate const &);
private:
struct PImpl;
@@ -5,6 +5,7 @@
#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/ExcessLiquidityUpdateEvent.h"
#include "lib/orderman/events/NewAdminDataEvent.h"
#include "lib/orderman/events/NewSecuritiesEvent.h"
#include "lib/orderman/events/OrderManagerReadyEvent.h"
@@ -55,6 +56,9 @@ void OrderManager::init() {
[this](auto const &admin_update) { this->on_admin_data(admin_update); });
subscribe<AccountPnLUpdateEvent>(
[this](auto const &pnl_update) { this->on_pnl_update(pnl_update); });
subscribe<ExcessLiquidityUpdateEvent>([this](auto const &liq_update) {
this->on_excess_liquidity_update(liq_update);
});
}
void OrderManager::on_admin_data(const mercury::Update<NewAdminDataEvent> &m) {
@@ -77,10 +81,18 @@ void OrderManager::on_admin_data(const mercury::Update<NewAdminDataEvent> &m) {
}
}
void OrderManager::on_pnl_update(const mercury::Update<AccountPnLUpdateEvent> &u) {
if (u.events)
for (auto ev : *u.events)
me->services_data.limiter.set_day_pnl(ev.account_id,ev.day_pnl);
void OrderManager::on_pnl_update(
const mercury::Update<AccountPnLUpdateEvent> &u) {
if (u.events)
for (auto ev : *u.events)
me->services_data.limiter.set_day_pnl(ev.account_id, ev.day_pnl);
}
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);
}
void OrderManager::on_securities(
@@ -35,6 +35,7 @@ class CreateFIXBufferReplyEvent;
class GatewayStatusChangeEvent;
class NewAdminDataEvent;
class AccountPnLUpdateEvent;
class ExcessLiquidityUpdateEvent;
struct SessionServicesData;
class DynamicOrderRegistry;
} // namespace orderman
@@ -85,6 +86,7 @@ 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;
// end external events
@@ -0,0 +1,25 @@
#pragma once
#include "lib/mercury/common/mercury_common.h"
#include "lib/mercury/events/Event.h"
#include "lib/mercury/synopsis/MergeByKey.h"
#include <memory>
namespace bts {
namespace orderman {
class ExcessLiquidityUpdateEvent : public mercury::Event<ExcessLiquidityUpdateEvent> {
public:
using SynopsisPolicy = mercury::MergeByKey<ExcessLiquidityUpdateEvent>;
AccountID key() const { return account_id; }
ExcessLiquidityUpdateEvent(AccountID id, double excess_liquidity)
: account_id(id), excess_liquidity(excess_liquidity) {}
AccountID account_id;
double excess_liquidity;
};
} // namespace orderman
} // namespace bts
+10 -2
View File
@@ -32,11 +32,13 @@ void LimitStore::copy_data_from(LimitStore &source) {
if (source_security_limit_tree != nullptr)
it->second.copy_positions_from(*source_security_limit_tree);
}
// copy pnl's
// copy pnl's and liqs
for (auto it=_account_data_map.begin();it!=_account_data_map.end();it++){
auto source_it = source._account_data_map.find(it->first);
if(source_it != source._account_data_map.end())
if(source_it != source._account_data_map.end()) {
it->second.curr_day_pnl = source_it->second.curr_day_pnl;
it->second.excess_liquidity = source_it->second.excess_liquidity;
}
}
}
void LimitStore::set_pnl (AccountID account_id, double pnl){
@@ -44,6 +46,12 @@ void LimitStore::set_pnl (AccountID account_id, double pnl){
bts_assert(it != _account_data_map.end());
it->second.curr_day_pnl = pnl;
}
void LimitStore::set_excess_liquidity (AccountID account_id,
double excess_liquidity){
auto it = _account_data_map.find(account_id.value());
bts_assert(it != _account_data_map.end());
it->second.excess_liquidity = excess_liquidity;
}
void LimitStore::_add_product_entry(
const api::Security &security,
const bts::api::admin::AdminData &admin_data) {
+49 -7
View File
@@ -10,6 +10,9 @@
#include "ProductLimitTree.h"
#include "SecurityLimitTree.h"
#include "lib/os/os.h"
#include "lib/config/config.h"
#include "lib/config/protos/span.pb.h"
namespace bts {
namespace orderman {
@@ -39,10 +42,12 @@ private:
public:
const bts::api::admin::BTSAccount& account;
double curr_day_pnl;
double excess_liquidity;
AccountData (const bts::api::admin::BTSAccount& account)
:
account(account),
curr_day_pnl (os::nan())
curr_day_pnl (os::nan()),
excess_liquidity (os::nan())
{}
};
const bts::api::admin::AdminData _admin_data;
@@ -107,6 +112,7 @@ public:
}
}
void set_pnl (AccountID account_id, double pnl);
void set_excess_liquidity (AccountID account_id, double excess_liquidity);
// risk limit checks
////////////////////
// checks to see if the user is allowed to trade
@@ -152,7 +158,13 @@ public:
Quantity quantity,
bool enforce_clip = true) const{
Limiter::LimiterQueryResult rv; rv.result = Limiter::OK;
_loss_limit(account_id, rv);
const auto acct_it = _account_data_map.find(account_id.value());
AccountData const* account_ptr = (acct_it == _account_data_map.end()) ?
nullptr : &(acct_it->second);
_loss_limit(account_ptr, rv);
if(!rv.ok())
return rv;
_margin_limit(account_ptr,rv);
if(!rv.ok())
return rv;
const SecurityLimitTree* sec_tree = _find_security(security.id());
@@ -183,10 +195,13 @@ public:
Quantity from, Quantity to,
bool enforce_clip = true) const{
Limiter::LimiterQueryResult rv; rv.result = Limiter::OK;
const auto acct_it = _account_data_map.find(account_id.value());
AccountData const* account_ptr = (acct_it == _account_data_map.end()) ?
nullptr : &(acct_it->second);
// in case of order modifications, loss limits are only checked
// for size increases
if (to.value() > from.value())
_loss_limit(account_id, rv);
_loss_limit(account_ptr, rv);
if(!rv.ok())
return rv;
const SecurityLimitTree* sec_tree = _find_security(security.id());
@@ -226,16 +241,15 @@ private:
void _add_product_entry(const api::Security& security,
const bts::api::admin::AdminData& admin_data);
void _set_user_data();
void _loss_limit(AccountID account_id,
void _loss_limit(AccountData const* account_ptr,
Limiter::LimiterQueryResult& out_res) const{
// the usual flow should not alter out_res.
// its set to an error state iff :
// i. account is not found
// ii. limit check is enabled but pnl is nan
// iii. limit check is enable and it actually fails
const auto acct_it = _account_data_map.find(account_id.value());
if(acct_it != _account_data_map.end()){
const auto& account_data = acct_it->second;
if(account_ptr != nullptr){
const auto& account_data = *account_ptr;
const auto& account = account_data.account;
if (account.has_account_loss_limit() &&
account.account_loss_limit().enforce()){
@@ -260,5 +274,33 @@ private:
out_res.error_msg = "Could not find account";
}
}
void _margin_limit(AccountData const* account_ptr,
Limiter::LimiterQueryResult& out_res) const{
// similiar flow as the loss_limit above
if(account_ptr != nullptr){
const auto& account_data = *account_ptr;
const auto& account = account_data.account;
if(config::get<bts::config::SpanMargin>().enabled()) {
if (account.has_margin_limit() && account.margin_limit().enforce_margin()){
double ex_liq = account_data.excess_liquidity;
if(os::is_nan(ex_liq)){
out_res.result = Limiter::LimiterErrorCode::MARGIN_LIMIT_BREACHED;
out_res.error_msg = "Could not find account Excess Liquidity";
}
else{
if(ex_liq < 0){
out_res.result = Limiter::LimiterErrorCode::MARGIN_LIMIT_BREACHED;
out_res.error_msg = fmt::format("Margin Limit Excess Liquidity : {}",
ex_liq);
}
}
}
}
}
else{
out_res.result = Limiter::LimiterErrorCode::NO_SUCH_ACCOUNT;
out_res.error_msg = "Could not find account";
}
}
};
}}
+9
View File
@@ -78,6 +78,15 @@ void Limiter::set_day_pnl (AccountID account_id, double pnl){
_add_account_and_reset(account_id);
me->limit_store->set_pnl(account_id, pnl);
}
void Limiter::set_excess_liquidity (AccountID account_id,
double excess_liquidity) {
LOG(OrderMan, Info,
"Limiter::set_excess_liquidity account:{} excess_liquidity: {}",
account_id, excess_liquidity);
if (!me->limit_store->has_account(account_id))
_add_account_and_reset(account_id);
me->limit_store->set_excess_liquidity(account_id, excess_liquidity);
}
Limiter::LimiterQueryResult Limiter::can_trade(UserID user_id,
AccountID account_id) const {
LimiterQueryResult rv = me->limit_store->can_trade(user_id, account_id);
+4 -2
View File
@@ -34,7 +34,8 @@ class Limiter {
void remove(api::Security const &, std::string const & /* account_name */,
api::Side, Quantity, bool recurse);
void set_day_pnl (AccountID account_id, double pnl);
void set_excess_liquidity(AccountID account_id, double excesss_liquidity);
enum LimiterErrorCode {
OK,
NO_SUCH_SECURITY,
@@ -47,7 +48,8 @@ class Limiter {
NO_SUCH_ACCOUNT,
USER_DEACTIVATED,
NO_SUCH_USER,
LOSS_LIMIT_BREACHED
LOSS_LIMIT_BREACHED,
MARGIN_LIMIT_BREACHED
};
struct LimiterQueryResult {
@@ -19,8 +19,8 @@
#include "lib/orderman/orders/algo/algo_orders/TopAlgo.h"
#include "lib/orderman/orders/algo/algo_orders/IcebergAlgo.h"
#include "lib/orderman/orders/algo/algo_orders/LeanAlgo.h"
#include "lib/orderman/orders/algo/algo_orders/OffsetAlgo.h"
#include "lib/orderman/orders/book_algos/OCOOrder.h"
#include "lib/orderman/orders/book_algos/OffsetOrder.h"
#include "lib/orderman/orders/book_algos/PricerOrder.h"
#include "lib/orderman/orders/spreader_orders/SpreaderOrder.h"
#include "lib/orderman/orders/CompositeOrder.h"
@@ -183,7 +183,7 @@ Order &OrderFactory::allocate(OrderKey k, OrderKey pk,
new orderman::AlgoWrapperOrder(std::make_unique<CoverAlgo>()));
break;
case CustomOrderDefinition::kOffset:
order_ptr.reset(new orderman::OffsetOrder());
order_ptr.reset(new orderman::AlgoWrapperOrder(std::make_unique<OffsetAlgo>()));
break;
case CustomOrderDefinition::kQueueHolder:
order_ptr.reset(new orderman::QueueHolderOrder());
@@ -14,6 +14,7 @@ bool can_consume_attachment(api::orderman::CustomOrderDefinition::CustomCase ord
case CustomOrderDefinition::kTop:
case CustomOrderDefinition::kCover:
case CustomOrderDefinition::kLean:
case CustomOrderDefinition::kOffset:
return true;
default:
return false;
@@ -44,6 +45,10 @@ bool should_forward_attachment(
return
cdef.lean().has_child() &&
can_consume_attachment(cdef.lean().child().custom_case());
case CustomOrderDefinition::kOffset:
return
cdef.offset().has_child() &&
can_consume_attachment(cdef.offset().child().custom_case());
default:
return false;
}
@@ -0,0 +1,190 @@
#include "lib/orderman/orders/algo/IAlgoServices.h"
#include "lib/orderman/orders/algo/algo_orders/OffsetAlgo.h"
#include "lib/orderman/order_factory/IOrderFactory.h"
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
#include "lib/os/os.h"
#include "lib/utils/PBUtils.h"
namespace bts {
namespace orderman {
using namespace api::orderman;
using namespace std;
enum class OffsetAlgo::Status { WAITING_FOR_MD, DEPLOYED };
struct OffsetAlgo::PImpl {
IAlgoServices *algo;
Status status = Status::WAITING_FOR_MD;
OrderKey child_key = null_order_key();
ChildTemplate *child_template = nullptr;
Book last_book;
uint32_t tick_offset_on_deploy;
double child_price = os::nan();
};
OffsetAlgo::OffsetAlgo() : me(new PImpl()) {}
OffsetAlgo::~OffsetAlgo() {}
IAlgoServices &OffsetAlgo::algo() const { return *me->algo; }
OrderOpResult OffsetAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv) {
auto &def = serv.definition();
bts_assert(def.has_custom_def());
bts_assert(def.custom_def().has_offset());
// Validate the offset part of the definition
auto &offset = def.custom_def().offset();
if (!offset.has_child() &&
OrderKey(def.attach_target_order_key()) == null_order_key()) {
return OrderOpResult{
ORDER_ERROR_INVALID_ORDER_DEFINITON,
"Offset order must have either a child order definition or an "
"order to attach to"};
}
me->tick_offset_on_deploy = offset.tick_offset_on_deploy();
if (!serv.is_attaching()) {
// if we are not attaching create a child template so we can
// quickly launch our child when the time comes.
auto child_def = def;
*child_def.mutable_custom_def() = def.custom_def().offset().child();
me->child_template = &(serv.make_child_template(child_def));
}
return {};
}
void OffsetAlgo::do_launch(IAlgoServices &algo) {
me->algo = &algo;
bts_assert(me->child_template);
algo.subscribe_book(SecurityKey(algo.security().id()));
}
void OffsetAlgo::do_launch_attached(IAlgoServices &algo, OrderKey k,
ChildState st) {
me->algo = &algo;
me->child_key = k;
me->child_price = st.price.value();
algo.subscribe_book(SecurityKey(algo.security().id()));
}
void OffsetAlgo::do_update(api::orderman::Update const &update) {
LOG(OrderMan, Diag, "OffsetAlgo order {} receiving update: {}",
algo().order_key().value(), utils::pb::to_string(update));
if (update.has_custom()) {
if (!update.custom().has_offset()) {
algo().terminate_error("Invalid update");
return;
}
me->tick_offset_on_deploy =
update.custom().offset().tick_offset_on_deploy();
}
switch (me->status) {
case Status::WAITING_FOR_MD:
if (update.has_custom()) {
if (algo().is_attaching()) {
// don't change the child's price
// (need md to determine initial deploy price)
bts_assert(!os::is_nan(me->child_price));
algo().update_child(me->child_key, mk_child_update(update, me->child_price));
} else {
auto &def = algo().definition();
auto child_def = def;
*child_def.mutable_custom_def() = update.custom().offset().child();
me->child_template = &(algo().make_child_template(child_def));
}
}
break;
case Status::DEPLOYED:
algo().update_child(me->child_key, mk_child_update(update));
break;
}
}
void OffsetAlgo::on_book(SecurityKey, Book const &b) {
me->last_book = b;
// log top of book
LOG(OrderMan, Diag, "OffsetAlgo order {} on book. BID: {}@{} ASK: {}@{}",
algo().order_key().value(), b.side(api::SIDE_BUY)[0].size(),
b.side(api::SIDE_BUY)[0].price(), b.side(api::SIDE_SELL)[0].size(),
b.side(api::SIDE_SELL)[0].price());
// attempt deploy
if (me->status == Status::WAITING_FOR_MD)
try_deploy();
}
Update OffsetAlgo::mk_child_update(const Update &source, const double &price_override) {
Update target;
if (source.has_custom()) {
bts_assert(source.custom().has_offset());
*target.mutable_custom() = source.custom().offset().child();
}
if (!os::is_nan(price_override))
target.set_price(price_override);
else
target.set_price(source.price());
target.set_quantity(source.quantity());
return target;
}
void OffsetAlgo::try_deploy() {
bts_assert(me->status == Status::WAITING_FOR_MD);
auto side = algo().definition().side();
auto &top_psz = me->last_book.side(side)[0];
if (!top_psz.size()) {
// log state (still waiting for md)
LOG(OrderMan, Diag,
"OffsetAlgo order {} still waiting for md. Order: {} {}@ {} ticks "
"away.",
algo().order_key().value(), algo().definition().side(),
algo().quantity().value(), me->tick_offset_on_deploy);
} else {
const double &offset = securities::tick_size(algo().security()).value() *
me->tick_offset_on_deploy;
me->child_price =
securities::worsen_price(side, Price(top_psz.price()), Price(offset)).value();
if (algo().is_attaching()) {
// log imminent update
LOG(OrderMan, Diag,
"OffsetAlgo order {} attaching child {}. Order: {} {}@ {} ({} ticks "
"away).",
algo().order_key().value(),
me->child_key.value(), side,
algo().quantity().value(),
me->child_price, me->tick_offset_on_deploy);
// update
Update child_update;
child_update.set_quantity(algo().quantity().value());
child_update.set_price(me->child_price);
algo().update_child(me->child_key, child_update);
} else {
// log imminent deploy
LOG(OrderMan, Diag,
"OffsetAlgo order {} deploying child. Order: {} {}@ {} ({} ticks "
"away).",
algo().order_key().value(), side,
algo().quantity().value(),
me->child_price, me->tick_offset_on_deploy);
// deploy
me->child_key =
algo().launch_child(*me->child_template, Price(me->child_price), algo().quantity());
}
algo().set_ladder_visibility(false);
me->status = Status::DEPLOYED;
}
}
void OffsetAlgo::on_child_change(OrderKey, ChildState const &st) {
me->child_price = st.price.value();
algo().update_fill_state(st.total_fills, st.last_price);
switch (st.status) {
case ChildStatus::WORKING:
return;
case ChildStatus::COMPLETED:
algo().complete();
return;
case ChildStatus::CANCELED:
algo().cancel("Unexpected child cancel");
return;
}
}
} // namespace orderman
} // namespace bts
@@ -0,0 +1,38 @@
#pragma once
#include "lib/orderman/orders/algo/IAlgoOrder.h"
using Update = bts::api::orderman::Update;
namespace bts {
namespace orderman {
// Offset sends a child-order/algo N ticks away from the top of the book.
// If necessary, it will wait for the market to arrive before shooting the
// child.
class OffsetAlgo : public IAlgoOrder {
public:
OffsetAlgo();
~OffsetAlgo();
OrderOpResult do_before_launch(IBeforeLaunchAlgoServices &) override;
void do_launch(IAlgoServices &) override;
void do_launch_attached(IAlgoServices &, OrderKey, ChildState) override;
void do_update(Update const &) override;
void on_book(SecurityKey, Book const &) override;
void on_child_change(OrderKey, ChildState const &) override;
private:
enum class Status;
struct PImpl;
std::unique_ptr<PImpl> me;
static Update mk_child_update(const Update& source_update, const double& price_override = os::nan());
IAlgoServices &algo() const;
void try_deploy();
};
} // namespace orderman
} // namespace bts
@@ -16,6 +16,7 @@ using namespace api::orderman;
struct TopAlgo::PImpl {
IAlgoServices *algo;
spark::QuantityMeasure top_threshold_measure;
uint32_t ticks_off = 0;
OrderKey child_key = null_order_key();
ChildTemplate *child_template = nullptr;
Book last_book;
@@ -41,7 +42,7 @@ OrderOpResult TopAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv) {
}
me->top_threshold_measure = top.top_threshold();
me->ticks_off = top.ticks_off();
if (!serv.is_attaching()) {
// if we are not attaching create a child template so we can
// quickly launch our child when the time comes.
@@ -87,13 +88,14 @@ void TopAlgo::do_update(api::orderman::Update const &update) {
auto &top_update = update.custom().top();
*child_update.mutable_custom() = top_update.child();
me->top_threshold_measure = top_update.top_threshold();
me->ticks_off = top_update.ticks_off();
}
algo().update_child(me->child_key, child_update);
}
void TopAlgo::on_book(SecurityKey, Book const &b) {
me->last_book = b;
ensure_min_quantity();
ensure_order_meets_constraints();
}
void TopAlgo::on_child_change(OrderKey, ChildState const &st) {
@@ -111,14 +113,14 @@ void TopAlgo::on_child_change(OrderKey, ChildState const &st) {
}
}
bool TopAlgo::ensure_min_quantity() {
bool TopAlgo::ensure_order_meets_constraints() {
LOG(OrderMan, Diag,
"Top order {} received book update. Current top of book: {}@{}",
algo().order_key().value(), top_of_book_quantity().value(),
top_of_book_price().value());
if (better_than_top()) {
LOG(OrderMan, Diag,
LOG(OrderMan, Info,
"Top order {} became better than the top of the book, canceling",
algo().order_key().value());
algo().cancel("Order would become BBO");
@@ -135,7 +137,7 @@ bool TopAlgo::ensure_min_quantity() {
algo().order_key().value(), total_min_quantity,
top_of_book_quantity().value());
if (top_of_book_quantity() < Quantity(total_min_quantity)) {
LOG(OrderMan, Diag,
LOG(OrderMan, Info,
"Top order {} is canceling because min quantiy is not met",
algo().order_key().value());
algo().cancel("Top of book is below threshold");
@@ -147,6 +149,26 @@ bool TopAlgo::ensure_min_quantity() {
algo().order_key().value(), algo().price().value(),
top_of_book_price().value());
if (me->ticks_off > 0) {
auto tick_diff = securities::price_diff_to_ticks(
algo().price().value(), top_of_book_price().value(),
securities::tick_size(algo().security()).value());
if (std::abs(tick_diff) <= (int)me->ticks_off) {
LOG(OrderMan, Info,
"Top order {} price {} is less than {} ticks away from top ({}). "
"Canceling",
algo().order_key().value(), algo().price().value(),
me->ticks_off + 1, top_of_book_price().value());
algo().cancel("Order is too close to top of the book");
return false;
} else
LOG(OrderMan, Diag,
"Top order {} price {} is {} ticks away from top. Top: {} Ticks "
"off: {}",
algo().order_key().value(), algo().price().value(),
std::abs(tick_diff), top_of_book_price().value(), me->ticks_off);
}
return true;
}
@@ -27,7 +27,7 @@ class TopAlgo : public IAlgoOrder {
bool at_top_of_book() const;
bool better_than_top() const;
Quantity min_quantity_at_top() const;
bool ensure_min_quantity();
bool ensure_order_meets_constraints();
bool has_running_child() const;
Price top_of_book_price() const;
Quantity top_of_book_quantity() const;
@@ -1,102 +0,0 @@
#include "OffsetOrder.h"
#include "lib/orderman/actors/order_manager/OrderBuilder.h"
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
#include "lib/utils/PBUtils.h"
#include <google/protobuf/timestamp.pb.h>
namespace bts {
namespace orderman {
using namespace api::orderman;
struct OffsetOrder::PImpl
{
PImpl() {}
uint32_t tick_offset_on_deploy;
};
OffsetOrder::OffsetOrder() : me(new PImpl()) {}
OffsetOrder::~OffsetOrder() {}
void OffsetOrder::setup_child(const api::orderman::OrderDefinition& this_def, const PreActivationOrderServices&,
api::orderman::OrderState& initial_state, api::orderman::OrderDefinition* out_child)
{
initial_state.mutable_offset();
auto const &offset_def = this_def.custom_def().offset();
*out_child->mutable_custom_def() = offset_def.child();
me->tick_offset_on_deploy = offset_def.tick_offset_on_deploy();
}
void OffsetOrder::on_book_update(const bts::orderman::BookUpdateEvent& book)
{
switch (this_state().status())
{
case ORDER_STATUS_WORKING:
switch (child_state().status())
{
case ORDER_STATUS_INACTIVE:
{
if(definition().side() == api::SIDE_BUY)
{
const auto& same = book.book.side(api::Side::SIDE_BUY)[0];
double price = same.price() - tick_size() * me->tick_offset_on_deploy;
activate_child(Price(price), Quantity(this_state().quantity()));
transition(ORDER_STATUS_WORKING);
}
else
{
const auto& same = book.book.side(api::Side::SIDE_SELL)[0];
double price = same.price() + tick_size() * me->tick_offset_on_deploy;
activate_child(Price(price), Quantity(this_state().quantity()));
transition(ORDER_STATUS_WORKING);
}
report_state();
}
break;
case ORDER_STATUS_WORKING:
{
detach();
}
break;
case ORDER_STATUS_PENDING_WORKING:
break;
// child cannot be in any of these states if we are in the working state
case ORDER_STATUS_DISCONNECTED:
case ORDER_STATUS_ERROR:
case ORDER_STATUS_REJECTED_BY_SPARK:
case ORDER_STATUS_COMPLETED:
case ORDER_STATUS_CANCELED:
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
bts_assert(false);
break;
}
break;
case ORDER_STATUS_COMPLETED:
case ORDER_STATUS_CANCELED:
case ORDER_STATUS_ERROR:
break;
case ORDER_STATUS_INACTIVE:
case ORDER_STATUS_REJECTED_BY_SPARK:
case ORDER_STATUS_PENDING_WORKING:
case ORDER_STATUS_DISCONNECTED:
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
bts_assert(false);
break;
}
}
}
}
@@ -1,29 +0,0 @@
#pragma once
#include "lib/orderman/orders/book_algos/BookAlgo.h"
namespace bts {
namespace orderman {
class OrderStateUpdateEvent;
class BookUpdateEvent;
//OffsetOrder deploys N ticks away from the initial same-side inside market it's mainly for composition / fat finger
class OffsetOrder : public BookAlgo
{
public:
OffsetOrder();
virtual ~OffsetOrder();
protected:
void setup_child(const api::orderman::OrderDefinition& this_def, const PreActivationOrderServices&,
api::orderman::OrderState&, api::orderman::OrderDefinition*) override;
void on_book_update(const bts::orderman::BookUpdateEvent&) override;
private:
struct PImpl;
std::unique_ptr<PImpl> me;
};
}}
@@ -130,7 +130,7 @@ public:
for (auto& o : _orders){
// is_cancelled() is checked so as not to keep
// sending cancel requests
if(!o.is_cancelled()&&o.acknowledged()&&!o.terminal_status())
if(!o.cancel_sent()&&o.acknowledged()&&!o.terminal_status())
o.cancel_order();
}
}
@@ -118,6 +118,12 @@ ChildOrder SpreaderOrder::get_new_hedge_order(size_t leg_index){
bts::orderman::ChildOrder child_order = leg_data.hedger_order_builder().build();
return child_order;
}
void SpreaderOrder::send_hedge_order (size_t hedge_leg_index,
Price hedge_price,
Quantity hedge_qty,
bool use_quoting_order){
_send_hedge(hedge_leg_index, hedge_price, hedge_qty, use_quoting_order);
}
// events from orders system ////////////////////
/////////////////////////////////////////////////
void SpreaderOrder::_on_time(const bts::mercury::TimerEvent& t_event){
@@ -368,10 +374,12 @@ bool SpreaderOrder::_quoters_can_accept_modification (){
}
void SpreaderOrder::_send_hedge(size_t hedge_leg_index,
Price hedge_price,
Quantity hedge_qty){
Quantity hedge_qty,
bool use_quoting_order){
_bookkeeping_data().add_new_hedger (hedge_leg_index,
hedge_price,
hedge_qty);
hedge_qty,
use_quoting_order);
}
void SpreaderOrder::_compute_hedge_price_quantity(size_t filled_leg_index,
Price fill_price,
@@ -140,10 +140,13 @@ public:
}
void setup_new_quoter_order (size_t leg_index) override;
ChildOrder get_new_hedge_order (size_t leg_index) override;
void send_hedge_order (size_t hedge_leg_index,
Price hedge_price,
Quantity hedge_qty,
bool use_quoting_order = false) override;
inline bool in_cache_warming_cycle() const override{
return _cw_helper.in_cache_warming_cycle;
}
private:
// events from orders system ////////////////////
/////////////////////////////////////////////////
@@ -235,7 +238,8 @@ private:
// quantity 'filled_quantity'
void _send_hedge(size_t hedge_leg_index,
Price hedge_price,
Quantity hedge_qty);
Quantity hedge_qty,
bool use_quoting_order);
void _compute_hedge_price_quantity(size_t filled_leg_index,
Price filled_price,
double filled_quantity,
@@ -7,12 +7,17 @@ namespace orderman {
class LegPropertyData;
class CacheWarmingState;
class SpreaderChildOrderState;
// The Spreader spawns a bunch of quoters and
// hedgers and hands them this interface to
// i. get data such as book and leg properties
// (in O(1) access time)
// ii. create new quoter order
class ISpreaderManager{
public:
struct OrderTransfer{
SpreaderChildOrderState* q_order;
};
public:
virtual bts::orderman::OrderKey spreader_order_key() const = 0;
virtual bts::TimeStamp current_time() const = 0;
@@ -28,6 +33,14 @@ public:
// it does not alter the state or has side effects (as
// as the spreader goes)
virtual ChildOrder get_new_hedge_order (size_t leg_index) = 0;
// sends a new hedge for the leg index at a specified
// hedge price and size. when use_quoting_order is
// set to true the hegder is passed over the quoting
// order (and its state) to hedge
virtual void send_hedge_order (size_t hedge_leg_index,
Price hedge_price,
Quantity hedge_qty,
bool use_quoting_order) = 0;
// the spreader can be in a cache warming cycle and generate
// fake updates, the quoters and hedgers should ignore them
// (however do as much as they can to keep the instruction
@@ -35,7 +35,9 @@ public:
const bts::api::Security& security() const { return _leg_contract.security(); }
double price_multiplier() const { return _leg_contract.price_multiplier(); }
double size_multiplier() const { return _leg_contract.quantity(); }
double tick_size() const { return _leg_contract.security().contract_spec().low_tick(); }
double tick_size() const {
return _leg_contract.security().contract_spec().low_tick();
}
bool is_active_quoting() const {return _leg_params.is_active_quoting();}
bool is_net_change() const{
return _price_calc==bts::api::SyntheticContract::PRICECALC_NET_CHANGE;
@@ -56,6 +58,9 @@ public:
uint32_t n_queue_holder_orders() const{
return _leg_params.quote_params().n_queue_holder_orders();
}
bts::spark::UseSpreaderQuoteForHedging use_quote_for_hedging() const{
return _leg_params.quote_params().use_quote_for_hedging();
}
};
}}
@@ -83,8 +83,9 @@ _end_state_worker (this, other._end_state_worker){
/****************************External Calls**************************/
/********************************************************************/
void SingleFillHedger::init_hedger (Price price,
Quantity quantity){
_worker->init(price,quantity);
Quantity quantity,
ISpreaderManager::OrderTransfer* order){
_worker->init(price, quantity, order);
}
void SingleFillHedger::on_order_update(const SpreaderChildOrderState& u){
//bts_assert (u.order_key() == _order.order_key());
@@ -138,7 +139,9 @@ void SingleFillHedger::transform_to_WAITING_FOR_FIRST_ACK_CANCELLED () {
_switch_state (&_waiting_for_first_ack_cancelled_state_worker);
}
void SingleFillHedger::transform_to_WORKING() {
bts_assert(_worker->state() == HedgerState::WAITING_FOR_FIRST_ACK);
bts_assert(_worker->state() == HedgerState::WAITING_FOR_FIRST_ACK ||
// in case of quoting orders assigned to hedger
_worker->state() == HedgerState::START);
_switch_state (&_working_state_worker);
}
void SingleFillHedger::transform_to_WAITING_FOR_CANCEL_ACK(){
@@ -58,6 +58,9 @@ private:
void _modify_order (Price new_price){
_child_order_state.modify_order(new_price);
}
void _modify_order (Price new_price, Quantity qty){
_child_order_state.modify_order(new_price, qty);
}
void _cancel_order () {
_child_order_state.cancel_order();
}
@@ -93,7 +96,9 @@ public:
//that live in the START state until...
//iii.until init_hedger is called which sets the price
//qty and causes the order to be submitted
void init_hedger (Price price, Quantity quantity);
void init_hedger (Price price,
Quantity quantity,
ISpreaderManager::OrderTransfer* order = nullptr);
//b. called by the spreader when there is an order update
// reported by the exchange
void on_order_update(const SpreaderChildOrderState& order_update_message);
@@ -112,13 +112,17 @@ void SingleLegQuoter::on_book(size_t leg_index,
_worker->on_book (leg_index, book);
}
void SingleLegQuoter::update_other_leg_fills(size_t leg_index,
Quantity filled_quantity){
Quantity filled_quantity,
Price hedge_price,
Quantity hedge_qty){
bts_assert(_active_quoting);
LOG(OrderMan, Info, "SingleLegQuoter::update_other_leg_fills "
"spread_key:{} leg_idx:{} fill_idx:{} filled_quantity:{}",
_spreader.spreader_order_key(), _this_leg_data.leg_index(),
leg_index, filled_quantity);
_worker->on_other_leg_quoter_fill (leg_index, filled_quantity);
if(hedge_qty.value()>0)
LOG(OrderMan, Info, "SingleLegQuoter::update_other_leg_fills "
"spread_key:{} leg_idx:{} fill_idx:{} filled_quantity:{}",
_spreader.spreader_order_key(), _this_leg_data.leg_index(),
leg_index, filled_quantity);
_worker->on_other_leg_quoter_fill (leg_index, filled_quantity,
hedge_price, hedge_qty);
}
void SingleLegQuoter::update_order_price_quantity(Price price,
Quantity quantity){
@@ -161,8 +165,18 @@ bool SingleLegQuoter::accept_modifications() const {
return _worker->state() == QuoterState::WAITING_FOR_SIZE ||
_worker->state() == QuoterState::WORKING;
}
void SingleLegQuoter::_incorporate_other_leg_fill (size_t, Quantity hedge_reduction){
void SingleLegQuoter::_incorporate_other_leg_fill (size_t,
Quantity hedge_reduction,
Price hedge_price,
Quantity hedge_qty,
bool send_new_hedge,
bool use_quoting_order){
_price_quantity_state.add_hedged_reduction (hedge_reduction);
if(send_new_hedge)
_spreader.send_hedge_order(_this_leg_data.leg_index(),
hedge_price,
hedge_qty,
use_quoting_order);
}
void SingleLegQuoter::_compute_quote(
Quantity target_qty,
@@ -15,6 +15,7 @@
#include "lib/orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForCancelAckStateWorker.h"
#include "lib/orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWorkingStateWorker.h"
#include "lib/orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterEndStateWorker.h"
#include "lib/orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForOrderTransferStateWorker.h"
#include "lib/orderman/orders/spreader_orders/spreader/quoter/QuoteLegDriver.h"
#include "lib/orderman/actors/order_manager/ChildOrder.h"
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.h"
@@ -35,6 +36,7 @@ friend QuoterWaitingForIOCWorker;
friend QuoterWaitingForFirstAckCancelledWorker;
friend QuoterWaitingForCancelAckStateWorker;
friend QuoterWorkingStateWorker;
friend QuoterWaitingForOrderTransferStateWorker;
friend QuoterEndStateWorker;
private:
const bool _two_legged;
@@ -115,7 +117,9 @@ public:
//g. this is called by the spreader when a quoting fill
// (ie not hedging fill) happens on one of the quoting
// legs
void update_other_leg_fills(size_t leg_index, Quantity filled_quantity);
void update_other_leg_fills(size_t leg_index, Quantity filled_quantity,
Price hedge_price = Price(0),
Quantity hedge_qty = Quantity(0));
//h. called when the user modified the spreader order price or quantity
void update_order_price_quantity(Price price, Quantity quantity);
// true if the quoter has an active working order. the order can
@@ -181,7 +185,12 @@ private:
}
void _cancel_order () {_child_order_state.cancel_order();}
// this updates the hedge reduction in _price_quantity_state
void _incorporate_other_leg_fill (size_t leg_index, Quantity hedge_reduction);
void _incorporate_other_leg_fill (size_t leg_index,
Quantity hedge_reduction,
Price hedge_price,
Quantity hedge_qty,
bool send_new_hedge = true,
bool use_quoting_order_to_hedge = false);
// given a target quoting qty
// this figures out the price and the actual
// qty that can be quoted.
@@ -103,12 +103,16 @@ public:
// and returns a ref to it
// (dont keep pointers to hedgers since the vector
// can resize)
inline SingleFillHedger& add_new_hedger(size_t leg_index,
inline SingleFillHedger& add_new_hedger(
size_t leg_index,
Price hedge_price,
Quantity hedge_quantity){
Quantity hedge_quantity,
bool use_quoting_order = false){
bts_assert(leg_index < _leg_data.size());
SpreaderLegData& leg_data=_leg_data[leg_index];
return leg_data.add_new_hedger(hedge_price,hedge_quantity);
return leg_data.add_new_hedger(hedge_price,
hedge_quantity,
use_quoting_order);
}
// finds the spreader fill, price (ie averages it out, using
// the size and price ratio, across all legs)
@@ -10,18 +10,20 @@ _is_live(src._is_live),
_sec_key(src._sec_key),
_is_quoting (src._is_quoting),
_test_only_order_key(src._test_only_order_key),
_base_price(src._base_price),
_base_quantity(src._base_quantity),
_n_place_orders(src._n_place_orders),
_n_cancel_orders(src._n_cancel_orders),
_n_modify_orders(src._n_modify_orders),
_base_price(src._base_price),
_base_quantity(src._base_quantity),
_child_order(std::move(src._child_order)),
_handover_filled_qty(Quantity(0)),
_status(src._status),
_filled_price(src._filled_price),
_filled_quantity(src._filled_quantity),
_last_filled_price(src._last_filled_price),
_last_update_filled_price(src._last_update_filled_price),
_last_update_filled_quantity(src._last_update_filled_quantity),
_last_reported_order_price(src._last_reported_order_price),
_last_filled_quantity(src._last_filled_quantity),
_last_reported_order_qty(src._last_reported_order_qty),
_out_price(src._out_price),
_out_quantity(src._out_quantity),
_order_place_time(src._order_place_time)
@@ -40,7 +42,8 @@ _base_quantity(0){
ChildOrder& empty_order=_empty_order();
re_init(empty_order);
}
void SpreaderChildOrderState::re_init (ChildOrder& child_order){
void SpreaderChildOrderState::re_init (ChildOrder& child_order,
Quantity handover_filled_qty){
SpreaderUtils::compute_average_price(_base_price, _base_quantity,
_filled_price, _filled_quantity,
_base_price, _base_quantity);
@@ -48,12 +51,14 @@ void SpreaderChildOrderState::re_init (ChildOrder& child_order){
_n_cancel_orders = _n_modify_orders = 0;
_child_order = ChildOrder();
_child_order = std::move(child_order);
_handover_filled_qty = handover_filled_qty;
_status = bts::api::orderman::OrderStatus::ORDER_STATUS_INACTIVE;
_filled_price = Price(0);
_filled_quantity = Quantity (0);
_last_filled_price = Price(0);
_last_update_filled_price = Price(0);
_last_update_filled_quantity = Quantity(0);
_last_reported_order_price=Price(0);
_last_filled_quantity = Quantity(0);
_last_reported_order_qty=Quantity(0);
_out_price = Price(0);
_out_quantity = Quantity(0);
_order_place_time=bts::TimeStamp();
@@ -4,6 +4,7 @@
#include "lib/api/services/OrderService.pb.h"
#include "lib/orderman/events/OrderStateUpdateEvent.h"
#include "SpreaderUtils.h"
#include "lib/domain_model/Security.h"
namespace bts {
namespace orderman {
@@ -20,17 +21,22 @@ private:
const SecurityKey _sec_key;
const bool _is_quoting;
const OrderKey _test_only_order_key;
// Since SpreaderChildOrderState can be assigned
// multiple ChildOrders during its lifetime, the
// accumulated fills and fill price from previous
// orders is kept here
Price _base_price;
Quantity _base_quantity;
// just for statistics
uint16_t _n_place_orders, _n_cancel_orders;
uint32_t _n_modify_orders;
// while child orders can recycle, their
// accumulated price, qty is kept here
Price _base_price;
Quantity _base_quantity;
ChildOrder _child_order;
ChildOrder _child_order;
// If the child order handled through re_init already
// is in a working state with fills
Quantity _handover_filled_qty;
api::orderman::OrderStatus _status;
// this is the total filled qty and
// average price for the active order
// average filled price for the active order
Price _filled_price;
Quantity _filled_quantity;
// this is the fill price, qty reported
@@ -38,16 +44,23 @@ private:
// (if no fill was reported but it was
// merely an order update, the qty
// here will be 0).
// _last_reported_order_price is the
// the working order price as it was
// last reported
Price _last_filled_price;
Price _last_reported_order_price;
Quantity _last_filled_quantity;
// this is latest price, qty sent out
Price _last_update_filled_price;
Quantity _last_update_filled_quantity;
// these are the order price and qty reported
// in the last update (this is the best knowledge
// of what is out there)
Price _last_reported_order_price;
Quantity _last_reported_order_qty;
// this is last price, qty sent out through
// the place_order or modify_order calls
Price _out_price;
Quantity _out_quantity;
Quantity _out_quantity;
bts::TimeStamp _order_place_time;
private:
bool _change_in_flight() const{
return !securities::is_same(_out_price, _last_reported_order_price) ||
_out_quantity != _last_reported_order_qty;
}
public:
// constructors ///////////////////
///////////////////////////////////
@@ -56,37 +69,52 @@ public:
SpreaderChildOrderState(SecurityKey sec_key,
bool is_live,
bool is_quoting);
SpreaderChildOrderState (SpreaderChildOrderState&& src);
SpreaderChildOrderState (SpreaderChildOrderState&& src);
SpreaderChildOrderState& operator=(const SpreaderChildOrderState&) = delete;
SpreaderChildOrderState& operator=(SpreaderChildOrderState&&) = delete;
// const accessors ////////////////////
///////////////////////////////////////
SpreaderChildOrderState& operator=(SpreaderChildOrderState&&) = delete;
////////////////////////////////////////////////////////////////////////////
// const direct accessors //////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
OrderKey order_key() const {
if (_is_live)
return _child_order.key();
// TODO
return _child_order.empty() ? OrderKey(0) : _child_order.key();
else
return _test_only_order_key;
}
api::orderman::OrderStatus status () const {
}
api::orderman::OrderStatus status() const {
return _status;
}
// if the last fill was a status change
// this will be zero
Price last_update_filled_price() const {
return _last_filled_price;
// this is the fills from the current active order
Quantity current_fills() const {
return _filled_quantity;
}
Price last_reported_order_price() const{
return _last_reported_order_price;
Price last_update_filled_price() const {
return _last_update_filled_price;
}
// if the last fill was a status change
// this will be zero
Quantity last_update_filled_quantity () const {
return _last_filled_quantity;
return _last_update_filled_quantity;
}
// all the status calls are based on the
// current order (and not the subsumed ones)
Price last_reported_order_price() const{
return _last_reported_order_price;
}
Quantity last_reported_order_quantity() const{
return _last_reported_order_qty;
}
Price out_price() const {
return _out_price;
}
Quantity out_quantity () const {
return _out_quantity;
}
bts::TimeStamp order_place_time() const{
return _order_place_time;
}
// status accessors ////////////////////////////////////////////////////////
bool terminal_status() const {
return SpreaderUtils::order_in_terminal_state(_status);
return SpreaderUtils::order_in_terminal_state(_status);
}
bool acknowledged() const {
return SpreaderUtils::order_acknowledged (_status);
@@ -100,8 +128,13 @@ public:
bool errored() const{
return SpreaderUtils::order_in_error_state(_status);
}
// this is total fills across current and
// previous orders
bool working() const{
return SpreaderUtils::order_in_working_state(_status);
}
bool cancel_sent() const{
return _n_cancel_orders > 0;
}
// total across multiple orders ////////////////////////////////////////////
Quantity total_fills() const {
return Quantity(_base_quantity.value() + _filled_quantity.value());
}
@@ -111,30 +144,29 @@ public:
_filled_price, _filled_quantity,
out_price, out_filled);
}
// this is the fills from the current active order
Quantity current_fills () const {
return _filled_quantity;
}
Price out_price() const {
return _out_price;
// returns true is there are no cancels
// or modifies in flight
bool stable_state() const{
return !cancel_in_flight() && !_change_in_flight();
}
Quantity out_quantity () const {
return _out_quantity;
}
bts::TimeStamp order_place_time() const{
return _order_place_time;
}
// returns true if the current order has been
// cancelled
bool is_cancelled() const{
return _n_cancel_orders>0;
// in-flight accessors /////////////////////////////////////////////////////
bool cancel_in_flight() const{
return cancel_sent() && !terminal_status();
}
// init ///////////////////
ChildOrder& active_order(){
return _child_order;
}
void re_init (){
ChildOrder empty_order;
re_init(empty_order);
}
///////////////////////////
// this assignes a new order, and subsumes the earlier order's
// fills and filled price into the base quantity and
// base filled price
void re_init (ChildOrder& child_order);
void re_init (ChildOrder& child_order,
Quantity handover_filled_qty = Quantity(0));
ChildOrder& _empty_order(){
_child_order = ChildOrder();
return _child_order;
@@ -144,16 +176,20 @@ public:
// last filled price
void on_order_update(const OrderStateUpdateEvent& e){
bts_assert(!_is_live || e.key == order_key());
bts_assert(e.filled_quantity >= _filled_quantity.value());
bts_assert(e.filled_quantity >= _handover_filled_qty.value());
uint32_t effective_filled_qty = e.filled_quantity -
_handover_filled_qty.value();
bts_assert(effective_filled_qty >= _filled_quantity.value());
_status = e.status;
_last_filled_quantity = Quantity(e.filled_quantity
_last_update_filled_quantity = Quantity(effective_filled_qty
- _filled_quantity.value());
_last_filled_price = Price(e.last_price);
_last_reported_order_price=Price(e.price);
_last_update_filled_price = Price(e.last_price);
_last_reported_order_price = Price(e.price);
_last_reported_order_qty = Quantity(e.quantity);
SpreaderUtils::compute_average_price(_filled_price,
_filled_quantity,
_last_filled_price,
_last_filled_quantity,
_last_update_filled_price,
_last_update_filled_quantity,
_filled_price,
_filled_quantity);
}
@@ -181,9 +181,16 @@ public:
return _hedger_manager.test_only_get_hedger_at(index);
}
SingleFillHedger& add_new_hedger(bts::Price hedge_price,
bts::Quantity hedge_quantity){
bts::Quantity hedge_quantity,
bool quote_as_hedge){
SingleFillHedger& rv = _hedger_manager.get_hedger();
rv.init_hedger (hedge_price,hedge_quantity);
ISpreaderManager::OrderTransfer* order_transfer = nullptr;
ISpreaderManager::OrderTransfer order_transfer_arg;
if(quote_as_hedge){
order_transfer_arg.q_order = _quoter_child_order_state;
order_transfer = &order_transfer_arg;
}
rv.init_hedger (hedge_price, hedge_quantity, order_transfer);
return rv;
}
};
@@ -114,6 +114,9 @@ public:
static bool order_in_cancelled_state (bts::api::orderman::OrderStatus order_status){
return order_status == api::orderman::OrderStatus::ORDER_STATUS_CANCELED;
}
static bool order_in_working_state(bts::api::orderman::OrderStatus order_status){
return order_status == api::orderman::OrderStatus::ORDER_STATUS_WORKING;
}
////////////////////////////////////////////////////
// market data /////////////////////////////////////
////////////////////////////////////////////////////
@@ -652,6 +655,24 @@ public:
out_cum_qty);
quantity = Quantity(std::min(quantity.value(),out_cum_qty.value()));
}
// given an order's filled and out qty, and the desired target
// from now on, this function finds the adjusted qty of the order
// example 1 : working order is 3/10, and we want to use
// this working order to get 9 from here on, this function
// will return 12, to make this 3/12, to allow for 9
// fills.
// example 2 : working order is 3/10, and we want 2 more fills,
// it will output 5
// increments are guarded by allow_inc
static uint32_t adjust_qty_to_target (uint32_t filled_qty,
uint32_t order_qty,
uint32_t target,
bool allow_inc){
uint32_t rv = filled_qty + target;
if (rv > order_qty && !allow_inc)
rv = order_qty;
return rv;
}
////////////////////////2 legged spreads
// given a quoting target qty, finds the "driver" price
// and qty, thats needed to hedge the quote. It also
@@ -4,6 +4,7 @@
#include "lib/orderman/orderman_utils/orderman_common.h"
#include "lib/orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerState.h"
#include "lib/orderman/actors/order_manager/ChildOrder.h"
#include "lib/orderman/orders/spreader_orders/spreader/ISpreaderManager.h"
namespace bts {
namespace trace {struct CorID;}
@@ -22,7 +23,8 @@ public:
virtual const std::string state_text () const = 0;
// called once and only once, before any other calls.
virtual void init (Price price,
Quantity quantity) = 0;
Quantity quantity,
ISpreaderManager::OrderTransfer* order = nullptr) = 0;
// called only when this hedger's order is updated
virtual void on_order_update (const SpreaderChildOrderState& order_update) = 0;
// called only when the security that the hedger is working on
@@ -9,12 +9,21 @@ void HedgerEndStateWorker::on_transition (){
// this is to allow the hedger to be re-used.
// the state is cleared and the hedger returns
// to the start state, waiting for the init call
if(!_hedger->_is_permenantly_cancelled)
if(!_hedger->_is_permenantly_cancelled){
Quantity rem_to_fill = _hedger->_price_quantity_state.remaining_to_fill();
if(rem_to_fill.value() > 0)
_hedger->_spreader.send_hedge_order(
_hedger->_leg_property_data.leg_index(),
_hedger->_child_order_state.out_price(),
rem_to_fill,
false);
_hedger->transform_to_START();
}
}
void HedgerEndStateWorker::init (Price,
Quantity){
Quantity,
ISpreaderManager::OrderTransfer*){
bts_assert_msg (false, "HedgerEndStateWorker::init illegal operation");
}
void HedgerEndStateWorker::on_order_update(const SpreaderChildOrderState&){
@@ -23,7 +23,9 @@ public:
void on_transition () override;
HedgerState state () const override {return HedgerState::END;}
const std::string state_text () const override {return "END";}
void init (Price price,Quantity quantity) override;
void init (Price price,
Quantity quantity,
ISpreaderManager::OrderTransfer* order = nullptr) override;
void on_order_update (const SpreaderChildOrderState& order_update) override;
void on_book (const bts::orderman::Book& book) override;
void cancel() override;
@@ -14,11 +14,31 @@ void HedgerStartStateWorker::on_transition (){
}
void HedgerStartStateWorker::init (Price price,
Quantity quantity){
Quantity quantity,
ISpreaderManager::OrderTransfer* order_ptr){
_hedger->_price_quantity_state.re_init(price,quantity);
if(quantity.value() > 0){
_hedger->_place_order (price, quantity);
_hedger->transform_to_WAITING_FOR_FIRST_ACK ();
if(order_ptr==nullptr){
_hedger->_place_order (price, quantity);
_hedger->transform_to_WAITING_FOR_FIRST_ACK ();
}
else{
SpreaderChildOrderState& q_order = *(order_ptr->q_order);
bts_assert(q_order.working());
//bts_assert(q_order.active_order().is_active());
uint32_t hedge_order_qty = SpreaderUtils::adjust_qty_to_target(
q_order.current_fills().value(),
q_order.out_quantity().value(),
quantity.value(),
true);
ChildOrder& existing_order = q_order.active_order();
_hedger->_child_order_state.re_init(existing_order,
q_order.current_fills());
_hedger->_modify_order (price, Quantity(hedge_order_qty));
_hedger->transform_to_WORKING();
// figure out how many have been filled
// reinit the SCO and modify the price/qty
}
}
}
void HedgerStartStateWorker::on_order_update(const SpreaderChildOrderState&){
@@ -21,7 +21,9 @@ public:
void on_transition () override;
HedgerState state () const override {return HedgerState::START;}
const std::string state_text () const override {return "START";}
void init (Price price,Quantity quantity) override;
void init (Price price,
Quantity quantity,
ISpreaderManager::OrderTransfer* order = nullptr) override;
void on_order_update (const SpreaderChildOrderState& order_update) override;
void on_book (const bts::orderman::Book& book) override;
void cancel() override;
@@ -6,17 +6,20 @@ namespace bts{
namespace orderman{
void HedgerWaitingForCancelAckStateWorker::init (Price,
Quantity){
Quantity,
ISpreaderManager::OrderTransfer*){
bts_assert_msg (false, "HedgerWaitingForCancelAckStateWorker::init "
"illegal operation");
}
void HedgerWaitingForCancelAckStateWorker::on_order_update(const SpreaderChildOrderState& order_update){
void HedgerWaitingForCancelAckStateWorker::on_order_update(
const SpreaderChildOrderState& order_update){
bts_assert (order_update.acknowledged());
_hedger->_price_quantity_state.update_fill (order_update.last_update_filled_quantity());
_hedger->_price_quantity_state.update_fill (
order_update.last_update_filled_quantity());
if (order_update.terminal_status())
_hedger->transform_to_END ();
}
void HedgerWaitingForCancelAckStateWorker::on_book(const bts::orderman::Book&){
void HedgerWaitingForCancelAckStateWorker::on_book(const bts::orderman::Book&){
}
void HedgerWaitingForCancelAckStateWorker::cancel(){
}
@@ -25,7 +25,9 @@ public:
const std::string state_text () const override {
return "WAITING_FOR_CANCEL_ACK";
}
void init (Price price,Quantity quantity) override;
void init (Price price,
Quantity quantity,
ISpreaderManager::OrderTransfer* order = nullptr) override;
void on_order_update (const SpreaderChildOrderState& order_update) override;
void on_book (const bts::orderman::Book& book) override;
void cancel() override;
@@ -8,7 +8,8 @@ namespace orderman{
void HedgerWaitingForFirstAckCancelledStateWorker::init(
Price,
Quantity){
Quantity,
ISpreaderManager::OrderTransfer*){
bts_assert_msg (false, "HedgerWaitingForFirstAckCancelledStateWorker::init "
"illegal operation");
}
@@ -26,8 +27,8 @@ void HedgerWaitingForFirstAckCancelledStateWorker::on_order_update(
_hedger->transform_to_WAITING_FOR_CANCEL_ACK ();
}
}
void HedgerWaitingForFirstAckCancelledStateWorker::on_book(const bts::orderman::Book&){
void HedgerWaitingForFirstAckCancelledStateWorker::on_book(
const bts::orderman::Book&){
}
void HedgerWaitingForFirstAckCancelledStateWorker::cancel(){
}
@@ -25,7 +25,9 @@ public:
const std::string state_text () const override {
return "WAITING_FOR_FIRST_ACK_CANCELLED";
}
void init (Price price,Quantity quantity) override;
void init (Price price,
Quantity quantity,
ISpreaderManager::OrderTransfer* order = nullptr) override;
void on_order_update (const SpreaderChildOrderState& order_update) override;
void on_book (const bts::orderman::Book& book) override;
void cancel() override;
@@ -5,7 +5,8 @@ namespace bts{
namespace orderman{
void HedgerWaitingForFirstAckStateWorker::init (Price,
Quantity){
Quantity,
ISpreaderManager::OrderTransfer*){
bts_assert_msg (false, "HedgerWaitingForFirstAckStateWorker::init "
"illegal operation");
}
@@ -26,7 +26,9 @@ public:
const std::string state_text () const override {
return "WAITING_FOR_FIRST_ACK";
}
void init (Price price,Quantity quantity) override;
void init (Price price,
Quantity quantity,
ISpreaderManager::OrderTransfer* order = nullptr) override;
void on_order_update (const SpreaderChildOrderState& order_update) override;
void on_book (const bts::orderman::Book& book) override;
void cancel() override;
@@ -10,7 +10,8 @@ void HedgerWorkingStateWorker::on_transition(){
_order_touch_time = _hedger->_current_time();
}
void HedgerWorkingStateWorker::init(Price,
Quantity){
Quantity,
ISpreaderManager::OrderTransfer*){
bts_assert_msg (false, "HedgerWorkingStateWorker::init illegal operation");
}
void HedgerWorkingStateWorker::on_order_update(
@@ -42,12 +43,15 @@ void HedgerWorkingStateWorker::terminate(){
}
void HedgerWorkingStateWorker::on_time(const TimeStamp& ts){
double new_price;
const auto& book =
_hedger->_spreader.get_book (_hedger->_leg_property_data.leg_index());
if (SpreaderUtils::post_hedge_time_based_price_action (
_order_touch_time,
ts,
_hedger->_leg_property_data,
_hedger->_spreader.get_book (_hedger->_leg_property_data.leg_index()),
new_price)){
_order_touch_time,
ts,
_hedger->_leg_property_data,
book,
new_price))
{
_hedger->_modify_order (Price(new_price));
_order_touch_time = _hedger->_current_time();
}
@@ -23,7 +23,9 @@ public:
void on_transition () override;
HedgerState state () const override {return HedgerState::WORKING;}
const std::string state_text () const override {return "WORKING";}
void init (Price price,Quantity quantity) override;
void init (Price price,
Quantity quantity,
ISpreaderManager::OrderTransfer* order = nullptr) override;
void on_order_update (const SpreaderChildOrderState& order_update) override;
void on_book (const bts::orderman::Book& book) override;
void cancel() override;
@@ -35,7 +35,10 @@ public:
// time update from the infrastructure
virtual void on_time(const TimeStamp&) = 0;
// on a quoting fill on one of the other legs
virtual void on_other_leg_quoter_fill (size_t leg_id, Quantity fill_quantity) = 0;
virtual void on_other_leg_quoter_fill (size_t leg_id,
Quantity fill_quantity,
Price hedge_price,
Quantity hedge_qty) = 0;
// when a spreader order gets updated, it could be that the one of
// the price or quantity does not change
virtual void update_spreader_order (Price price, Quantity quantity) = 0;
@@ -18,7 +18,8 @@ void QuoterEndStateWorker::on_transition (){
_quoter->irrecoverable_error();
if (!is_final){
// getting new order
_quoter->_spreader.setup_new_quoter_order(_quoter->_this_leg_data.leg_index());
_quoter->_spreader.setup_new_quoter_order(
_quoter->_this_leg_data.leg_index());
_quoter->_transform_to_WAITING_FOR_SIZE ();
}
}
@@ -37,8 +38,10 @@ void QuoterEndStateWorker::terminate()
{}
void QuoterEndStateWorker::on_time(const TimeStamp&)
{}
void QuoterEndStateWorker::on_other_leg_quoter_fill (size_t, Quantity)
{}
void QuoterEndStateWorker::on_other_leg_quoter_fill (size_t,
Quantity,
Price,
Quantity){}
void QuoterEndStateWorker::update_spreader_order (Price, Quantity)
{}
}}
@@ -29,7 +29,10 @@ public:
void cancel() override;
void terminate() override;
void on_time(const TimeStamp& ts) override;
void on_other_leg_quoter_fill (size_t leg_id, Quantity fill_quantity) override;
void on_other_leg_quoter_fill (size_t leg_id,
Quantity fill_quantity,
Price hedge_price,
Quantity hedge_qty) override;
void update_spreader_order (Price price, Quantity quantity) override;
};
}}
@@ -43,8 +43,11 @@ void QuoterStartStateWorker::on_time(const TimeStamp&){
// however for the purpose of this state, we can hide that detail and deal
// with it all !
void QuoterStartStateWorker::on_other_leg_quoter_fill (size_t leg_index,
Quantity filled_quantity){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity);
Quantity filled_quantity,
Price hedge_price,
Quantity hedge_qty){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity,
hedge_price, hedge_qty);
}
// same as above, but we can deal with it like one_time_activate
void QuoterStartStateWorker::update_spreader_order (Price price, Quantity quantity){
@@ -27,7 +27,10 @@ public:
void cancel() override;
void terminate() override;
void on_time(const TimeStamp& ts) override;
void on_other_leg_quoter_fill (size_t leg_id, Quantity fill_quantity) override;
void on_other_leg_quoter_fill (size_t leg_id,
Quantity fill_quantity,
Price hedge_price,
Quantity hedge_qty) override;
void update_spreader_order (Price price, Quantity quantity) override;
};
}}
@@ -10,6 +10,7 @@ enum class QuoterState
WAITING_FOR_IOC,
WAITING_FOR_FIRST_ACK_CANCELLED,
WORKING,
WAITING_FOR_ORDER_TRANSFER,
WAITING_FOR_CANCEL_ACK,
END
};
@@ -30,9 +30,13 @@ void QuoterWaitingForCancelAckStateWorker::terminate(){
void QuoterWaitingForCancelAckStateWorker::on_time(const TimeStamp&){
// TODO check threshold
}
void QuoterWaitingForCancelAckStateWorker::on_other_leg_quoter_fill (size_t leg_index,
Quantity filled_quantity){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity);
void QuoterWaitingForCancelAckStateWorker::on_other_leg_quoter_fill (
size_t leg_index,
Quantity filled_quantity,
Price hedge_price,
Quantity hedge_qty){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity,
hedge_price, hedge_qty);
}
void QuoterWaitingForCancelAckStateWorker::update_spreader_order (Price price,
Quantity quantity){
@@ -28,7 +28,10 @@ public:
void cancel() override;
void terminate() override;
void on_time(const TimeStamp& ts) override;
void on_other_leg_quoter_fill (size_t leg_id, Quantity fill_quantity) override;
void on_other_leg_quoter_fill (size_t leg_id,
Quantity fill_quantity,
Price hedge_price,
Quantity hedge_qty) override;
void update_spreader_order (Price price, Quantity quantity) override;
};
}}
@@ -34,8 +34,13 @@ void QuoterWaitingForFirstAckCancelledWorker::terminate(){
}
void QuoterWaitingForFirstAckCancelledWorker::on_time(const TimeStamp&){
}
void QuoterWaitingForFirstAckCancelledWorker::on_other_leg_quoter_fill (size_t leg_index, Quantity filled_quantity){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity);
void QuoterWaitingForFirstAckCancelledWorker::on_other_leg_quoter_fill (
size_t leg_index,
Quantity filled_quantity,
Price hedge_price,
Quantity hedge_qty){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity,
hedge_price, hedge_qty);
}
void QuoterWaitingForFirstAckCancelledWorker::update_spreader_order (Price price,
Quantity quantity){
@@ -34,7 +34,10 @@ public:
void cancel() override;
void terminate() override;
void on_time(const TimeStamp& ts) override;
void on_other_leg_quoter_fill (size_t leg_id, Quantity fill_quantity) override;
void on_other_leg_quoter_fill (size_t leg_id,
Quantity fill_quantity,
Price hedge_price,
Quantity hedge_qty) override;
void update_spreader_order (Price price, Quantity quantity) override;
};
}}
@@ -34,8 +34,11 @@ void QuoterWaitingForFirstAckWorker::terminate(){
void QuoterWaitingForFirstAckWorker::on_time(const TimeStamp&){
}
void QuoterWaitingForFirstAckWorker::on_other_leg_quoter_fill (size_t leg_index,
Quantity filled_quantity){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity);
Quantity filled_quantity,
Price hedge_price,
Quantity hedge_qty){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity,
hedge_price, hedge_qty);
_analyze_and_act ();
}
void QuoterWaitingForFirstAckWorker::update_spreader_order (Price price,
@@ -32,7 +32,10 @@ public:
void cancel() override;
void terminate() override;
void on_time(const TimeStamp& ts) override;
void on_other_leg_quoter_fill (size_t leg_id, Quantity fill_quantity) override;
void on_other_leg_quoter_fill (size_t leg_id,
Quantity fill_quantity,
Price hedge_price,
Quantity hedge_qty) override;
void update_spreader_order (Price price, Quantity quantity) override;
private:
// checks if the target is reached, and cancels
@@ -34,9 +34,13 @@ void QuoterWaitingForIOCWorker::terminate(){
}
void QuoterWaitingForIOCWorker::on_time(const TimeStamp&){
}
void QuoterWaitingForIOCWorker::on_other_leg_quoter_fill (size_t leg_index,
Quantity filled_quantity){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity);
void QuoterWaitingForIOCWorker::on_other_leg_quoter_fill (
size_t leg_index,
Quantity filled_quantity,
Price hedge_price,
Quantity hedge_qty){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity,
hedge_price, hedge_qty);
}
void QuoterWaitingForIOCWorker::update_spreader_order (Price price,
Quantity quantity){
@@ -35,7 +35,10 @@ public:
void cancel() override;
void terminate() override;
void on_time(const TimeStamp& ts) override;
void on_other_leg_quoter_fill (size_t leg_id, Quantity fill_quantity) override;
void on_other_leg_quoter_fill (size_t leg_id,
Quantity fill_quantity,
Price hedge_price,
Quantity hedge_qty) override;
void update_spreader_order (Price price, Quantity quantity) override;
};
}}
@@ -0,0 +1,60 @@
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.h"
#include "lib/orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForOrderTransferStateWorker.h"
#include "lib/orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterState.h"
#include "lib/orderman/orders/spreader_orders/spreader/SingleLegQuoter.h"
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.h"
namespace bts{
namespace orderman{
QuoterState QuoterWaitingForOrderTransferStateWorker::state () const {
return QuoterState::WAITING_FOR_ORDER_TRANSFER;
}
void QuoterWaitingForOrderTransferStateWorker::one_time_activate (Price,
Quantity){
bts_assert_msg (false,
"QuoterWaitingForOrderTransferStateWorker::one_time_activate "
"is an illegal operation");
}
void QuoterWaitingForOrderTransferStateWorker::on_order_update (
const SpreaderChildOrderState& u){
bts_assert (u.acknowledged());
_analyze_and_act();
}
void QuoterWaitingForOrderTransferStateWorker::on_book (
size_t,
const bts::orderman::Book&){
}
void QuoterWaitingForOrderTransferStateWorker::cancel(){
_quoter->_cancel_order();
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK ();
}
void QuoterWaitingForOrderTransferStateWorker::terminate(){
_quoter->_transform_to_END ();
}
void QuoterWaitingForOrderTransferStateWorker::on_time(const TimeStamp&){
}
void QuoterWaitingForOrderTransferStateWorker::on_other_leg_quoter_fill (
size_t leg_index,
Quantity filled_quantity,
Price hedge_price,
Quantity hedge_qty){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity,
hedge_price, hedge_qty);
_analyze_and_act();
}
void QuoterWaitingForOrderTransferStateWorker::update_spreader_order (
Price price,
Quantity quantity){
_quoter->_price_quantity_state.update_target_price_quantity (price, quantity);
_analyze_and_act();
}
void QuoterWaitingForOrderTransferStateWorker::_analyze_and_act(){
const auto& u = _quoter->_child_order_state;
if(u.terminal_status() ||
_quoter->_price_quantity_state.target_reached()){
_quoter->_transform_to_END ();
return;
}
}
}}
@@ -0,0 +1,43 @@
#pragma once
#include "lib/orderman/orderman_utils/orderman_common.h"
#include "lib/utils/bts_chrono.h"
#include "lib/orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterState.h"
#include "lib/orderman/orders/spreader_orders/spreader/quoter/IQuoterStateWorker.h"
namespace bts {
namespace orderman {
class SpreaderChildOrderState;
class Book;
class SingleLegQuoter;
// Quoter order is in the process of transferring ownership
// to thehedger
// exit:
class QuoterWaitingForOrderTransferStateWorker : public IQuoterStateWorker
{
private:
SingleLegQuoter* const _quoter;
public:
QuoterWaitingForOrderTransferStateWorker (SingleLegQuoter* quoter)
:_quoter(quoter){}
QuoterState state () const override;
const std::string state_text () const override {
return "WAITING_FOR_ORDER_TRANSFER";
}
virtual void on_transition () override {}
void one_time_activate (Price, Quantity) override;
void on_order_update (
const SpreaderChildOrderState& order_update) override;
void on_book (size_t leg_id, const bts::orderman::Book& book) override;
void cancel() override;
void terminate() override;
void on_time(const TimeStamp& ts) override;
void on_other_leg_quoter_fill (size_t leg_id,
Quantity fill_quantity,
Price hedge_price,
Quantity hedge_qty) override;
void update_spreader_order (Price price, Quantity quantity) override;
private:
void _analyze_and_act ();
};
}}
@@ -34,8 +34,11 @@ void QuoterWaitingForSizeStateWorker::on_time(const TimeStamp&){
}
void QuoterWaitingForSizeStateWorker::on_other_leg_quoter_fill (size_t leg_index,
Quantity filled_quantity){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity);
Quantity filled_quantity,
Price hedge_price,
Quantity hedge_qty){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity,
hedge_price, hedge_qty);
_longpath_analyze_and_act ();
}
void QuoterWaitingForSizeStateWorker::update_spreader_order (Price price,
@@ -34,7 +34,10 @@ public:
void cancel() override;
void terminate() override;
void on_time(const TimeStamp& ts) override;
void on_other_leg_quoter_fill (size_t leg_id, Quantity fill_quantity) override;
void on_other_leg_quoter_fill (size_t leg_id,
Quantity fill_quantity,
Price hedge_price,
Quantity hedge_qty) override;
void update_spreader_order (Price price, Quantity quantity) override;
private:
// checks to see if target has reached and goes to end
@@ -5,6 +5,7 @@
#include "lib/orderman/orders/spreader_orders/spreader/ISpreaderManager.h"
#include "lib/orderman/orderman_utils/orderman_common.h"
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderCacheWarmingState.h"
#include "lib/domain_model/Security.h"
namespace bts{
namespace orderman{
@@ -41,12 +42,28 @@ void QuoterWorkingStateWorker::cancel(){
void QuoterWorkingStateWorker::terminate(){
_quoter->_transform_to_END ();
}
void QuoterWorkingStateWorker::on_time(const TimeStamp&){
void QuoterWorkingStateWorker::on_time(const TimeStamp&){
}
void QuoterWorkingStateWorker::on_other_leg_quoter_fill (size_t leg_index,
Quantity filled_quantity){
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity);
_longpath_analyze_and_act ();
void QuoterWorkingStateWorker::on_other_leg_quoter_fill (
size_t leg_index,
Quantity filled_quantity,
Price hedge_price,
Quantity hedge_qty){
bool q_to_h = hedge_qty.value() > 0 &&
_use_quoting_order_to_hedge(hedge_price,hedge_qty);
// decide how to send hedge
_quoter->_incorporate_other_leg_fill (leg_index,
filled_quantity,
hedge_price,
hedge_qty,
true,
q_to_h);
if(q_to_h){
_quoter->_child_order_state.re_init();
_quoter->_transform_to_END();
}
else
_longpath_analyze_and_act ();
}
void QuoterWorkingStateWorker::update_spreader_order (Price price,
Quantity quantity){
@@ -99,4 +116,51 @@ void QuoterWorkingStateWorker::_modify_order (Price price, Quantity quantity){
_quoter->_modify_order(price, quantity);
}
}
bool QuoterWorkingStateWorker::_use_quoting_order_to_hedge(Price h_price,
Quantity h_qty) const{
const LegPropertyData& leg = _quoter->_this_leg_data;
const SpreaderChildOrderState& q_ord = _quoter->_child_order_state;
// check to see if the order is in transition ?
auto q_for_h = leg.use_quote_for_hedging();
bool q_better = securities::same_or_better_order_price(
_quoter->_this_leg_data.trading_side(),
q_ord.last_reported_order_price(),
h_price) &&
// this is to make sure that the hedge price
// is also worse than anything in flight
securities::same_or_better_order_price(
_quoter->_this_leg_data.trading_side(),
q_ord.out_price(),
h_price);
bool rv;
switch(q_for_h){
case spark::UseSpreaderQuoteForHedging::NEVER:
rv = false;
break;
case spark::UseSpreaderQuoteForHedging::WHEN_CANT_OVERHEDGE:
rv = q_better &&
// max fill potential <= hedge qty
h_qty.value() >= SpreaderUtils::subtract_quanitities(
q_ord.out_quantity().value(),
q_ord.current_fills().value()) &&
h_qty.value() >= SpreaderUtils::subtract_quanitities(
q_ord.last_reported_order_quantity().value(),
q_ord.current_fills().value());
break;
case spark::UseSpreaderQuoteForHedging::ALWAYS:
rv = q_better;
break;
default:
bts_assert(false);
rv = false;
break;
}
LOG(OrderMan, Info, "QuoterWorkingStateWorker::_use_quoting_order_to_hedge "
"res: leg:{} hp:{} hq:{}",
rv,
leg.leg_index(),
h_price,
h_qty);
return rv;
}
}}
@@ -27,7 +27,10 @@ public:
void cancel() override;
void terminate() override;
void on_time(const TimeStamp& ts) override;
void on_other_leg_quoter_fill (size_t leg_id, Quantity fill_quantity) override;
void on_other_leg_quoter_fill (size_t leg_id,
Quantity fill_quantity,
Price hedge_price,
Quantity hedge_qty) override;
void update_spreader_order (Price price, Quantity quantity) override;
private:
// this does the following in this order
@@ -36,5 +39,7 @@ private:
// iii. if reprice (ie qty changed or price changed beyond the threshold) => requote
void _longpath_analyze_and_act ();
void _modify_order (Price price, Quantity quantity);
bool _use_quoting_order_to_hedge(Price h_price,
Quantity h_qty) const;
};
}}
Loaded 100 of 139 files, more files were not shown because too many files have changed in this diff. Show more