ScratchAlgo works

This commit is contained in:
Kevin Darby committed 2019-05-25 23:27:54 -04:00
1 parent 6fc3c0b601
commit ea232fbaf1
3 files changed
+17 -16

No files matched your search

@@ -306,8 +306,7 @@ orderman::OrderOpResult AlgoWrapperOrder::on_cancel() {
// IBeforeLaunchAlgoServices
// --------------------------------------------------------------------------------
api::orderman::OrderDefinition const &AlgoWrapperOrder::definition() const {
//return *def();
return me->definition;
return *def();
}
api::Security const &AlgoWrapperOrder::security() const {
@@ -63,7 +63,8 @@ void ProRataAlgo::check_dynamic(const api::orderman::OrderDefinition& def)
if (def.has_custom_def() && def.custom_def().has_dynamic())
{
//copy
api::orderman::DynamicOrderDefinition dprorata = def.custom_def().dynamic();
api::orderman::DynamicOrderDefinition dprorata;
dprorata.CopyFrom(def.custom_def().dynamic());
auto& mutable_def = const_cast<api::orderman::OrderDefinition&>(def); //TODO Terrible hack
auto& prorata = *mutable_def.mutable_custom_def()->mutable_prorata();
@@ -200,14 +201,12 @@ void ProRataAlgo::check_overfill()
{
auto my_side = algo().definition().side();
auto other_side = securities::other_side(my_side);
Quantity my_quan;
bool found = SpreaderUtils::find_qty_upto_price_level(me->last_book, my_side, algo().price(), /*unused*/ 0.0, my_quan);
auto &my_side_psz = me->last_book.side(my_side)[0];
auto &my_side_psz = me->last_book.side(my_side)[0];
auto &other_side_psz = me->last_book.side(other_side)[0];
bool market_moved = other_side_psz.price() != my_side_psz.price();
if (market_moved || !found || (found && my_quan.value() <= me->stay_in_threshold.value()) )
bool market_moved = !securities::is_same(Price(other_side_psz.price()), Price(me->book_at_inception.side(other_side)[0].price()));
bool on_market = securities::is_same(Price(my_side_psz.price()), Price(algo().price()));
if (market_moved || (on_market && my_side_psz.size() <= me->stay_in_threshold.value()) )
get_out();
}
else
@@ -22,6 +22,7 @@ struct ScratchAlgo::PImpl
ChildTemplate *child_template = nullptr;
Book last_book;
Book book_at_inception;
Quantity total_fills = Quantity(0);
Price scratch_price=Price(os::nan());
};
@@ -33,8 +34,10 @@ void ScratchAlgo::check_dynamic(const api::orderman::OrderDefinition& def)
{
if (def.has_custom_def() && def.custom_def().has_dynamic())
{
//copy
api::orderman::DynamicOrderDefinition dscratch = def.custom_def().dynamic();
api::orderman::DynamicOrderDefinition dscratch;
dscratch.CopyFrom(def.custom_def().dynamic());
auto& mutable_def = const_cast<api::orderman::OrderDefinition&>(def); //TODO Terrible hack
auto& scratch = *mutable_def.mutable_custom_def()->mutable_scratch();
@@ -164,12 +167,11 @@ void ScratchAlgo::try_to_scratch()
auto other_side = securities::other_side(my_side);
Quantity my_quan;
bool found = SpreaderUtils::find_qty_upto_price_level(me->last_book, my_side, algo().price(), /*unused*/ 0.0, my_quan);
auto &my_side_psz = me->last_book.side(my_side)[0];
auto &other_side_psz = me->last_book.side(other_side)[0];
bool market_moved = other_side_psz.price() != my_side_psz.price();
if (market_moved || !found || (found && my_quan.value() <= me->scratch_threshold.value()) )
bool market_moved = !securities::is_same(Price(other_side_psz.price()), Price(me->book_at_inception.side(other_side)[0].price()));
bool on_market = securities::is_same(Price(my_side_psz.price()), Price(algo().price()));
if (market_moved || (on_market && my_side_psz.size() <= me->scratch_threshold.value()) )
{
Price scratch_price;
Quantity scratch_quan;
@@ -182,7 +184,7 @@ void ScratchAlgo::try_to_scratch()
me->scratch_price = scratch_price;
child_update.set_price(scratch_price.value());
//we still want to try to scratch all of it
child_update.set_quantity(algo().quantity().value());
child_update.set_quantity(algo().quantity().value() - me->total_fills.value());
algo().update_child(me->child_key, child_update);
me->status = Status::SCRATCHED;
}
@@ -222,6 +224,7 @@ void ScratchAlgo::update_scratch_threshold()
void ScratchAlgo::on_child_change(OrderKey, ChildState const &st)
{
algo().update_fill_state(st.total_fills, st.last_price);
me->total_fills = st.total_fills;
switch (st.status)
{
case ChildStatus::WORKING: