Merge branch 'DJ_ICE' into DJ_ICE_cpp_mult

This commit is contained in:
Taha Afzal committed 2020-06-15 09:53:32 -04:00
commit f381d536d6
17 files changed
+213 -46

No files matched your search

@@ -100,6 +100,7 @@ namespace bts.shell {
ShellWindowVM shell_window_vm = null;
IShellWindow shell_window = null;
var title_source = new LazyObservable<string>(() => ShellWindowExtensions.literal_title_source(shell_window, shell_window_vm));
LadderVM vm = null;
var view = new Lazy<UIElement>(() => {
// resources
var model = new LadderModel(md, _orders_model, _mbo);
@@ -113,7 +114,6 @@ namespace bts.shell {
/// In response to that event, 'needs_resync' is set to true. This causes 'last_value' to be refreshed when the next caller requests the latest settings
/// (i.e., an IObserver subscribing to the settings_source, or the settings-dialog viewmodel).
bool initialized = false, needs_resync = false;
LadderVM vm = null;
var settings_subject = new Subject<LadderSettings>();
var settings_source = Observable.Create<LadderSettings>(o => {
ensure_synced();
@@ -272,10 +272,11 @@ namespace bts.shell {
(v, s) => save(_get_state(((LadderView)v).vm, settings_id), s),
icon: Icons.Ladder,
thread_id: _thread_id_provider.next_id(),
vm => {
shell_window_vm = vm;
swvm => {
shell_window_vm = swvm;
title_source.connect();
});
},
key_event_args => vm?.key_down(key_event_args));
}
async void _show_windows(IImmutableSet<uint> securities) {
@@ -260,7 +260,11 @@ namespace mbts.spark {
public IBus bus => _bus;
public event Action on_tick, request_settings_dialog, settings_invalidated;
public event Action
on_tick,
request_settings_dialog,
request_recenter,
settings_invalidated;
public MDConsumerHandle md => _model.md;
// we return only entries who have piqs and whose piqs are not uint.Max
@@ -448,15 +452,27 @@ namespace mbts.spark {
public void key_down(KeyEventArgs e) {
if (order_properties_vm == null)
return;
if (KeyboardExtensions.IsDown(Key.Space)) {
_bus?.post(SparkTags.RequestRecenterLadder, null);
}
// the ctrl modifier requirement helps avoid keyboard-input collisions w/ algo-templates popup
if (!KeyboardExtensions.IsCtrlDown()) return;
var new_algo = order_properties_vm.algo_definitions.FirstOrDefault(o => o.algo_root.key_match(e));
if (new_algo != null) {
order_properties_vm.selected_algo_definition = new_algo;
e.Handled = true;
switch (e.Key) {
case Key.Space:
if (KeyboardExtensions.IsShiftDown()) {
// only recenter this ladder
request_recenter?.Invoke();
} else {
// recenter all ladders
_bus?.post(SparkTags.RequestRecenterLadder, null);
}
e.Handled = true;
break;
default:
// the ctrl modifier requirement helps avoid keyboard-input collisions w/ algo-templates popup
if (KeyboardExtensions.IsCtrlDown()) {
var new_algo = order_properties_vm.algo_definitions.FirstOrDefault(o => o.algo_root.key_match(e));
if (new_algo != null) {
order_properties_vm.selected_algo_definition = new_algo;
e.Handled = true;
}
}
break;
}
}
@@ -534,7 +550,7 @@ namespace mbts.spark {
if (ticks_from_settle.HasValue) {
var max_cross = (current_settings?.ladder_order_limits?.max_settlement_cross_ticks)?.as_nullable();
if (max_cross.HasValue) {
if (side == Side.Sell ? ticks_from_settle < max_cross.Value : ticks_from_settle > max_cross.Value)
if (side == Side.Sell ? ticks_from_settle < (-1 * max_cross.Value) : ticks_from_settle > max_cross.Value)
msg = $"exceeds settle cross ticks limit ({ticks_from_settle.Value})";
}
}
@@ -53,7 +53,7 @@ namespace mbts.spark {
readonly RefValueContainer<IEnumerable<VolumeAtPriceLevelImmutable>> _volume_container =
new RefValueContainer<IEnumerable<VolumeAtPriceLevelImmutable>>();
IDisposable _settings_sub, _volume_sub, _tick_sub;
IDisposable _settings_sub, _volume_sub, _tick_sub, _vm_sub;
ScrollViewer _scrollViewer;
LadderSettings _settings;
LadderVM _vm;
@@ -697,10 +697,22 @@ namespace mbts.spark {
_price_comparer = Comparer<double>.Create((x, y) => security.ContractSpec.tick_equals(x, y) ? 0 : y.CompareTo(x));
_price_dirty = true;
_piq_dirty = true;
_vm.on_tick += _tick;
// **use local vm to protect against re-assignment,
// so the events are unhooked from the same instance to which they were added
// when the subs are disposed.
var local_vm = _vm;
local_vm.on_tick += _tick;
local_vm.request_recenter += on_request_recenter;
_settings_sub = _vm.settings.OnDispatcher().Subscribe(_settings_updated);
_volume_sub = _vm.model.order_gateway.md_auxiliary_model.security_volume_at_price(security.Id).Subscribe(t => _volume_container.write_value(t.state.Values));
_tick_sub = Disposable.Create(() => _vm.on_tick -= _tick);
// **unhook from local_vm.request_recenter.
// todo: organize these subs into a single entity, prob _vm_subs.
// This hasn't already been done bc the ladder a bit fragile, so changes must be carefully implemented,
// with meticulous attention to detail.
_tick_sub = Disposable.Create(() => local_vm.on_tick -= _tick);
_vm_sub = Disposable.Create(() => local_vm.request_recenter -= on_request_recenter);
void on_request_recenter() =>
RecenterCommand?.ExecuteIfCan(null);
}
}
@@ -1068,24 +1080,24 @@ namespace mbts.spark {
double _get_bid_market_break() {
double best_bid = _get_top_price(_bids);
double best_ask = _get_top_price(_asks);
return double.IsNaN(best_bid) && !double.IsNaN(best_ask) ?
security.ContractSpec.tickdown(best_ask) :
return double.IsNaN(best_bid) ?
double.IsNaN(best_ask) ? _vm.settlement : security.ContractSpec.tickdown(best_ask) :
best_bid;
}
double _get_ask_market_break() {
double best_bid = _get_top_price(_bids);
double best_ask = _get_top_price(_asks);
return double.IsNaN(best_ask) && !double.IsNaN(best_bid) ?
security.ContractSpec.tickup(best_bid) :
best_ask;
return double.IsNaN(best_ask) ?
double.IsNaN(best_bid) ? _vm.settlement : best_bid :
security.ContractSpec.tickdown(best_ask);
}
double _get_mid_market_break() {
double best_bid = _get_top_price(_bids);
double best_ask = _get_top_price(_asks);
return double.IsNaN(best_bid) ?
double.IsNaN(best_ask) ? double.NaN : security.ContractSpec.tickdown(best_ask) :
double.IsNaN(best_ask) ? _vm.settlement : security.ContractSpec.tickdown(best_ask) :
double.IsNaN(best_ask) ? best_bid : TickUtils.mid_tick(security.ContractSpec, best_bid, best_ask);
}
@@ -1325,11 +1337,8 @@ namespace mbts.spark {
else if (!double.IsNaN(ask))
new_origin = ask;
else new_origin = mid;
if (double.IsNaN(new_origin)) {
if (double.IsNaN(new_origin))
new_origin = _owner._get_bid_market_break();
if (double.IsNaN(new_origin))
new_origin = _owner._vm.settlement;
}
origin_dirty = ConvertUtils.update_value_type(ref _origin, new_origin);
}
}
@@ -93,6 +93,7 @@ namespace mbts.spark {
_ui_scaler.MouseDoubleClick += _ui_scaler_MouseDoubleClick;
this.PreviewMouseWheel += LadderView_PreviewMouseWheel;
this.PreviewMouseDown += LadderView_PreviewMouseDown;
PreviewKeyDown += (s, e) => vm.key_down(e);
}
IDisposable _connect_left_panel_scroll() {
@@ -2,6 +2,7 @@
using System;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace mbts.ui {
@@ -51,15 +52,19 @@ namespace mbts.ui {
public void thread_init() { }
}
public static IShellWindow create(IShellModule owner, string title, string window_type, Lazy<UIElement> content, Action<UIElement, Stream> get_state = null, ImageSource icon = null, string thread_id=null, Action<ShellWindowVM> on_shell_window_vm = null) {
public static IShellWindow create(IShellModule owner, string title, string window_type, Lazy<UIElement> content, Action<UIElement, Stream> get_state = null, ImageSource icon = null, string thread_id=null, Action<ShellWindowVM> on_shell_window_vm = null, Action<KeyEventArgs> on_key_down = null) {
IShellWindow rv = null;
if (string.IsNullOrEmpty(thread_id)) {
return create<AnonShellWindow>(owner, title, window_type, content, get_state, icon, on_shell_window_vm);
rv = create<AnonShellWindow>(owner, title, window_type, content, get_state, icon, on_shell_window_vm);
if (on_key_down != null)
rv = new KeyListenerWrapper(rv, on_key_down);
}
else {
var res = create<LazyAnonShellWindow>(owner, title, window_type, content, get_state, icon, on_shell_window_vm);
res.thread_id = thread_id;
return res;
rv = on_key_down == null ? (ISharedWindow)res : new SharedKeyListenerWrapper(res, on_key_down);
}
return rv;
}
static T create<T>(IShellModule owner, string title, string window_type, Lazy<UIElement> content, Action<UIElement,Stream> get_state=null, ImageSource icon=null, Action<ShellWindowVM> on_shell_window_vm = null) where T : AnonShellWindow, new() {
var result = new T() {
@@ -121,5 +126,56 @@ namespace mbts.ui {
if (cleanup != null) { window.Closed += (o, e) => cleanup.Dispose(); }
return window;
}
class KeyListenerWrapper<T> : IShellWindow, IKeyListener where T : class, IShellWindow {
readonly T _model;
readonly Action<KeyEventArgs> _key_down;
public KeyListenerWrapper(T model, Action<KeyEventArgs> key_down) {
_model = model ?? throw new ArgumentNullException(nameof(model));
_key_down = key_down ?? throw new ArgumentNullException(nameof(key_down));
}
public event Action TitleChanged {
add => _model.TitleChanged += value;
remove => _model.TitleChanged -= value;
}
public event Action IconChanged {
add => _model.IconChanged += value;
remove => _model.IconChanged -= value;
}
public string Title { get => _model.Title; set => _model.Title = value; }
public string window_type => _model.window_type;
public ImageSource Icon => _model.Icon;
public IShellModule Owner => _model.Owner;
public void Dispose() => _model.Dispose();
public ShellWindowUI GetContent() => _model.GetContent();
public void GetState(Stream save_here) => _model.GetState(save_here);
public void on_shell_window_vm(ShellWindowVM shell_window_vm) => _model.on_shell_window_vm(shell_window_vm);
public void key_down(KeyEventArgs e) =>
_key_down(e);
}
class KeyListenerWrapper : KeyListenerWrapper<IShellWindow> {
public KeyListenerWrapper(IShellWindow model, Action<KeyEventArgs> key_down)
: base(model, key_down) { }
}
class SharedKeyListenerWrapper : KeyListenerWrapper<ISharedWindow>, ISharedWindow {
readonly ISharedWindow _model;
readonly Action<KeyEventArgs> _key_down;
public SharedKeyListenerWrapper(ISharedWindow model, Action<KeyEventArgs> key_down)
: base(model, key_down) {
_model = model ?? throw new ArgumentNullException(nameof(model));
_key_down = key_down ?? throw new ArgumentNullException(nameof(key_down));
}
public string thread_id => _model.thread_id;
public void thread_init() => _model.thread_init();
}
}
}
@@ -10,6 +10,7 @@ using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace mbts.ui.shell {
// This Class owns the hierarchy of shell Windows
@@ -59,6 +60,14 @@ namespace mbts.ui.shell {
viewmodel.host_id = state.host_id ?? "";
viewmodel.TitleOverride = state.custom_title;
}
if (model is IKeyListener key_listener) {
content.KeyDown += on_key_down;
void on_key_down(object sender, KeyEventArgs e) {
viewmodel.Dispatcher.InvokeAsync(() => {
key_listener.key_down(e);
});
}
}
var window = await CreateWindow(content, state);
window.Show();
+2 -2
View File
@@ -786,9 +786,9 @@ OutFIXPtr make_logon(uint32_t seq_num, uint32_t last_seq_num_processed,
if(session_cfg.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_ICE ||
session_cfg.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_SIMICE)
{
buffer.add<ICEApplicationSystemName>(application);
buffer.add<ICEApplicationSystemName>("Katallage");
buffer.add<ICEApplicationSystemVersion>("1.0");
buffer.add<ICEApplicationSystemVendor>("BTS");
buffer.add<ICEApplicationSystemVendor>("Katallage");
buffer.add<UserName>(session_cfg.user_name());
buffer.add<RawDataLength>(session_cfg.raw_data().size());
+8 -8
View File
@@ -620,7 +620,7 @@ OrderOpResult ICENativeOrder::on_update(api::orderman::Update const &update)
if (me->state.last_msg().size())
me->state.set_last_msg("");
LOG(OrderMan, Warn,
LOG(OrderMan, Info,
"ICE may not honor this update if we recently issued an unacknowledged cancelreplace {}. Update: {}@{}. Buffering",
key().value(), q.value(), p.value());
me->buffered_update.emplace(p, q);
@@ -807,7 +807,7 @@ void ICENativeOrder::on_exe_report(const NewExecutionReportEvent &er)
if(er.data->exec_type == api::orderman::ExecType::EXEC_TYPE_TRADE_CANCEL ||
er.data->exec_type == api::orderman::ExecType::EXEC_TYPE_TRADE_CORRECT)
{
LOG(OrderMan, Info, "ICENativeOrder ignoring Cancel or Correct execution report {} in order {}", er.data->msg_seq_num, key().value());
LOG(OrderMan, Error, "ICENativeOrder ignoring Cancel or Correct execution report {} in order {}", er.data->msg_seq_num, key().value());
return;
}
@@ -934,7 +934,7 @@ void ICENativeOrder::handle_buffered_state(const std::string& condition)
{
if (me->buffered_cancel)
{
LOG(OrderMan, Warn,
LOG(OrderMan, Info,
"Applying buffered cancel to order {}, on ",
condition,
key().value());
@@ -943,7 +943,7 @@ void ICENativeOrder::handle_buffered_state(const std::string& condition)
else if (me->buffered_update.has_value())
{
auto [p, q] = me->buffered_update.value();
LOG(OrderMan, Warn,
LOG(OrderMan, Info,
"Applying buffered update ({}@{}) to order {}, on ",
condition,
q.value(),p.value(), key().value());
@@ -1106,14 +1106,14 @@ void ICENativeOrder::init_fix()
create_encoding.add<fix::Memo>(memo);
me->create_clordid_bm = create_encoding.add<fix::Int_ClOrdID>(get_clordid(0), ice_orderid_sz());
create_encoding.add<fix::CompanyID>(std::atoi(rr.company_id().c_str()));
//create_encoding.add<fix::OnBehalfOfCompID>(""); //optional, unclear if we need
create_encoding.add<fix::OnBehalfOfCompID>("Katallage|Katallage");
std::string cust = rr.cust_order_handing_inst();
if(cust == "")
cust = "Y";
create_encoding.add<fix::CustOrderHandlingInst>(cust);
create_encoding.add<fix::SenderSubID>(rr.operator_id());
create_encoding.add<fix::OnBehalfOfSubID>(rr.operator_id() + "|" + rr.authorized_trader());
create_encoding.add<fix::OnBehalfOfLocationID>("ISV-BTS|" + rr.authorized_group());
create_encoding.add<fix::OnBehalfOfLocationID>("DAU|" + rr.authorized_group());
create_encoding.add<fix::OriginatorUserID>(rr.authorized_trader());
create_encoding.add<fix::HandlInst>('1');
create_encoding.add<fix::Int_Symbol>(sec.ice().exchange_id());
@@ -1137,10 +1137,10 @@ void ICENativeOrder::init_fix()
update_encoding.add<fix::Memo>(memo);
me->update_orig_clordid_bm = update_encoding.add<fix::Int_OrigClOrdID>(get_clordid(0), ice_orderid_sz());
update_encoding.add<fix::CompanyID>(std::atoi(rr.company_id().c_str()));
//update_encoding.add<fix::OnBehalfOfCompID>(""); //optional, unclear if we need
update_encoding.add<fix::OnBehalfOfCompID>("Katallage|Katallage");
update_encoding.add<fix::SenderSubID>(rr.operator_id());
update_encoding.add<fix::OnBehalfOfSubID>(rr.operator_id() + "|" + rr.authorized_trader());
update_encoding.add<fix::OnBehalfOfLocationID>("ISV-BTS|" + rr.authorized_group());
update_encoding.add<fix::OnBehalfOfLocationID>("DAU|" + rr.authorized_group());
update_encoding.add<fix::OriginatorUserID>(rr.authorized_trader());
update_encoding.add<fix::HandlInst>('1');
update_encoding.add<fix::Int_Symbol>(sec.ice().exchange_id());
@@ -84,7 +84,7 @@ void ICEListener::onFuturesProductDefinition(const onixs_ice::FuturesProductDefi
on_future_strip(msg, is_interested);
else
on_future(msg, is_interested);
LOG(md,Info,"ICE_Future,{},{},{},{},{},{},{},{},{},{},{},{},{}",
LOG(md,Diag,"ICE_Future,{},{},{},{},{},{},{},{},{},{},{},{},{}",
is_interested,
msg.productName, // NG Swing GDD Futures,
msg.hubAlias, // Henry
@@ -108,7 +108,7 @@ void ICEListener::onNewExpiry(const onixs_ice::NewExpiry& msg, bool& is_interest
void ICEListener::onFuturesStrategyDefinition(const onixs_ice::FuturesStrategyDefinition& msg, bool& is_interested)
{
on_uds_future_spread(msg, is_interested);
LOG(md,Info,"ICE_Strategy,{},{},{},{},{},{},{},{},{},{},{},{},{},{}",
LOG(md,Diag,"ICE_Strategy,{},{},{},{},{},{},{},{},{},{},{},{},{},{}",
is_interested,
msg.productName,
msg.hubAlias,
@@ -334,7 +334,7 @@ void ICEListener::onSettlementPrice(const onixs_ice::SettlementPrice& msg, const
auto price = msg.settlementPrice;
auto time = msg.dateTime;
auto denominator = data->handle.security().ice_settle_denominator;
LOG(md,Diag,"OnixSICE Got Settlement: {} - {}", std::to_string(data->id), std::to_string(price));
LOG(md,Info,"OnixSICE Got Settlement: {} - {}", std::to_string(data->id), std::to_string(price));
data->handle.update_settlement(ts, convert_price(price, denominator), date_of_timestamp(time));
}
}
@@ -382,7 +382,7 @@ void ICEListener::onEndOfDayMarketSummary(const onixs_ice::EndOfDayMarketSummary
auto settle_denominator = data->handle.security().ice_settle_denominator;
data->handle.update_settlement( ts, convert_price(msg.settlementPrice, settle_denominator), date_of_timestamp(time) );
LOG(md,Warn,"OnixSICE Got EOD Market : {} - {}", std::to_string(data->id), std::to_string(msg.settlementPrice));
LOG(md,Info,"OnixSICE Got EOD Market : {} - {}", std::to_string(data->id), std::to_string(msg.settlementPrice));
auto deal_denominator = data->handle.security().ice_deal_denominator;
data->handle.update_opening( ts, double_of_price(msg.openingPrice, deal_denominator), date_of_timestamp(time) );
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SRC_ROOT=$DIR/../..
BUILD_ROOT=`readlink -f $SRC_ROOT/build`
BUILD_TYPE="${1:-clang_debug}"
BUILD_CMD="ninja -C $BUILD_ROOT/$BUILD_TYPE"
touch $SRC_ROOT/CMakeLists.txt
$DIR/execute_in_docker $BUILD_CMD
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SRC_ROOT=$DIR/../..
BUILD_ROOT=`readlink -f $SRC_ROOT/build`
cgdb -- -ex start --cd=$BUILD_ROOT/ninja_debug/server --args ./sparkd run
+39
View File
@@ -0,0 +1,39 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SRC_ROOT=$DIR/../..
CMD=$@
read -d '' docker_cmd << EOF
docker run \
--rm \
--net host \
-h $(hostname)_spark \
-e "TZ=America/New_York" \
--security-opt seccomp=unconfined \
-v /var/log/syslog:/var/log/syslog \
-v /usr/local/share/fonts:/usr/local/share/fonts \
-v /usr/share/fonts:/usr/share/fonts \
-v /run/user/:/run/user/ \
-v /tmp:/tmp \
-v /etc/group:/etc/group \
-v /etc/passwd:/etc/passwd \
-v /tmp:/tmp \
-v /etc/sudoers:/etc/sudoers \
-v /home:/home \
--shm-size=4024m \
-w $SRC_ROOT \
-u $UID \
-t \
-i \
-e DISPLAY=$DISPLAY \
bluetradingsystems/linux_docker
EOF
if [ -f /.dockerenv ]; then
$CMD
else
echo "Running $CMD"
$docker_cmd $CMD
fi
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
$DIR/execute_in_docker /usr/local/bin/rdm $@
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CMD="$DIR/../setup_builds.sh"
$DIR/execute_in_docker "/bin/bash -c $CMD"
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SRC_ROOT=$DIR/../
$DIR/execute_in_docker /bin/bash
+3
View File
@@ -14,6 +14,7 @@ mkdir $BUILD_ROOT/clang_debug
cd $BUILD_ROOT/clang_debug
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_CXX_COMPILER=/usr/lib/ccache/clang++ $SRC_ROOT
rm -rf $BUILD_ROOT/ninja_debug
mkdir $BUILD_ROOT/ninja_debug
cd $BUILD_ROOT/ninja_debug
@@ -24,3 +25,5 @@ mkdir $BUILD_ROOT/ninja_release
cd $BUILD_ROOT/ninja_release
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_CXX_COMPILER=g++ $SRC_ROOT
rm -f $SRC_ROOT/compile_commands.json
ln -s $BUILD_ROOT/clang_debug/compile_commands.json $SRC_ROOT/compile_commands.json