made the 'toward' behavior on lean an enum

This commit is contained in:
Kevin Darby committed 2018-09-19 16:36:25 -04:00
1 parent bd4f840d27
commit bedd0051a9
6 files changed
+81 -25

No files matched your search

@@ -25,14 +25,14 @@ namespace mbts.spark
cross_threshold = new InlineUserProperty<bts.spark.QuantityMeasure>(
new bts.spark.QuantityMeasure() { Ratio = 1.0, Absolute = 1}, false);
max_chase_ticks = new InlineUserProperty<uint>(2, false);
detach_on_toward = new InlineUserProperty<bool>(true, false);
trade_toward_behavior = new InlineUserProperty<LeanOrderDefinition.Types.OnToward>(LeanOrderDefinition.Types.OnToward.Cancel, false);
}
public readonly InlineUserProperty<CustomOneofCase> selected_child_order_type;
public readonly InlineUserProperty<IReadOnlyCollection<CustomOneofCase>> child_order_types;
public readonly InlineUserProperty<bts.spark.QuantityMeasure> cross_threshold;
public readonly InlineUserProperty<uint> max_chase_ticks;
public readonly InlineUserProperty<bool> detach_on_toward;
public readonly InlineUserProperty<LeanOrderDefinition.Types.OnToward> trade_toward_behavior;
}
class LeanOrderVM : OrderTypeVMBase<LeanOrderDefinition>, IHierarchicalOrderTypeVM, IDisposable
@@ -47,7 +47,7 @@ namespace mbts.spark
public bts.spark.QuantityMeasure cross_threshold { get; set; } = new bts.spark.QuantityMeasure() { Ratio = 1.0, Absolute = 1 };
public uint max_chase_ticks { get; set; } = 2;
public bool detach_on_toward { get; set; } = true;
public LeanOrderDefinition.Types.OnToward trade_toward_behavior { get; set; } = LeanOrderDefinition.Types.OnToward.Cancel;
public LeanOrderVM(OrdersModel model, IObservable<SecurityMD> security_md_source)
: this(model, security_md_source, security_md_source.Select(smd =>
@@ -80,10 +80,10 @@ namespace mbts.spark
max_chase_ticks = p.max_chase_ticks.value;
RaisePropertyChanged(nameof(max_chase_ticks));
}
if (p.detach_on_toward.force_override)
if (p.trade_toward_behavior.force_override)
{
detach_on_toward = p.detach_on_toward.value;
RaisePropertyChanged(nameof(detach_on_toward));
trade_toward_behavior = p.trade_toward_behavior.value;
RaisePropertyChanged(nameof(trade_toward_behavior));
}
_inline_props = p;
_validate();
@@ -102,11 +102,13 @@ namespace mbts.spark
var i = factory.lean_order();
i.CrossThreshold = cross_threshold;
i.MaxChaseTicks = max_chase_ticks;
i.DetachOnToward = detach_on_toward;
i.TradeTowardBehavior = trade_toward_behavior;
child_order.assign_to(i.Child);
value.Lean = i;
}
}
}
public IEnumerable<LeanOrderDefinition.Types.OnToward> trade_toward_types => EnumHelper.get_values_except<LeanOrderDefinition.Types.OnToward>();
public ICollection<IOrderTypeVM> child_order_types
{
@@ -235,7 +235,8 @@
<uag:QuantityMeasureControl Grid.Row="1" Grid.Column="2" QuantityMeasure="{Binding cross_threshold}"/>
<TextBlock Grid.Row="3" VerticalAlignment="Center">Max Chase Ticks</TextBlock>
<c:TickUpDownUInt Grid.Row="3" Grid.Column="2" Value="{Binding max_chase_ticks}"/>
<CheckBox Grid.Row="5" Grid.Column="2" VerticalAlignment="Center" Margin="0,0,0,0" IsChecked="{Binding detach_on_toward}">Detach on Toward</CheckBox>
<TextBlock Grid.Row="5">On Toward</TextBlock>
<ComboBox Grid.Row="5" Grid.Column="2" ItemsSource="{Binding trade_toward_types}" ItemTemplate="{StaticResource EnumDescriptionTemplate}" SelectedItem="{Binding trade_toward_behavior}"/>
<TextBlock Grid.Row="7">Child</TextBlock>
<uag:OrderDetailsPopupControl
Grid.Row="7" Grid.Column="2"
+9 -1
View File
@@ -109,7 +109,15 @@ message TickOrderDefinition {
message LeanOrderDefinition {
spark.QuantityMeasure cross_threshold = 1;
uint32 max_chase_ticks = 2;
bool detach_on_toward = 4;
reserved 4; reserved "detach_on_toward";
enum OnToward
{
NO_CHANGE = 0; //continue to lean on initial inside market
CANCEL = 1; //cancel algo and order
DETACH = 2; //cancel algo but leave order working
REPRICE = 3; //lean on new inside market
}
OnToward trade_toward_behavior = 5;
CustomOrderDefinition child = 3;
}
message JoinOrderDefinition {
@@ -12,12 +12,12 @@ using namespace api::orderman;
struct LeanOrder::PImpl
{
PImpl() : cross_threshold(), max_chase_ticks(0), detach_on_toward(false), opposite_at_inception(), num_chases(0)
PImpl() : cross_threshold(), max_chase_ticks(0), trade_toward_behavior(LeanOrderDefinition_OnToward_NO_CHANGE), opposite_at_inception(), num_chases(0)
{}
spark::QuantityMeasure cross_threshold;
uint32_t max_chase_ticks;
bool detach_on_toward;
LeanOrderDefinition_OnToward trade_toward_behavior;
md::PriceSize opposite_at_inception;
uint32_t num_chases;
@@ -37,7 +37,7 @@ void LeanOrder::setup_child(const api::orderman::OrderDefinition& this_def, cons
me->cross_threshold = lean_def.cross_threshold();
me->max_chase_ticks = lean_def.max_chase_ticks();
me->detach_on_toward = lean_def.detach_on_toward();
me->trade_toward_behavior = lean_def.trade_toward_behavior();
}
void LeanOrder::payup(const md::PriceSize&, const bts::orderman::BookUpdateEvent& book, uint32_t cross_ticks /*= 0*/)
@@ -96,6 +96,33 @@ void LeanOrder::paydown(const md::PriceSize&, const bts::orderman::BookUpdateEve
report_state();
}
void LeanOrder::choose_trade_toward_behavior(const md::PriceSize& opposite)
{
switch (me->trade_toward_behavior)
{
case LeanOrderDefinition_OnToward_CANCEL:
{
cancel_child();
transition(ORDER_STATUS_CANCELED);
report_state();
}
break;
case LeanOrderDefinition_OnToward_DETACH:
{
detach();
}
break;
case LeanOrderDefinition_OnToward_REPRICE:
{
me->opposite_at_inception = opposite;
}
break;
case LeanOrderDefinition_OnToward_NO_CHANGE:
default:
break;
}
}
void LeanOrder::on_book_update(const bts::orderman::BookUpdateEvent& book)
{
switch (this_state().status())
@@ -122,12 +149,7 @@ void LeanOrder::on_book_update(const bts::orderman::BookUpdateEvent& book)
{
const auto& opposite = book.book.side(api::Side::SIDE_SELL)[0];
if(opposite.price() < me->opposite_at_inception.price())
{
if(me->detach_on_toward)
detach();
else
me->opposite_at_inception = opposite; //we don't want to detach so look at next level
}
choose_trade_toward_behavior(opposite);
else if(opposite.price() > me->opposite_at_inception.price())
payup(opposite, book); //you missed, payup/join
else
@@ -140,12 +162,7 @@ void LeanOrder::on_book_update(const bts::orderman::BookUpdateEvent& book)
{
const auto& opposite = book.book.side(api::Side::SIDE_BUY)[0];
if(opposite.price() > me->opposite_at_inception.price())
{
if(me->detach_on_toward)
detach();
else
me->opposite_at_inception = opposite;
}
choose_trade_toward_behavior(opposite);
else if(opposite.price() < me->opposite_at_inception.price())
paydown(opposite, book);
else
@@ -26,6 +26,7 @@ protected:
private:
void payup(const md::PriceSize& opposite, const bts::orderman::BookUpdateEvent&, uint32_t cross_ticks = 0) override;
void paydown(const md::PriceSize& opposite, const bts::orderman::BookUpdateEvent&, uint32_t cross_ticks = 0) override;
void choose_trade_toward_behavior(const md::PriceSize& opposite);
private:
struct PImpl;
@@ -80,6 +80,33 @@ void TopOrder::on_book_update(const bts::orderman::BookUpdateEvent& book)
{
case ORDER_STATUS_INACTIVE:
{
Quantity thresh = SpreaderUtils::_quantity_threshold(me->top_threshold, Quantity(this_state().quantity()));
if(definition().side() == api::SIDE_BUY)
{
const auto& same = book.book.side(api::Side::SIDE_BUY)[0];
if(securities::test_price_equality(this_state().price(), same.price(), tick_size()))
{
if(same.size() <= thresh.value())
{
transition(ORDER_STATUS_CANCELED);
report_state();
return;
}
}
}
else
{
const auto& same = book.book.side(api::Side::SIDE_SELL)[0];
if(securities::test_price_equality(this_state().price(), same.price(), tick_size()))
{
if(same.size() <= thresh.value())
{
transition(ORDER_STATUS_CANCELED);
report_state();
return;
}
}
}
activate_child(Price(this_state().price()), Quantity(this_state().quantity()));
transition(ORDER_STATUS_WORKING);
report_state();