Merge branch 'DJ_ICE_pnl_symbol' into DJ_ICE_cpp_mult
This commit is contained in:
commit
daaa7311a0
6 files changed
+62
-3
No files matched your search
@@ -335,6 +335,8 @@ namespace bts.shell.pnl {
|
||||
AskLTESettle = Ask | Settle | 1 << 7
|
||||
}
|
||||
|
||||
public string symbol => security?.pnl_symbol() ?? string.Empty;
|
||||
|
||||
/// Market/Calc
|
||||
public double mid_price => (bid_price + ask_price) / 2;
|
||||
public double pnl_price {
|
||||
@@ -591,6 +593,11 @@ namespace bts.shell.pnl {
|
||||
}
|
||||
|
||||
static class PNLDataExtensions {
|
||||
public static string pnl_symbol(this SecurityImmutable security) {
|
||||
// TODO: actual impl
|
||||
return security.Symbol;
|
||||
}
|
||||
|
||||
// Note: PNLRowData is passed by ref because it is fairly large struct, and since it is a readonly struct, we know it cannot be modified (so might as well avoid excessive copying).
|
||||
public static PNLRowData with(this PNLRowData pnl_data, SecurityImmutable? security = null, string account_name = null, WorkingOrderData? working = null, PNLCalculationType? calc_type = null) =>
|
||||
new PNLRowData(
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace bts.shell.pnl {
|
||||
account_name_cell = _cell_map.add(ColumnKeys.Account, d => d.account_name);
|
||||
security_type_cell = _cell_map.add(ColumnKeys.SecurityType, d => d.security?.ContractCase ?? Security.ContractOneofCase.None);
|
||||
exchange_cell = _cell_map.add(ColumnKeys.Exchange, d => d.security?.Exchange ?? Venue.Unset);
|
||||
symbol_cell = _cell_map.add(ColumnKeys.Symbol, d => d.security?.Symbol ?? string.Empty);
|
||||
symbol_cell = _cell_map.add(ColumnKeys.Symbol, d => d.symbol);
|
||||
security_cell = _cell_map.add(ColumnKeys.Security, d => (d.security), null, EqualityComparer<SecurityImmutable?>.Default, Comparer<SecurityImmutable>.Default.to_nullable());
|
||||
security_key = _cell_map.add(ColumnKeys.SecurityKey, d => d.key.security_id);
|
||||
cpp = _cell_map.add(ColumnKeys.CPP, d => d.cpp);
|
||||
|
||||
@@ -88,6 +88,11 @@ namespace bts.shell.pnl {
|
||||
});
|
||||
// filters
|
||||
account_filter = DiscreteValuesFilterVM.Common.account<PNLRowData>(orders_model, r => new AccountTuple(r.key.account_id, r.account_name), nameof(PNLRowVM.account_name));
|
||||
symbol_filter = DiscreteValuesFilterVM.Create<PNLRowData, string, string[]>(
|
||||
_symbols_source(pnl_source),
|
||||
r => r.symbol,
|
||||
selection => selection.ToArray(),
|
||||
selection => Observable.Return(selection));
|
||||
_refresh_filter = new DeferrableActionWrapper(() => _filter_changed?.Invoke(get_filters_states().build_predicate()));
|
||||
var filter_src = Observable.Create<Func<PNLRowData, bool>>(o => {
|
||||
o.OnNext(get_filters_states().build_predicate());
|
||||
@@ -111,6 +116,7 @@ namespace bts.shell.pnl {
|
||||
Disposable.Create(() => {
|
||||
foreach (var f in _all_filters)
|
||||
f.filter_changed -= _refresh_filter.execute;
|
||||
_all_filters.OfType<IDisposable>().DisposeAll();
|
||||
rows.DisposeAll();
|
||||
_rows_view.Groups.OfTypeSafe<IDisposable>().DisposeAll();
|
||||
}));
|
||||
@@ -187,7 +193,7 @@ namespace bts.shell.pnl {
|
||||
/// security
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, uint[]> account_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, Venue[]> exchange_filter { get; } = DiscreteValuesFilterVM.Common.exchange<PNLRowData>(r => r.security.exchange_or_default(), nameof(PNLRowVM.exchange));
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, string[]> symbol_filter { get; } = DiscreteValuesFilterVM.Common.symbol<PNLRowData>(r => r.security.symbol_or_default(), nameof(PNLRowVM.symbol));
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, string[]> symbol_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, string> security_filter { get; } = new RegexFilterVM<PNLRowData>(r => r.security?.ToString(), nameof(PNLRowData.security));
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, string> security_key_filter { get; } = new RegexFilterVM<PNLRowData>(r => r.key.security_id.ToString());
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, SecurityType[]> security_type_filter { get; } = DiscreteValuesFilterVM.Create<PNLRowData, SecurityType>(
|
||||
@@ -542,6 +548,17 @@ namespace bts.shell.pnl {
|
||||
yield return col_hash.Contains(c.id) ? c.with(is_visible: false) : c;
|
||||
}
|
||||
|
||||
// combines the known system symbols
|
||||
static IObservable<(IEnumerable<string> added, IEnumerable<string> removed)> _symbols_source(IObservable<TableUpdate<PNLRowData, PNLKey>> pnl_source) =>
|
||||
pnl_source
|
||||
// ensure this fires once immediatey, because the known symbols are appended to the first update
|
||||
// (observers shouldn't have to wait for the pnl source to tick to see them).
|
||||
.StartWith(TableUpdate<PNLRowData, PNLKey>.mk_empty(PNLRowData.key_fn))
|
||||
.distinct_on(PNLRowData.key_fn, r => r.symbol, s => s)
|
||||
.Filter(sym => !string.IsNullOrEmpty(sym))
|
||||
.AppendTable(mbts.co2.UserSymbol.get_all().Select(u => u.symbol).Distinct().ToList())
|
||||
.Select(t => (t.added, t.removed));
|
||||
|
||||
#region Fills Popup Utils
|
||||
static void _append_key_filters(fills.FillsFilterStates f, ColumnKeys key) {
|
||||
switch (key) {
|
||||
|
||||
@@ -111,7 +111,9 @@ namespace mbts.spark {
|
||||
raw_mid = (bid + ask) / 2.0;
|
||||
}
|
||||
double tick_size = spec.ticksize(raw_mid);
|
||||
return raw_mid - (raw_mid % tick_size);
|
||||
return raw_mid < 0 ?
|
||||
raw_mid + (raw_mid % tick_size) :
|
||||
raw_mid - (raw_mid % tick_size);
|
||||
}
|
||||
|
||||
public static TickFactors deduce_ticks(IEnumerable<ContractSpecification> contract_specs) {
|
||||
|
||||
@@ -11,6 +11,35 @@ using System.Reactive.Linq;
|
||||
|
||||
namespace bts.utils {
|
||||
public static class UpdateExtensions {
|
||||
public static IObservable<TableUpdate<T, TKey>> AppendTable<T, TKey>(this IObservable<TableUpdate<T, TKey>> source, IEnumerable<T> append_items) where TKey : IEquatable<TKey> {
|
||||
HashSet<TKey> append_keys = null;
|
||||
Func<T, bool> append_key_filter = null;
|
||||
return Observable.Create<TableUpdate<T, TKey>>(o => {
|
||||
TableUpdate<T, TKey> output = null;
|
||||
return source.Subscribe(table => {
|
||||
if (output == null) {
|
||||
// first update - initialize output, and (maybe) append_keys/append_key_filter
|
||||
// Note: append_keys/filter can be shared among all subscriptions because, and only needs to be initialized once;
|
||||
// once initialized, the append_keys/filter will not change.
|
||||
output = table;
|
||||
if (append_keys == null) {
|
||||
append_keys = new HashSet<TKey>(append_items.Select(table.key_extractor));
|
||||
append_key_filter = v => !append_keys.Contains(table.key_extractor(v));
|
||||
}
|
||||
// filter append_items out of the normal source (ensures that they will be immune to removes/changes).
|
||||
output = TableUpdate<T, TKey>.FilterHelper.on_predicate_changed(output, table.state, null, append_key_filter);
|
||||
// add the append_items to the output table (only need to do this once)
|
||||
output = TableUpdate<T, TKey>.update(output, append_items, Enumerable.Empty<Change<T>>(), Enumerable.Empty<T>(), table.key_extractor);
|
||||
output = output.as_snapshot();
|
||||
} else {
|
||||
output = TableUpdate<T, TKey>.FilterHelper.on_source_changed(
|
||||
output, table.added, table.changes, table.removed, append_key_filter);
|
||||
}
|
||||
o.OnNext(output);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static TableUpdate<T, TKey> with_added<T, TKey>(this TableUpdate<T, TKey> table, IEnumerable<T> added) where TKey : IEquatable<TKey> =>
|
||||
TableUpdate<T, TKey>.update(table, added, Enumerable.Empty<Change<T>>(), Enumerable.Empty<T>(), table.key_extractor);
|
||||
|
||||
|
||||
@@ -187,7 +187,11 @@ void ICEListener::onMarketStatistics(const onixs_ice::MarketStatistics& msg, con
|
||||
if (data != nullptr)
|
||||
{
|
||||
bts_assert(data->id == msg.marketId);
|
||||
auto ts = utils::TimeStamp::now();
|
||||
auto deal_denominator = data->handle.security().ice_deal_denominator;
|
||||
data->handle.set_total_volume(msg.volume);
|
||||
data->handle.update_session_high( ts, double_of_price(msg.high, deal_denominator) );
|
||||
data->handle.update_session_low( ts, double_of_price(msg.low, deal_denominator) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user