Compare commits

..
9 Commits
11 changed files with 121 additions and 123 deletions

No files matched your search

@@ -154,7 +154,7 @@ insert_anchor_links = "right"
- Pay Less - If enabled by checking the checkbox, the spreader will
attempt to pay less when the quantity at the level of the calculated
hedge price is more than the threshold defined.  The hedge order is
hedge price is less than the threshold defined.  The hedge order is
paid less by the “Payless Ticks” as defined per leg.
- Pay Up - If enabled by checking the checkbox, the spreader will pay
up when the quantity at the level of the calculated hedge price is
@@ -227,7 +227,7 @@ namespace mbts.ui.spark {
}
DataGridColumn _column_factory(LegSpreaderParamsTuple l) {
var col = new DataGridColumnInternal(l.leg.Security, ParameterCellTemplateConverter, ParameterCellEditingTemplateConverter) { Width = 75, };
var col = new DataGridColumnInternal(l.leg.Security, ParameterCellTemplateConverter, ParameterCellEditingTemplateConverter);
col.HeaderTemplate = (DataTemplate)FindResource(IsNew ? RemovableColumnHeaderTemplateKey : NonRemovableColumnHeaderTemplateKey);
DataGridEx.SetRightBorder(col, new DataGridExVerticalLine(false, true, Colors.DarkGray, 1));
return col;
@@ -501,6 +501,12 @@ namespace bts.shell.pnl {
account_name == other.account_name &&
sod == other.sod &&
day == other.day &&
bid_price.Equals(other.bid_price) &&
ask_price.Equals(other.ask_price) &&
last_price.Equals(other.last_price) &&
mid_price.Equals(other.mid_price) &&
settlement_price.Equals(other.settlement_price) &&
calc_type.Equals(other.calc_type) &&
raw_day == other.raw_day &&
working.summary == other.working.summary;
@@ -97,22 +97,22 @@ namespace bts.shell.pnl {
if (security.HasValue && security.Value.ContractCase != Security.ContractOneofCase.Future) {
day_long = day_short = sod_long = sod_short = 0;
} else {
day_long = (decimal)DoubleUtil.nan_to_zero(data.day.long_pos);
day_short = (decimal)DoubleUtil.nan_to_zero(data.day.short_pos);
sod_long = (decimal)DoubleUtil.nan_to_zero(data.sod.long_pos);
sod_short = (decimal)DoubleUtil.nan_to_zero(data.sod.short_pos);
day_long = DoubleUtil.round_to_decimal(data.day.long_pos);
day_short = DoubleUtil.round_to_decimal(data.day.short_pos);
sod_long = DoubleUtil.round_to_decimal(data.sod.long_pos);
sod_short = DoubleUtil.round_to_decimal(data.sod.short_pos);
}
var nd = new PNLNormalizedData(
(decimal)DoubleUtil.nan_to_zero(day_pnl.value),
DoubleUtil.round_to_decimal(day_pnl.value),
day_long,
day_short,
(decimal)DoubleUtil.nan_to_zero(data.raw_day.long_pos),
(decimal)DoubleUtil.nan_to_zero(data.raw_day.short_pos),
(decimal)DoubleUtil.nan_to_zero(sod_pnl.value),
DoubleUtil.round_to_decimal(data.raw_day.long_pos),
DoubleUtil.round_to_decimal(data.raw_day.short_pos),
DoubleUtil.round_to_decimal(sod_pnl.value),
sod_long,
sod_short,
(decimal)DoubleUtil.nan_to_zero(data.working_long_pos),
(decimal)DoubleUtil.nan_to_zero(data.working_short_pos));
DoubleUtil.round_to_decimal(data.working_long_pos),
DoubleUtil.round_to_decimal(data.working_short_pos));
if (_normalized_data != nd) {
_normalized_data = nd;
updated?.Invoke(nd);
@@ -103,7 +103,7 @@ namespace bts.shell.pnl {
load_from(settings);
_dispose = Disposable.Create(
pnl_source.Operate(
_calculation_type.observe_current(),
_calculation_type.observe_current(true),
(data, calc) => data.with(calc_type: calc)
).FilterWithRaw(filter_src, PNLRowData.key_fn, null)
.OnDispatcher()
-2
View File
@@ -75,7 +75,6 @@ namespace mbts.spark {
.TableCheckedAutoCorrect(EqualityComparer<(SecurityImmutable? sec, PNLUnitImmutable data)>.Default)
.Where(t => t.has_changes())
.Cache();
on_account_pnl = _position_service.subscribei_pnl_account_data().Naggle(interval, scheduler).Table().Cache();
var working_orders = on_orders.Filter(tup => tup.order.is_active());
this.working_orders =
on_orders.Scan(
@@ -265,7 +264,6 @@ namespace mbts.spark {
public IObservable<IReadOnlyDictionary<uint, OrderSecurity>> working_orders { get; }
public IObservable<TableUpdate<(SecurityImmutable?, PNLUnitImmutable), int>> on_pnl { get; }
public IObservable<TableUpdate<PNLRowData, PNLKey>> security_account_pnl { get; }
public IObservable<TableUpdate<AccountPNLImmutable, uint>> on_account_pnl { get; }
public IObservable<TableUpdate<(SecurityImmutable?, PositionUnitImmutable), int>> on_positions { get; }
public IObservable<TableUpdate<(AlgoData algo, AlgoDefinitionMetadata? meta), AlgoKey>> studio_algos_with_meta { get; }
public IObservable<TableUpdate<(SecurityImmutable?, ManualFillImmutable), int>> on_manual_fills_securities { get; }
@@ -1,10 +1,9 @@
using System;
using System.Linq;
namespace mbts.ui.controls
{
internal class DoubleUtil
{
namespace mbts.ui.controls {
static class DoubleUtil {
public const int API_DECIMAL_PRECISION = 9;
/* smallest such that 1.0+DBL_EPSILON != 1.0 */
private const double EPSILON = 2.2204460492503131e-016;
private const double BIG_EPSILON = EPSILON * 10;
@@ -36,6 +35,9 @@ namespace mbts.ui.controls
(double.IsNaN(right) ? double.NaN : -right) :
(double.IsNaN(right) ? left : left - right);
public static decimal round_to_decimal(double value, int decimals = API_DECIMAL_PRECISION) =>
double.IsNaN(value) ? 0 : (decimal)Math.Round(value, decimals, MidpointRounding.AwayFromZero);
internal static bool AreClose(double v1, double v2) {
if (v1 == v2) return true;
double delta = Math.Abs(v1 - v2);
+54 -45
View File
@@ -8,7 +8,6 @@ using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
namespace bts.api.core {
@@ -94,38 +93,38 @@ namespace bts.api.core {
new Update<T, TKey>(new T[0], new T[0], new Change<T>[0], new T[0], key_extractor);
public Update<T,TKey> merge(Update<T, TKey> next) {
var comp = new RowEqualityComparer<T, TKey>(_key);
var added = this.added as HashSet<T> ?? new HashSet<T>(this.added, comp);
var added = this.added as KeyedValueSet<TKey, T> ?? new KeyedValueSet<TKey, T>(this.added, _key);
var changes = this.changed as ChangeDict<T,TKey> ?? new ChangeDict<T,TKey>(this.changes, _key);
var removed = this.removed as HashSet<T> ?? new HashSet<T>(this.removed, comp);
var removed = this.removed as KeyedValueSet<TKey, T> ?? new KeyedValueSet<TKey, T>(this.removed, _key);
// Add
added.UnionWith(next.added);
foreach (var v in next.added) {
var k = _key(v);
if (removed.TryPop(k, out var oldval)) {
changes.AddOrMerge(new Change<T>(oldval, v));
} else {
added[k] = v;
}
}
// Change
foreach (var c in next.changes) {
if (added.Contains(c.Old)) {
added.Remove(c.Old);
added.Add(c.New);
}
else {
var k = _key(c.Old);
if (!added.TryReplace(k, c.New))
changes.AddOrMerge(c);
}
}
// Remove
foreach (var r in next.removed) {
if (!added.Remove(r)) {
removed.Add(r);
}
changes.Remove(_key(r));
var k = _key(r);
if (!added.Remove(k))
removed[k] = changes.TryRemove(k, out var ch) ? ch.Old : r;
}
return new Update<T, TKey>(
next.all,
added, changes, removed,
_key
);
_key);
}
public IEnumerable<T> all { get; }
@@ -148,6 +147,39 @@ namespace bts.api.core {
#endif
}
class KeyedValueSet<TKey, TValue> : IEnumerable<TValue> {
readonly Dictionary<TKey, TValue> _cache = new Dictionary<TKey, TValue>();
public KeyedValueSet(IEnumerable<TValue> value, Func<TValue, TKey> key) {
foreach (var v in value)
_cache[key(v)] = v;
}
public TValue this[TKey key] {
set => _cache[key] = value;
}
public bool Remove(TKey key) =>
_cache.Remove(key);
public bool TryPop(TKey key, out TValue value) =>
_cache.TryGetValue(key, out value) && _cache.Remove(key);
public bool TryReplace(TKey key, TValue value) {
if (_cache.ContainsKey(key)) {
_cache[key] = value;
return true;
}
return false;
}
public IEnumerator<TValue> GetEnumerator() =>
_cache.Values.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() =>
GetEnumerator();
}
class ChangeDict<T, TKey> : IEnumerable<Change<T>> {
Dictionary<TKey, Change<T>> _changes;
Func<Change<T>, TKey> _key;
@@ -167,9 +199,11 @@ namespace bts.api.core {
return null;
}
public void Remove(TKey key) {
public bool Remove(TKey key) =>
_changes.Remove(key);
}
public bool TryRemove(TKey key, out Change<T> result) =>
_changes.TryGetValue(key, out result) && _changes.Remove(key);
#region IEnumerable
public IEnumerator<Change<T>> GetEnumerator() {
@@ -181,31 +215,6 @@ namespace bts.api.core {
#endregion
}
struct RowEqualityComparer<T,TKey> : IEqualityComparer<T>, IEqualityComparer<Change<T>>
where TKey : IEquatable<TKey> {
readonly Func<T,TKey> _key;
public RowEqualityComparer(Func<T,TKey> key) {
_key = key;
}
public bool Equals(T x, T y) {
return _key(x).Equals(_key(y));
}
public bool Equals(Change<T> x, Change<T> y) {
return Equals(x.New, y.New);
}
public int GetHashCode(T obj) {
return _key(obj).GetHashCode();
}
public int GetHashCode(Change<T> c) {
return GetHashCode(c.New);
}
}
public class TableUpdate<T, TKey> where TKey : IEquatable<TKey> {
// warning: this does not have a key_extractor
public static readonly TableUpdate<T, TKey> empty = new TableUpdate<T, TKey>(ImmutableDictionary<TKey, T>.Empty, Array.Empty<T>(), Array.Empty<Change<T>>(), Array.Empty<T>(), null);
@@ -922,4 +931,4 @@ namespace bts.api.core {
$"T is '{typeof(T)}', TKey is '{typeof(TKey)}'";
}
}
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ Prerequisites
User settings
-------------
3. Navigate to http://sparkvm:8000 (or wherever your sparkd resides), Users tab
4. Between bts and bts_2 users, verify that have distinct operator ids (Order Routing tab)
4. Between bts and bts_2 users, verify they have distinct operator ids (Order Routing tab)
5. In another ssh session on your server, let's tail the sim fix log for orders
tail -f ~/sparkdata/data/jetfix/sim/current/fix | grep --line-buffered 35=D | tr '\001' '|'
6. Open up a client, login as bts, pick your favorite symbol and submit an order
@@ -1,4 +1,4 @@
Test Author: Pedro
Test Author: Pedro
If it breaks: Pedro
Spreader Requote Performance test
@@ -30,13 +30,13 @@ OrdermanCfg {
value {
executor {
thread_name: "oman_orders"
poll: true
poll: true
hosted_actor: "MDSource"
hosted_actor: "OrderManager"
}
executor {
thread_name: "oman_slow"
poll: false
poll: false
hosted_actor: "*"
}
}
@@ -54,7 +54,7 @@ Threads {
5) Now you are ready to start testing. Start a shell and create a new
synthetic say with 2 CL futures. Use the near month (fast ticking)
future as the non quoting leg, so that the other leg gets quoted
often. Make sure to disable throtling in the synthetic definition
often. Make sure to disable throttling in the synthetic definition
dialog.
6) Place an order for this synthetic, away from the market.
+37 -54
View File
@@ -1,50 +1,33 @@
User Settings Test (15 min)
User Settings Test
(there is a REFERENCE section at the bottom, please consult it before getting frustrated, if things are still unclear, ask John.)
NOTES:
- in addition to the notes below, there is a "Reference" section at the bottom of the test,
feel free to add things to it if you run into problems; impart your wisdom unto the next tester.
- the settings button is located in the bottom-left corner of the Ladder
- the "Default" tab will be referred to as [DTab], "Custom" as [CTab]
- the "Use Defaults" checkbox is located at the top of the dialog
- when "Use Defaults" is checked, [CTab] is disabled ([DTab], however, is always enabled)
- to Import/Export settings to files, click the hamburger icon in the upper-right corner of the settings dialog.
- you cannot open multiple settings dialog for the same Ladder
i) if a settings dialog is already open, clicking the settings button in the Ladder again closes said dialog, then opens a new one
- the settings dialogs do not live update
i) this only pertains to [DTab], as Custom settings are not shared.
- commit changes by clicking "Apply" or "OK"
i) the only difference between the 2 buttons is that "OK" also closes the dialog
- when you commit changes:
i) even if "Use Defaults" is NOT checked, the settings in [DTab] will be compared with the current defaults,
if they are different, the default changes will be committed as well.
ii) be advised of the following scenario:
You have 2 settings dialogs open (call them [A] and [B]), and commit changes to the defaults in [A].
As the dialogs do NOT live update, [B] will have stale defaults.
When you click commit in [B] (even if you have not actually changed anything in [DTab])
the stale defaults in [B] will be committed, effectively overwritting the changes to the defaults you just committed from [A].
- the "sample" areas should always reflect the properties in your editor, if this is unclear, see the reference section at the bottom for a more detailed explanation.
- when the test directs you to "Visually Confirm blah...," just give it a quick glance, if something isn't matching it should be obvious.
- when the test directs you to repeat a step for each property, here is the list (in case it isn't clear in the dialog):
Note: the Sample column is purely output, don't bother clicking it
- Order Badge Style
- Alternate Order Quantity
- Size Presets (aka Number Pad buttons)
- Fonts and Colors section:
for each column (Orders, Bid, Price, Ask, Last)
- when the test directs you to repeat a step for each property, here is the list:
- Ladder Columns tab ->
- Order Badge Style
- for each column (Orders, Bid, Price, Ask, Last)
i) background
ii) foreground
iii) font (family, size, and weight)
- Market Break Lines section:
i) for each "price-line" (session high, ask, mid, bid, and session low)
- Order Quantities tab ->
- 'Single Click' Quantity
- Number Pad Quantities
- Market Break Lines tab:
i) for each "price-line" (session high, ask, mid, bid, and session low)
a) toggle show/hide
b) color
ii) for session range (this is not actually a line, but the color between the session low/high
a) toggle show/hide
b) color
- when the test advises you to name files (screenshots, or ladder settings files), it is because they will be referenced later by that name.
- if you uncheck all 3 market break lines, the ladder resolves to show the bid line by design.
- just to reiterate: there is a REFERENCE section at the bottom, please consult it before getting frustrated, if things are still unclear, ask John.
- if you uncheck all market break lines, the ladder resolves to show the bid line by design.
------------TEST STEPS------------------
@@ -52,61 +35,61 @@ NOTES:
- the security needs a few working orders on both sides, and a gap of 5-8 ticks between the top bid/ask.
The gap is needed to separate the market break lines (Bid, Ask, and Mid).
- from hence forth, the 2 ladders will be referred to as "[A]" and "[B]" and their settings dialogs as "dialog[A]" and "dialog[B]"
- at the risk of sounding redundant, the "Default" tab will be referred to as [DTab], the "Custom" as [CTab]
2) Open the settings dialogs for [A] and [B]
3) Make sure that both [A] and [B] are using default settings, then close [B]dialog
4) In dialog[A] (with [DTab] selected, [CTab] should be disabled anyways), change each property, then click "Apply"
4) In dialog[A] change each property, then click "Apply"
5) Visually confirm that all the changes have been applied to both ladders
- the row height should adjust to fit the largest font size,
- the scroll position should be maintained, assuming the AutoRecenterTimer didn't move it.
6) Take a screenshot, name it "A-1-confirmation.png"
7) In dialog[A], export the default settings to a file, name it "A-1.ladder" (instructions on how to import/export are in the NOTES section)
7) In dialog[A], export the settings to a file, name it "A-1.ladder" (from the irregular hamburger menu)
8) In dialog[A], click "Restore to Factory," then click "Apply"
8) In dialog[A], click "Load Factory Defaults" in the irregular hamburger menu then click "Apply"
9) Visually confirm that dialog[A], and both ladders, each changed appearance, and match one another.
10) In dialog[A], uncheck "Use Defaults", then select [CTab]
11) Import "A-1.ladder" to Custom, then click Apply
10) In dialog[A] Import "A-1.ladder", then click Apply
12) Visually confirm that:
- dialog[A] and [A] changed appearance, and look just like they did in "A-1-confirmation.png"
- [B] did not change appearance
13) Click the settings button in [A] and [B] to get 2 fresh dialogs (dialog[A] should close and reopen)
- in dialog[A], "Use Default" should be false, and [CTab] selected
- in dialog[B], "Use Default" should be true, and [DTab] selected ([CTab] should be disabled)
14) Take a screenshot, then save the workspace, then restore it
- visually confirm that [A] and [B] look as they did in the screenshot
- repeat step 13
15) In dialog[A], with [CTab] selected, click "Copy from Default"
- [CTab] should now have the same settings as [DTab]
15) In dialog[A] hit the plus stack icon to add a new Profile, give it a unique and memorable name
16) Click the settings button in [A] to close and reopen dialog[A]
16) In Dialog [B] select the profile you just created, if you remember the name
17) In dialog[A] select [DTab], then click "Copy from Custom"
- [DTab] should now have the same settings as [CTab]
17) Click Apply and verify [B] changes to match [A]
18) Click the smaller than average pencil button in dialog[B] change the name of your profile and hit enter. Verify the name changed in dialog[A]
19) Change any one setting of your choice in either dialog. Click the 3.5 inch floppy disk icon and wait for the light to go off before ejecting the disk. Verify both dialogs have the setting you changed.
2001) Change any one setting of your choice in either dialog; click apply in the same dialog and verify both ladders and both dialogs reflect the changed setting.
2002) Revert to factory defaults and create a new profile named "Unsafety Checks"
2003) On the Safety Checks tab uncheck Warn on Market Cross
2004) Click the security selection icon (with the hand), double click every entry in the Exchange column, and click OK. Save or Apply.
2005) Open a new ladder for any symbol and verify you can cross your own orders without being pestered by a confirmation dialog
DONE!!!
Reference-----------------------------------------------------------
Alternate Order Quantity:
- you may send an order with this size via a RIGHT CLICK on a price cell
Size Presets:
- aka the number-pad buttons
- click the expander-arrow button next to the "Size Presets" label to modify them
- you control the quantities in the buttons, and the order in which they appear
Market Break Lines (Bid, Ask, Mid, and Session Low/High/Range):
- each row corresponds to one item, and represents a "horizontal price-line" that will be displayed in the ladder (if show is checked, of course)