Merged with master
This commit is contained in:
commit
0fc977f5d3
24 files changed
+336
-46
No files matched your search
@@ -11,6 +11,12 @@ insert_anchor_links = "right"
|
||||
- Added OK, Cancel buttons to the security picker for ladder profiles or sounds
|
||||
- Added ladder settings for the mini order book
|
||||
- Added a safety check to guard against unintentional market crosses
|
||||
- Improved the Queue Holder mode in the spreader:
|
||||
- Added a Show Quantity, allowing the spreader to keep queue position of the trailing orders as Fills (of size Show Qty) happen
|
||||
- Improved spreader performance when in Queue Holder mode
|
||||
### Internal changes
|
||||
- Suppressed order callbacks for completed/canceled orders. This should eliminate some bogus error logs by spreader orders.
|
||||
|
||||
|
||||
## 2.3.0
|
||||
### User Visible Changes
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
MarketDataTypeTemplate="{StaticResource SimpleValueTextTemplate}"
|
||||
MarketDataCalculationTemplate="{StaticResource SimpleValueTextTemplate}"
|
||||
ConditionalPriceTypeTemplate="{StaticResource SimpleValueTextTemplate}"
|
||||
ShowQuantityTemplate="{StaticResource SimpleValueTextTemplate}"
|
||||
>
|
||||
<usp:DataGridParameterCellTemplateConverter.BooleanTemplate>
|
||||
<DataTemplate>
|
||||
@@ -115,6 +116,16 @@
|
||||
<c:TickUpDownUInt Value="{Binding value}" IsEnabled="{Binding enabled}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.UIntTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.ShowQuantityTemplate>
|
||||
<DataTemplate>
|
||||
<!-- Note: the motivation for this Template was to enforce a Minimum via the TickUpDownUInt -->
|
||||
<!-- As of 2019/06/17, we believe such a Minimum/Maximum is not actually getting enforced and -->
|
||||
<!-- furthermore is not the appropriate way to go about enforcing said value. It is near the end -->
|
||||
<!-- of the cycle though so that is why we are leaving this Template in here for now until we -->
|
||||
<!-- can come up with a better solution. -->
|
||||
<c:TickUpDownUInt Value="{Binding value}" IsEnabled="{Binding enabled}" />
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.ShowQuantityTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.MarketDataTypeTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox SelectedItem="{Binding value}" ItemsSource="{u:EnumBindingSource {u:Nested sp:LegSpreaderParams.Types.MarketDataType}}" ItemTemplate="{StaticResource EnumDescriptionTemplate}"/>
|
||||
|
||||
@@ -240,7 +240,7 @@ namespace mbts.ui.spark {
|
||||
FrameworkElement _generate_element(IValueConverter cell_template_converter) {
|
||||
var rv = new ContentControl();
|
||||
rv.SetBinding(ContentControl.ContentProperty, new Binding());
|
||||
rv.SetBinding(ContentControl.ContentTemplateProperty, new Binding(nameof(ICell.data_type)) { Converter = cell_template_converter });
|
||||
rv.SetBinding(ContentControl.ContentTemplateProperty, new Binding() { Converter = cell_template_converter });
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -306,17 +306,23 @@ namespace mbts.ui.spark {
|
||||
public DataTemplate MarketDataTypeTemplate { get; set; }
|
||||
public DataTemplate MarketDataCalculationTemplate { get; set; }
|
||||
public DataTemplate ConditionalPriceTypeTemplate { get; set; }
|
||||
public DataTemplate ShowQuantityTemplate { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
Type t = (Type)value;
|
||||
if (t == typeof(double)) return DoubleTemplate;
|
||||
else if (t == typeof(bool)) return BooleanTemplate;
|
||||
else if (t == typeof(int)) return IntTemplate;
|
||||
else if (t == typeof(uint)) return UIntTemplate;
|
||||
else if (t == typeof(QuantityMeasure)) return QuantityMeasureTemplate;
|
||||
else if (t == typeof(LegSpreaderParams.Types.MarketDataType)) return MarketDataTypeTemplate;
|
||||
else if (t == typeof(ConditionalQuoting.Types.PriceType)) return ConditionalPriceTypeTemplate;
|
||||
else return null;
|
||||
if (value is ICell cell) {
|
||||
if (cell.row is ShowQuantityQuantityModel) {
|
||||
return ShowQuantityTemplate;
|
||||
}
|
||||
Type t = cell.data_type;
|
||||
if (t == typeof(double)) return DoubleTemplate;
|
||||
else if (t == typeof(bool)) return BooleanTemplate;
|
||||
else if (t == typeof(int)) return IntTemplate;
|
||||
else if (t == typeof(uint)) return UIntTemplate;
|
||||
else if (t == typeof(QuantityMeasure)) return QuantityMeasureTemplate;
|
||||
else if (t == typeof(LegSpreaderParams.Types.MarketDataType)) return MarketDataTypeTemplate;
|
||||
else if (t == typeof(ConditionalQuoting.Types.PriceType)) return ConditionalPriceTypeTemplate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
|
||||
@@ -108,6 +108,9 @@ namespace bts.shell {
|
||||
NTicks = 2,
|
||||
PriceType = ConditionalQuoting.Types.PriceType.Leg
|
||||
};
|
||||
public static NullableQuantity ShowQuantity => new NullableQuantity {
|
||||
Quantity = 1
|
||||
};
|
||||
public static QuoteInsideMarketDistanceWithTravel QuoteInsideMarketDistanceWithTravel => new QuoteInsideMarketDistanceWithTravel { Priority = RulePriority };
|
||||
public static QuoteInsideMarketDistance QuoteInsideMarketDistance => new QuoteInsideMarketDistance { Priority = RulePriority };
|
||||
#endregion
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace mbts.spark {
|
||||
|
||||
public virtual Type data_type { get; } = typeof(T);
|
||||
|
||||
public virtual IRowModel row { get => _model; }
|
||||
|
||||
public T value {
|
||||
get => _model.get_value(_leg_tup);
|
||||
set {
|
||||
@@ -64,6 +66,8 @@ namespace mbts.spark {
|
||||
|
||||
public Type data_type { get; } = typeof(QuantityMeasure);
|
||||
|
||||
public virtual IRowModel row { get => _model; }
|
||||
|
||||
public double ratio {
|
||||
get => _get_qm().Ratio;
|
||||
set {
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
using bts.shell;
|
||||
using mbts.ui.spark;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class SyntheticEditorVM {
|
||||
class ShowQuantityEnabledModel : RowModelBase<bool> {
|
||||
readonly ShowQuantityQuantityModel _quantity;
|
||||
|
||||
public ShowQuantityEnabledModel(ShowQuantityQuantityModel quantity) {
|
||||
_quantity = quantity;
|
||||
}
|
||||
|
||||
public override string display_name => string.Empty;
|
||||
public override string help_text => string.Empty;
|
||||
public override string man_page => string.Empty;
|
||||
|
||||
public override ParameterSection[] section_path { get; } = new[] { Sections.Quote, Subsections.ShowQuantity };
|
||||
|
||||
public override bool get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.QuoteParams.ShowQuantity != null;
|
||||
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) {
|
||||
if (value) {
|
||||
if (leg_tup.leg_params.QuoteParams.ShowQuantity == null) {
|
||||
leg_tup.leg_params.QuoteParams.ShowQuantity = SyntheticDataHelper.Defaults.ShowQuantity;
|
||||
_quantity.apply_value(leg_tup);
|
||||
}
|
||||
} else {
|
||||
leg_tup.leg_params.QuoteParams.ShowQuantity = null;
|
||||
}
|
||||
_quantity.set_enabled(leg_tup, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
using bts.shell;
|
||||
using bts.spark;
|
||||
using mbts.ui.spark;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class SyntheticEditorVM {
|
||||
internal class ShowQuantityQuantityModel : RowModelBase<uint> {
|
||||
IDictionary<uint, uint> _value_store = new Dictionary<uint, uint>();
|
||||
|
||||
public override string display_name => "Quantity";
|
||||
|
||||
public override string help_text => string.Empty;
|
||||
|
||||
public override string man_page => string.Empty;
|
||||
|
||||
public override ParameterSection[] section_path { get; } = new[] { Sections.Quote, Subsections.ShowQuantity };
|
||||
|
||||
public void apply_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_value(leg_tup).Quantity = _value_from_store(leg_tup);
|
||||
|
||||
|
||||
public override uint get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_value(leg_tup) is NullableQuantity show_quantity ? show_quantity.Quantity : _value_from_store(leg_tup);
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) {
|
||||
_value_store[leg_tup.SecurityKey] = value;
|
||||
if (_get_value(leg_tup) is NullableQuantity show_quantity) {
|
||||
show_quantity.Quantity = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_value(leg_tup) != null;
|
||||
|
||||
NullableQuantity _get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.QuoteParams.ShowQuantity;
|
||||
|
||||
uint _value_from_store(LegSpreaderParamsTuple leg_tup) =>
|
||||
_value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.ShowQuantity.Quantity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ namespace mbts.spark {
|
||||
|
||||
internal interface ICell {
|
||||
event Action value_changed;
|
||||
IRowModel row { get; }
|
||||
Type data_type { get; }
|
||||
bool enabled { get; }
|
||||
}
|
||||
@@ -40,7 +41,7 @@ namespace mbts.spark {
|
||||
FontWeight font_weight { get; }
|
||||
}
|
||||
|
||||
abstract class RowModelBase<T> : ViewModelBase, IRowModel {
|
||||
internal abstract class RowModelBase<T> : ViewModelBase, IRowModel {
|
||||
readonly Dictionary<uint, ReplaySubject<bool>> _enabled_store = new Dictionary<uint, ReplaySubject<bool>>();
|
||||
readonly Dictionary<uint, Subject<T>> _override_value_store = new Dictionary<uint, Subject<T>>();
|
||||
|
||||
@@ -98,6 +99,10 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
private static class Subsections {
|
||||
public static ParameterSection ShowQuantity =>
|
||||
new ParameterSection("Show Quantity", true,
|
||||
"The quantity shown when the order is placed.");
|
||||
|
||||
public static ParameterSection Throttle =>
|
||||
new ParameterSection("Throttle", true,
|
||||
"Reduces re-quoting updates by defining a region on either side " +
|
||||
|
||||
@@ -177,6 +177,8 @@ namespace mbts.spark {
|
||||
} else {
|
||||
_can_add_leg = backing(nameof(can_add_leg), false);
|
||||
}
|
||||
var show_quantity_quantity = new ShowQuantityQuantityModel();
|
||||
|
||||
var quote_throttle_outside_ticks = new QuoteThrottleOutsideTicksModel();
|
||||
var quote_throttle_inside_ticks = new QuoteThrottleInsideTicksModel();
|
||||
|
||||
@@ -211,6 +213,8 @@ namespace mbts.spark {
|
||||
//new QuoteHiddenModel(),
|
||||
new QuoteQueueHolderModel(),
|
||||
new MarketDataTypeModel(),
|
||||
new ShowQuantityEnabledModel(show_quantity_quantity),
|
||||
show_quantity_quantity,
|
||||
new QuoteThrottleEnabledModel(quote_throttle_inside_ticks, quote_throttle_outside_ticks),
|
||||
quote_throttle_inside_ticks,
|
||||
quote_throttle_outside_ticks,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using mbts.ui.extensions;
|
||||
using bts.utils;
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.utilities;
|
||||
using System;
|
||||
using System.Linq;
|
||||
@@ -38,6 +39,32 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Minimum
|
||||
public static readonly DependencyProperty MinimumProperty =
|
||||
WPFHelper.create_dp<uint, TickUpDownUInt>(
|
||||
nameof(Minimum),
|
||||
(o, v) => o.CoerceValue(ValueProperty),
|
||||
uint.MinValue);
|
||||
|
||||
public uint Minimum {
|
||||
get => (uint)GetValue(MinimumProperty);
|
||||
set => SetValue(MinimumProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Maximum
|
||||
public static readonly DependencyProperty MaximumProperty =
|
||||
WPFHelper.create_dp<uint, TickUpDownUInt>(
|
||||
nameof(Maximum),
|
||||
(o, v) => o.CoerceValue(ValueProperty),
|
||||
uint.MaxValue);
|
||||
|
||||
public uint Maximum {
|
||||
get => (uint)GetValue(MaximumProperty);
|
||||
set => SetValue(MaximumProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Value
|
||||
public static readonly DependencyProperty ValueProperty =
|
||||
WPFHelper.create_dp<uint, TickUpDownUInt>(
|
||||
@@ -53,6 +80,7 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
}
|
||||
},
|
||||
(o, v) => MathUtils.within_range(o.Minimum, o.Maximum, v),
|
||||
0u);
|
||||
|
||||
public uint Value {
|
||||
|
||||
@@ -72,6 +72,12 @@ namespace bts.utils {
|
||||
if (value > max) return max;
|
||||
return value;
|
||||
}
|
||||
public static uint within_range(uint min, uint max, uint value) {
|
||||
if (value < min) return min;
|
||||
if (value > max) return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int RoundFractionalUnits(double value, double fractional_unit) =>
|
||||
(int)Math.Round(value / fractional_unit);
|
||||
|
||||
|
||||
@@ -186,6 +186,7 @@ message QueueHolderDefinition{
|
||||
// orders behind the top one (so value
|
||||
// of 1 means 2 orders in all)
|
||||
uint32 n_queue_orders = 1;
|
||||
spark.NullableQuantity show_quantity = 2;
|
||||
CustomOrderDefinition child=10;
|
||||
}
|
||||
message OCOOrderDefinition {
|
||||
|
||||
@@ -22,6 +22,7 @@ private:
|
||||
api::Side _side;
|
||||
double _tick_size;
|
||||
uint16_t _n_eff_orders;
|
||||
uint32_t _show_qty;
|
||||
// the order of this does is not asc/desc wrt
|
||||
// price (modify of price will make it unordered)
|
||||
std::vector<SpreaderChildOrderState> _orders;
|
||||
@@ -36,6 +37,7 @@ public:
|
||||
_side(api::Side::SIDE_BUY),
|
||||
_tick_size(os::nan()),
|
||||
_n_eff_orders(1),
|
||||
_show_qty(0),
|
||||
_orders(),
|
||||
_target_price(os::nan()),
|
||||
_target_qty(0){
|
||||
@@ -56,6 +58,7 @@ public:
|
||||
api::Side side,
|
||||
double tick_size,
|
||||
uint16_t n_orders,
|
||||
uint32_t show_qty,
|
||||
Price price,
|
||||
Quantity qty){
|
||||
_inited=true;
|
||||
@@ -65,6 +68,7 @@ public:
|
||||
// 1 trailing order means 2 total orders and so forth
|
||||
_n_eff_orders=n_orders+1;
|
||||
_orders.reserve(_n_eff_orders);
|
||||
_show_qty=show_qty;
|
||||
for(uint16_t i=0;i<_n_eff_orders;i++)
|
||||
_orders.emplace_back(key,true,true);
|
||||
_target_price=price;
|
||||
@@ -83,9 +87,7 @@ public:
|
||||
bts_assert(o.out_quantity().value()==0);
|
||||
ChildOrder child_order=_order_builder->build();
|
||||
o.re_init(child_order);
|
||||
o.place_order(Price(price_i),
|
||||
target_qty,
|
||||
bts::Timer::now());
|
||||
_place_order(o,Price(price_i),target_qty);
|
||||
price_i+=move_inc;
|
||||
}
|
||||
}
|
||||
@@ -101,9 +103,7 @@ public:
|
||||
Price price=o.out_price();//re-init resets the price
|
||||
ChildOrder child_order=_order_builder->build();
|
||||
o.re_init(child_order);
|
||||
o.place_order(price,
|
||||
target_qty,
|
||||
bts::Timer::now());
|
||||
_place_order(o,price,target_qty);
|
||||
}
|
||||
else
|
||||
_prune_qty(o);
|
||||
@@ -240,7 +240,8 @@ private:
|
||||
remaining_target.value(),
|
||||
true); // qty inc since its
|
||||
// changing price levels
|
||||
to_move.modify_order(Price(price_i),Quantity(new_ord_qty));
|
||||
//to_move.modify_order(Price(price_i),Quantity(new_ord_qty));
|
||||
_modify_child_order(to_move,Price(price_i),Quantity(new_ord_qty));
|
||||
}
|
||||
else
|
||||
_prune_qty(*order_i);
|
||||
@@ -256,7 +257,8 @@ private:
|
||||
_remaining().value(),
|
||||
false); // dont inc the qty
|
||||
bts_assert(new_ord_qty>0);
|
||||
o.modify_order(o.out_price(),Quantity(new_ord_qty));
|
||||
//o.modify_order(o.out_price(),Quantity(new_ord_qty));
|
||||
_modify_child_order(o,o.out_price(),Quantity(new_ord_qty));
|
||||
}
|
||||
Quantity _remaining() const{
|
||||
if(filled_qty().value()>=_target_qty.value())
|
||||
@@ -290,6 +292,28 @@ private:
|
||||
rv=&o;
|
||||
return *rv;
|
||||
}
|
||||
Quantity _force_show_qty(Quantity target_qty){
|
||||
return _show_qty==0 ? target_qty :
|
||||
Quantity(std::min(target_qty.value(),
|
||||
_show_qty));
|
||||
}
|
||||
void _place_order(SpreaderChildOrderState& ord,
|
||||
Price price, Quantity qty){
|
||||
qty=_force_show_qty(qty);
|
||||
ord.place_order(price,qty,bts::Timer::now());
|
||||
}
|
||||
void _modify_child_order(SpreaderChildOrderState& ord,
|
||||
Price price,
|
||||
Quantity qty){
|
||||
qty=_force_show_qty(qty);
|
||||
if(ord.out_quantity() == qty &&
|
||||
bts::securities::test_price_equality(
|
||||
price.value(),
|
||||
ord.out_price().value(),
|
||||
_tick_size))
|
||||
return;
|
||||
ord.modify_order(price,qty);
|
||||
}
|
||||
// given an order's filled and order qty, and the
|
||||
// target left on the total qho, finds the adjusted
|
||||
// qty of the order
|
||||
|
||||
@@ -69,6 +69,9 @@ OrderOpResult QueueHolderOrder::on_update(Price price,
|
||||
return OrderOpResult {};
|
||||
}
|
||||
OrderOpResult QueueHolderOrder::on_cancel() {
|
||||
LOG(OrderMan, Info,
|
||||
"QueueHolderOrder::on_cancel key:{} state:{}",
|
||||
key(), _state_int());
|
||||
_state_worker->on_cancel();
|
||||
_report_state();
|
||||
return OrderOpResult {};
|
||||
@@ -81,6 +84,9 @@ void QueueHolderOrder::_on_book_update(const BookUpdateEvent& b) {
|
||||
}
|
||||
void QueueHolderOrder::_on_child_order_update(
|
||||
const OrderStateUpdateEvent& c) {
|
||||
LOG(OrderMan, Diag,
|
||||
"QueueHolderOrder::_on_child_order_update key:{} state:{} "
|
||||
"order_key:{} order_state:{}", key(), _state_int(), c.key, c.status);
|
||||
_state_worker->on_child_order_update(c);
|
||||
_report_state();
|
||||
}
|
||||
@@ -161,4 +167,4 @@ api::orderman::OrderStatus QueueHolderOrder::_status(std::string& message) const
|
||||
return api::orderman::OrderStatus::ORDER_STATUS_WORKING;
|
||||
}
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
} // namespace bts
|
||||
@@ -106,6 +106,7 @@ private:
|
||||
}
|
||||
_reported_state.set_avg_price(filled_price);
|
||||
_reported_state.set_filled_quantity(filled_qty);
|
||||
_reported_state.set_display_status(bts::api::orderman::OrderState::HIDDEN);
|
||||
if(!_state_eq()){
|
||||
_sent_state=_reported_state;
|
||||
_services->report_state(_reported_state);
|
||||
|
||||
@@ -48,13 +48,16 @@ void QHOStartStateWorker::on_activate(Price price,
|
||||
if (_porder->_is_recovered || !_porder->_is_succ_inited)
|
||||
_porder->_switch_state(QueueHolderOrderState::END);
|
||||
else {
|
||||
const auto& qho_order=_porder->_order_def.custom_def().queue_holder();
|
||||
_porder->_order_builder.activate(services);
|
||||
_porder->_order_manager.init(
|
||||
_porder->_order_builder,
|
||||
SecurityKey(_porder->_order_def.security_key()),
|
||||
_porder->_order_def.side(),
|
||||
_porder->_tick_size,
|
||||
_porder->_order_def.custom_def().queue_holder().n_queue_orders(),
|
||||
qho_order.n_queue_orders(),
|
||||
qho_order.has_show_quantity() ?
|
||||
qho_order.show_quantity().quantity() : 0,
|
||||
price,
|
||||
qty);
|
||||
services.subscribe_to_child_updates(
|
||||
|
||||
@@ -76,16 +76,22 @@ bool QHOWorkingStateWorker::_analyze_moving_out(){
|
||||
// constituent orders end up in an unexpected terminal
|
||||
// state
|
||||
if(_porder->_filled()){
|
||||
LOG(OrderMan, Info, "QHOWorkingStateWorker::_analyze_moving_out "
|
||||
"_filled key:{}", _porder->key());
|
||||
_porder->_cancel_order(QueueHolderOrder::TerminationReason::FILLED);
|
||||
return true;
|
||||
}
|
||||
const QHOOrderManager& order_man=_porder->_order_manager;
|
||||
if(order_man.has_cancelled_order()){
|
||||
LOG(OrderMan, Info, "QHOWorkingStateWorker::_analyze_moving_out "
|
||||
"has_cancelled_order key:{}", _porder->key());
|
||||
_porder->_cancel_order(
|
||||
QueueHolderOrder::TerminationReason::UNEXPECTED_CHILD_CANCEL);
|
||||
return true;
|
||||
}
|
||||
if(order_man.has_errored_order()){
|
||||
LOG(OrderMan, Info, "QHOWorkingStateWorker::_analyze_moving_out "
|
||||
"has_errored_order key:{}", _porder->key());
|
||||
_porder->_cancel_order(QueueHolderOrder::TerminationReason::CHILD_ERROR);
|
||||
return true;
|
||||
}
|
||||
@@ -93,7 +99,9 @@ bool QHOWorkingStateWorker::_analyze_moving_out(){
|
||||
// yet one or more component orders has been filled.
|
||||
// switching to WAITING_FOR_FIRST_ACK will cause
|
||||
// filled orders to be replaced with new orders
|
||||
if (order_man.has_completed_order()){
|
||||
if (order_man.has_completed_order()){
|
||||
LOG(OrderMan, Info, "QHOWorkingStateWorker::_analyze_moving_out "
|
||||
"has_completed_order key:{}", _porder->key());
|
||||
_porder->_switch_state(QueueHolderOrderState::WAITING_FOR_FIRST_ACK);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,19 @@ public:
|
||||
bts::spark::LegSpreaderParams::MarketDataType md_type() const {
|
||||
return _leg_params.market_data_type();
|
||||
}
|
||||
bool has_show_qty () const{
|
||||
return _leg_params.quote_params().has_show_quantity() &&
|
||||
show_qty() > 0;
|
||||
}
|
||||
uint32_t show_qty () const{
|
||||
return _leg_params.quote_params().show_quantity().quantity();
|
||||
}
|
||||
bool has_queue_holder() const{
|
||||
return n_queue_holder_orders()>0;
|
||||
}
|
||||
uint32_t n_queue_holder_orders() const{
|
||||
return _leg_params.quote_params().n_queue_holder_orders();
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -64,6 +64,7 @@ public:
|
||||
Quantity out_quantity() const {
|
||||
return _order.out_quantity();
|
||||
}
|
||||
// this is target - (filled + hedge reduction)
|
||||
Quantity remaining_to_fill() const{
|
||||
uint32_t rv = 0;
|
||||
uint32_t accounted_for = total_filled_quantity().value() + _aggregated_hedged_reduction.value ();
|
||||
|
||||
@@ -20,6 +20,8 @@ _two_legged (n_spreader_legs == 2),
|
||||
_active_quoting(this_leg_property.is_active_quoting()),
|
||||
_hidden_order(this_leg_property.leg_params().has_quote_params() &&
|
||||
this_leg_property.leg_params().quote_params().has_quote_hidden()),
|
||||
_force_show_qty(this_leg_property.n_queue_holder_orders()==0 &&
|
||||
this_leg_property.has_show_qty()),
|
||||
_is_permenantly_cancelled (false),
|
||||
_irrecoverable_error(false),
|
||||
_n_spreader_legs (n_spreader_legs),
|
||||
@@ -50,6 +52,7 @@ SingleLegQuoter::SingleLegQuoter(SingleLegQuoter&& other)
|
||||
_two_legged (other._two_legged),
|
||||
_active_quoting(other._active_quoting),
|
||||
_hidden_order(other._hidden_order),
|
||||
_force_show_qty(other._force_show_qty),
|
||||
_is_permenantly_cancelled (other._is_permenantly_cancelled),
|
||||
_irrecoverable_error(other._irrecoverable_error),
|
||||
_n_spreader_legs (other._n_spreader_legs),
|
||||
@@ -161,29 +164,70 @@ bool SingleLegQuoter::accept_modifications() const {
|
||||
void SingleLegQuoter::_incorporate_other_leg_fill (size_t, Quantity hedge_reduction){
|
||||
_price_quantity_state.add_hedged_reduction (hedge_reduction);
|
||||
}
|
||||
void SingleLegQuoter::_compute_price_quantity(Price& price,
|
||||
Quantity& quantity){
|
||||
Quantity remaining_quantity = _price_quantity_state.remaining_to_fill();
|
||||
void SingleLegQuoter::_compute_quote(
|
||||
Quantity target_qty,
|
||||
Price& out_price,
|
||||
Quantity &out_qty){
|
||||
if (_two_legged){
|
||||
size_t other_leg_index = _this_leg_data.leg_index() == 0 ? 1 : 0;
|
||||
SpreaderUtils::compute_price_quantity_2_legs (_price_quantity_state.target_spread_price(),
|
||||
remaining_quantity,
|
||||
_this_leg_data,
|
||||
_spreader.get_leg_data(other_leg_index),
|
||||
_spreader.get_book(other_leg_index),
|
||||
price, quantity);
|
||||
bts_assert (quantity.value() <= remaining_quantity.value());
|
||||
}
|
||||
SpreaderUtils::compute_price_quantity_2_legs (
|
||||
_price_quantity_state.target_spread_price(),
|
||||
target_qty,
|
||||
_this_leg_data,
|
||||
_spreader.get_leg_data(other_leg_index),
|
||||
_spreader.get_book(other_leg_index),
|
||||
out_price,
|
||||
out_qty);
|
||||
bts_assert (out_qty.value() <= target_qty.value());
|
||||
}
|
||||
else
|
||||
SpreaderUtils::compute_quoting_price_size_n_legs (_price_quantity_state.target_spread_price(),
|
||||
remaining_quantity,
|
||||
_this_leg_data.leg_index(),
|
||||
_spreader,
|
||||
_drivers_temp_usage,
|
||||
price,
|
||||
quantity);
|
||||
if(!_apply_quote_entry_params(price, quantity))
|
||||
quantity=Quantity(0);
|
||||
SpreaderUtils::compute_quoting_price_size_n_legs (
|
||||
_price_quantity_state.target_spread_price(),
|
||||
target_qty,
|
||||
_this_leg_data.leg_index(),
|
||||
_spreader,
|
||||
_drivers_temp_usage,
|
||||
out_price,
|
||||
out_qty);
|
||||
}
|
||||
void SingleLegQuoter::_compute_quote_non_qho(Price& out_price,
|
||||
Quantity& out_qty){
|
||||
uint32_t tot_remaining = _price_quantity_state.remaining_to_fill().value(),
|
||||
effective_remaning = tot_remaining;
|
||||
// if there is a show qty then the quoting target
|
||||
// needs to be adjusted
|
||||
if (_this_leg_data.has_show_qty()){
|
||||
uint32_t curr_outstanding = SpreaderUtils::subtract_quanitities(
|
||||
_this_leg_data.show_qty(),
|
||||
_price_quantity_state.aggregated_filled_quantity().value());
|
||||
effective_remaning = std::min(tot_remaining, curr_outstanding);
|
||||
}
|
||||
_compute_quote(Quantity(effective_remaning),out_price,out_qty);
|
||||
}
|
||||
|
||||
void SingleLegQuoter::_compute_quote_qho(Price& out_price,
|
||||
Quantity& out_qty){
|
||||
uint32_t tot_remaining = _price_quantity_state.remaining_to_fill().value(),
|
||||
effective_remaning = tot_remaining;
|
||||
_compute_quote(Quantity(effective_remaning),out_price,out_qty);
|
||||
if (_this_leg_data.has_show_qty()){
|
||||
// since the actual order is always
|
||||
// limited by the show size we can get a better price
|
||||
// because of the smaller size req
|
||||
Quantity show_qty;
|
||||
_compute_quote(Quantity(_this_leg_data.show_qty()),out_price,show_qty);
|
||||
// however we need not pass the show_qty since the
|
||||
// qho order deals with it itself
|
||||
}
|
||||
}
|
||||
void SingleLegQuoter::_compute_price_quantity(Price& out_price,
|
||||
Quantity& out_qty){
|
||||
if(_this_leg_data.has_queue_holder())
|
||||
_compute_quote_qho(out_price,out_qty);
|
||||
else
|
||||
_compute_quote_non_qho(out_price,out_qty);
|
||||
if(!_apply_quote_entry_params(out_price, out_qty))
|
||||
out_qty=Quantity(0);
|
||||
}
|
||||
bool SingleLegQuoter::_apply_quote_entry_params(
|
||||
Price new_price,
|
||||
|
||||
@@ -40,6 +40,9 @@ private:
|
||||
const bool _two_legged;
|
||||
const bool _active_quoting;
|
||||
const bool _hidden_order;
|
||||
// if this is set to true, _compute_price_quantity
|
||||
// will use LegPropertyData::show_qty()
|
||||
const bool _force_show_qty;
|
||||
bool _is_permenantly_cancelled;
|
||||
bool _irrecoverable_error;
|
||||
// this is a config constant. if the quoter
|
||||
@@ -179,6 +182,26 @@ 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);
|
||||
// given a target quoting qty
|
||||
// this figures out the price and the actual
|
||||
// qty that can be quoted.
|
||||
// ex: on a 2.0*l1-1.0*l2 spread such that
|
||||
// spread qty=100 => l1_qty=200
|
||||
// l2 filled = 30
|
||||
// l1 filled = 60
|
||||
// remaining l1 needed: 200-(30*2)-60=80
|
||||
// so target_qty=80, it will look at the
|
||||
// hedging markets and tell how much of the
|
||||
// 80 can be quoted and at what price
|
||||
void _compute_quote(Quantity target_qty,
|
||||
Price& out_price,
|
||||
Quantity &out_qty);
|
||||
// computes the quote price and outstanding qty that
|
||||
// can be quoted for this leg in non qho mode
|
||||
void _compute_quote_non_qho(Price& price, Quantity& quantity);
|
||||
// computes the quote price and outstanding qty that
|
||||
// can be quoted for this leg in qho mode
|
||||
void _compute_quote_qho(Price& price, Quantity& quantity);
|
||||
// this is the function that computes the quoting price and the
|
||||
// quantity for this leg.
|
||||
void _compute_price_quantity(Price& price, Quantity& quantity);
|
||||
|
||||
@@ -46,12 +46,17 @@ bool SpreaderUtils::resolve_synthetic_spread (const SpreaderPreActivationOrderSe
|
||||
quoter_order_def.set_side(leg_order_side);
|
||||
quoter_order_def.set_sub_type(bts::api::orderman::OrderSubType::ORDER_SUB_TYPE_QUOTING_LEG);
|
||||
|
||||
uint32_t n_queue_holder_orders=leg_params.quote_params().n_queue_holder_orders();
|
||||
const auto& quote_params=leg_params.quote_params();
|
||||
uint32_t n_queue_holder_orders=quote_params.n_queue_holder_orders();
|
||||
if(n_queue_holder_orders>0){
|
||||
api::orderman::QueueHolderDefinition qho_order_def;
|
||||
qho_order_def.set_n_queue_orders(n_queue_holder_orders);
|
||||
qho_order_def.mutable_child()->mutable_limit()->MergeFrom (api::orderman::LimitOrderDefinition());
|
||||
quoter_order_def.mutable_custom_def()->mutable_queue_holder()->MergeFrom (qho_order_def);
|
||||
if(quote_params.has_show_quantity() &&
|
||||
quote_params.show_quantity().quantity()>0){
|
||||
qho_order_def.mutable_show_quantity()->CopyFrom(quote_params.show_quantity());
|
||||
}
|
||||
quoter_order_def.mutable_custom_def()->mutable_queue_holder()->MergeFrom (qho_order_def);
|
||||
}
|
||||
else{
|
||||
quoter_order_def.mutable_custom_def()->mutable_limit()->MergeFrom (api::orderman::LimitOrderDefinition());
|
||||
|
||||
@@ -33,6 +33,10 @@ public:
|
||||
api::Side static invert_side(api::Side side){
|
||||
return side == api::SIDE_BUY ? api::SIDE_SELL : api::SIDE_BUY;
|
||||
}
|
||||
// q1-q2
|
||||
uint32_t static subtract_quanitities (uint32_t q1, uint32_t q2){
|
||||
return (q1<q2) ? 0 : q1-q2;
|
||||
}
|
||||
// returns the effective threshold quantity, based
|
||||
// on the absolute or ratio setting in
|
||||
// QuantityMeasure (the second arg is used in the
|
||||
|
||||
@@ -16,6 +16,9 @@ message QuantityMeasure
|
||||
}
|
||||
}
|
||||
|
||||
message NullableQuantity{
|
||||
uint32 quantity = 10;
|
||||
}
|
||||
// /*************************************************************************************************/
|
||||
// /*************************************************************************************************/
|
||||
// /*************************************Spreader Parameters*****************************************/
|
||||
@@ -43,7 +46,7 @@ message LegSpreaderParams
|
||||
PreHedgeParams pre_hedge_params = 50;
|
||||
PostHedgeParams post_hedge_params = 60;
|
||||
MarketDataType market_data_type = 70;
|
||||
//reserve LegMarketDataCalculation leg_md_calc = 80;
|
||||
//reserve LegMarketDataCalculation leg_md_calc = 80;
|
||||
}
|
||||
|
||||
// /*************************************************************************************************
|
||||
@@ -70,6 +73,8 @@ message QuoteParams
|
||||
// (once we have ChildOrder's here, we can reture this
|
||||
// and the user can embed a QHO here)
|
||||
uint32 n_queue_holder_orders=2000;
|
||||
// this is the show quantity on the quoter order
|
||||
NullableQuantity show_quantity = 2010;
|
||||
}
|
||||
|
||||
/*************************************Quote MuteZone***********************************
|
||||
|
||||
Reference in new issue
Block a user