Join order works and hedges

This commit is contained in:
Kevin Darby committed 2018-05-26 15:13:13 -04:00
1 parent fc347250e3
commit 86deaf2edb
3 files changed
+34 -6

No files matched your search

@@ -30,7 +30,7 @@ namespace mbts.spark
min_tick_offset_on_deploy = new InlineUserProperty<uint>(0, false);
join_threshold = new InlineUserProperty<bts.spark.QuantityMeasure>(
new bts.spark.QuantityMeasure() { Absolute = 1}, false);
new bts.spark.QuantityMeasure() { Ratio = 1.0, Absolute = 1}, false);
enable_hedge = new InlineUserProperty<bool>(false, false);
hedge_ticks = new InlineUserProperty<int>(1, false);
}
@@ -196,11 +196,13 @@ namespace mbts.spark.utilities {
{
Child = custom_order(),
JoinThreshold = new QuantityMeasure(),
Hedge = custom_order(),
};
public TopOrderDefinition top_order() => new TopOrderDefinition
{
Child = custom_order(),
TopThreshold = new QuantityMeasure(),
Hedge = custom_order(),
};
@@ -88,14 +88,39 @@ void JoinOrder::on_book_update(const bts::orderman::BookUpdateEvent& book)
case ORDER_STATUS_INACTIVE:
{
if(_def.side() == api::SIDE_BUY)
{
me->opposite_at_inception = book.book.side(api::Side::SIDE_SELL)[0];
double max_price = me->opposite_at_inception.price() - _tick_size * me->min_tick_offset_on_deploy;
if(me->min_tick_offset_on_deploy && _state.price() > max_price)
{
LOG(OrderMan, Info, "JoinOrder order {} repricing child {}", key().value(), _child.key().value());
_state.set_price(max_price);
}
else
{
LOG(OrderMan, Info, "JoinOrder order {} launching child {}", key().value(), _child.key().value());
_child.activate(Price(_state.price()), Quantity(_state.quantity()));
_child_state.set_status(ORDER_STATUS_PENDING_WORKING);
transition(ORDER_STATUS_WORKING);
}
}
else
{
me->opposite_at_inception = book.book.side(api::Side::SIDE_BUY)[0];
LOG(OrderMan, Info, "JoinOrder order {} launching child {}", key().value(), _child.key().value());
_child.activate(Price(_state.price()), Quantity(_state.quantity()));
_child_state.set_status(ORDER_STATUS_PENDING_WORKING);
transition(ORDER_STATUS_WORKING);
double min_price = me->opposite_at_inception.price() + _tick_size * me->min_tick_offset_on_deploy;
if(me->min_tick_offset_on_deploy && _state.price() < min_price)
{
LOG(OrderMan, Info, "JoinOrder order {} repricing child {}", key().value(), _child.key().value());
_state.set_price(min_price);
}
else
{
LOG(OrderMan, Info, "JoinOrder order {} launching child {}", key().value(), _child.key().value());
_child.activate(Price(_state.price()), Quantity(_state.quantity()));
_child_state.set_status(ORDER_STATUS_PENDING_WORKING);
transition(ORDER_STATUS_WORKING);
}
}
report_state();
}
break;
@@ -107,6 +132,7 @@ void JoinOrder::on_book_update(const bts::orderman::BookUpdateEvent& book)
const auto& same = book.book.side(api::Side::SIDE_BUY)[0];
if(me->opposite_at_inception.price() > same.price())
{}
//we join exactly once, but we can't detach because we have to hang around and look for hedges
else if(!me->did_join && same.size() >= thresh.value())
{
me->did_join = true;