gui for haris orders
This commit is contained in:
1 parent
e1f590127e
commit
c8c6aea188
9 files changed
+163
-4
No files matched your search
@@ -71,6 +71,7 @@ namespace mbts.spark {
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveOrderDef: param.AsOrderDef = new CustomOrderDefinition(); break;
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveString: param.AsString = string.Empty; break;
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveUint: param.AsUint32 = 0u; break;
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveQuantity: param.AsQuantity = new bts.spark.QuantityMeasure(); break;
|
||||
}
|
||||
break;
|
||||
case DynamicOrderTypeDescriptor.DescriptorOneofCase.Structure: param.AsStruct = new DynamicOrderStruct(); break;
|
||||
@@ -87,5 +88,21 @@ namespace mbts.spark {
|
||||
}
|
||||
param.AsEnumerated.EnumValue = value ?? string.Empty;
|
||||
}
|
||||
|
||||
internal static bts.spark.QuantityMeasureImmutable? get_quantity_value(DynamicOrderParam param)
|
||||
{
|
||||
return new bts.spark.QuantityMeasureImmutable(param?.AsQuantity);
|
||||
}
|
||||
internal static void set_quantity_value(DynamicOrderParam param, bts.spark.QuantityMeasureImmutable? value)
|
||||
{
|
||||
if (param == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (param.ValueCase != DynamicOrderParam.ValueOneofCase.AsQuantity)
|
||||
{
|
||||
param.AsQuantity = value?.CloneToMutable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using bts.api.orderman;
|
||||
using Google.Protobuf.Reflection;
|
||||
using mbts.ui.shell;
|
||||
using bts.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -116,4 +117,41 @@ namespace mbts.spark {
|
||||
void _sync_elements() =>
|
||||
elements.sync_with(_get_elements(descriptor));
|
||||
}
|
||||
|
||||
|
||||
class DynamicOrderQuantityVM : DynamicOrderParamVM, IDynamicOrderParamVM<QuantityMeasureImmutable?>
|
||||
{
|
||||
static readonly FieldDescriptor _field_desc = DynamicOrderParam.Descriptor.FindFieldByNumber(DynamicOrderParam.AsQuantityFieldNumber);
|
||||
QuantityMeasureImmutable? _value;
|
||||
public DynamicOrderQuantityVM(DynamicOrderParamDescriptor descriptor)
|
||||
: base(descriptor)
|
||||
{
|
||||
}
|
||||
|
||||
public QuantityMeasureImmutable? value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
_value = value;
|
||||
_field_desc.Accessor.SetValue(param, _value?.CloneToMutable());
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public IObservable<QuantityMeasureImmutable?> subscribe_value() =>
|
||||
Observable.Create<QuantityMeasureImmutable?>(o =>
|
||||
{
|
||||
PropertyChanged += on_prop_changed;
|
||||
return Disposable.Create(() => PropertyChanged -= on_prop_changed);
|
||||
void on_prop_changed(object sender, PropertyChangedEventArgs e) =>
|
||||
o.OnNext(value);
|
||||
});
|
||||
|
||||
protected override void on_param_changed()
|
||||
{
|
||||
_value = new QuantityMeasureImmutable( (QuantityMeasure) _field_desc.Accessor.GetValue(param));
|
||||
RaisePropertyChanged(nameof(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using mbts.collections;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using bts.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -73,6 +74,11 @@ namespace mbts.spark {
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveInt: return mk<uint?, uint>(DynamicOrderParam.AsInt32FieldNumber, v => v, v => v.GetValueOrDefault());
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveUint: return mk<uint?, uint>(DynamicOrderParam.AsUint32FieldNumber, v => v, v => v.GetValueOrDefault());
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveString: return mk<string, string>(DynamicOrderParam.AsStringFieldNumber, v => v, v => v);
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveQuantity:
|
||||
{
|
||||
var qm = new DynamicOrderQuantityVM(descriptor);
|
||||
return attached(qm, DynamicOrderHelper.get_quantity_value, DynamicOrderHelper.set_quantity_value, new QuantityMeasureImmutable(new QuantityMeasure { Ratio = 1.0, Absolute = 1 }));
|
||||
}
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(descriptor.ParamType.Primitive, nameof(descriptor));
|
||||
}
|
||||
case DynamicOrderTypeDescriptor.DescriptorOneofCase.Enumerated:
|
||||
|
||||
@@ -563,6 +563,7 @@ enum DynamicOrderPrimitiveDescriptor {
|
||||
DYNAMIC_ORDER_PRIMITIVE_STRING = 3;
|
||||
DYNAMIC_ORDER_PRIMITIVE_BOOL = 4;
|
||||
DYNAMIC_ORDER_PRIMITIVE_ORDER_DEF = 5;
|
||||
DYNAMIC_ORDER_PRIMITIVE_QUANTITY = 6;
|
||||
}
|
||||
|
||||
message DynamicOrderTypeDescriptor {
|
||||
@@ -611,6 +612,7 @@ message DynamicOrderParam {
|
||||
DynamicOrderArray as_array = 7;
|
||||
DynamicOrderStruct as_struct = 8;
|
||||
DynamicOrderEnumerated as_enumerated = 9;
|
||||
spark.QuantityMeasure as_quantity = 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,31 @@ ProRataAlgo::ProRataAlgo() : me(new PImpl()) {}
|
||||
ProRataAlgo::~ProRataAlgo() {}
|
||||
IAlgoServices &ProRataAlgo::algo() const { return *me->algo; }
|
||||
|
||||
void ProRataAlgo::check_dynamic(const api::orderman::OrderDefinition& def)
|
||||
{
|
||||
if (def.has_custom_def() && def.custom_def().has_dynamic())
|
||||
{
|
||||
auto& dprorata = 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();
|
||||
|
||||
if(dprorata.order_params().count("hedge_ticks") > 0)
|
||||
prorata.set_hedge_ticks(dprorata.order_params().at("hedge_ticks").as_uint32());
|
||||
if(dprorata.order_params().count("fill_limit") > 0)
|
||||
*prorata.mutable_fill_limit() = dprorata.order_params().at("fill_limit").as_quantity();
|
||||
if(dprorata.order_params().count("stay_in_threshold") > 0)
|
||||
*prorata.mutable_stay_in_threshold() = dprorata.order_params().at("stay_in_threshold").as_quantity();
|
||||
if(dprorata.order_params().count("enable_scratch_on_overfill") > 0)
|
||||
prorata.set_enable_scratch_on_overfill(dprorata.order_params().at("enable_scratch_on_overfill").as_bool());
|
||||
if(dprorata.order_params().count("enable_stay_in") > 0)
|
||||
prorata.set_enable_stay_in(dprorata.order_params().at("enable_stay_in").as_bool());
|
||||
|
||||
*prorata.mutable_child() = dprorata.order_params().at("child").as_order_def();
|
||||
*prorata.mutable_hedge() = dprorata.order_params().at("hedge").as_order_def();
|
||||
*prorata.mutable_overfill_hedge() = dprorata.order_params().at("overfill_hedge").as_order_def();
|
||||
}
|
||||
}
|
||||
|
||||
OrderOpResult ProRataAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
|
||||
{
|
||||
auto &def = serv.definition();
|
||||
|
||||
@@ -32,6 +32,7 @@ private:
|
||||
void check_overfill();
|
||||
void check_terminate();
|
||||
const char *status_name(Status st);
|
||||
void check_dynamic(const api::orderman::OrderDefinition&);
|
||||
};
|
||||
|
||||
} // namespace orderman
|
||||
|
||||
@@ -29,12 +29,27 @@ ScratchAlgo::ScratchAlgo() : me(new PImpl()) {}
|
||||
ScratchAlgo::~ScratchAlgo() {}
|
||||
IAlgoServices &ScratchAlgo::algo() const { return *me->algo; }
|
||||
|
||||
void ScratchAlgo::check_dynamic(const api::orderman::OrderDefinition& def)
|
||||
{
|
||||
if (def.has_custom_def() && def.custom_def().has_dynamic())
|
||||
{
|
||||
auto& dscratch = 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();
|
||||
|
||||
if(dscratch.order_params().count("scratch_threshold") > 0)
|
||||
*scratch.mutable_scratch_threshold() = dscratch.order_params().at("scratch_threshold").as_quantity();
|
||||
|
||||
*scratch.mutable_child() = dscratch.order_params().at("child").as_order_def();
|
||||
}
|
||||
}
|
||||
|
||||
OrderOpResult ScratchAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
|
||||
{
|
||||
auto &def = serv.definition();
|
||||
const api::orderman::OrderDefinition& def = serv.definition();
|
||||
check_dynamic(def);
|
||||
bts_assert(def.has_custom_def());
|
||||
bts_assert(def.custom_def().has_scratch());
|
||||
|
||||
// Validate the scratch part of the definition
|
||||
auto &scratch = def.custom_def().scratch();
|
||||
if (!scratch.has_child() && OrderKey(def.attach_target_order_key()) == null_order_key())
|
||||
|
||||
@@ -27,10 +27,10 @@ private:
|
||||
std::unique_ptr<PImpl> me;
|
||||
|
||||
IAlgoServices &algo() const ;
|
||||
void update_scratch_threshold();
|
||||
bool has_running_child() const;
|
||||
void update_scratch_threshold();
|
||||
void try_to_scratch();
|
||||
Price get_price_to_pass (Price price) const;
|
||||
void check_dynamic(const api::orderman::OrderDefinition&);
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -34,6 +34,10 @@
|
||||
#include "server/sparkd/user/AdminServiceServer.h"
|
||||
#include "server/sparkd/user/AuthServiceServer.h"
|
||||
#include "server/sparkd/algo/AlgoDefinitionServiceServer.h"
|
||||
|
||||
#include "lib/orderman/orders/algo/algo_orders/ScratchAlgo.h"
|
||||
#include "lib/orderman/orders/algo/algo_orders/ProRataAlgo.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
namespace bts {
|
||||
@@ -76,6 +80,57 @@ int Run::execute(std::vector<std::string> const &) {
|
||||
SparkServices plugin_services(dyn_order_registry);
|
||||
plugin::init_plugins(plugin_services);
|
||||
// finished initializing order plugins
|
||||
|
||||
//TODO these will go away once Haris approves algo
|
||||
using namespace api::orderman;
|
||||
{
|
||||
DynamicOrderDescriptor desc;
|
||||
desc.set_dynamic_order_type("Scratch");
|
||||
auto param = desc.add_param_desc();
|
||||
param->set_param_name("scratch_threshold");
|
||||
param->mutable_param_type()->set_primitive(DYNAMIC_ORDER_PRIMITIVE_QUANTITY);
|
||||
|
||||
param = desc.add_param_desc();
|
||||
param->set_param_name("child");
|
||||
param->mutable_param_type()->set_primitive(DYNAMIC_ORDER_PRIMITIVE_ORDER_DEF);
|
||||
plugin_services.register_dynamic_algo_order(
|
||||
desc, []() { return std::make_unique<orderman::ScratchAlgo>(); });
|
||||
}
|
||||
|
||||
{
|
||||
DynamicOrderDescriptor desc;
|
||||
desc.set_dynamic_order_type("ProRata");
|
||||
auto param = desc.add_param_desc();
|
||||
param->set_param_name("hedge_ticks");
|
||||
param->mutable_param_type()->set_primitive(DYNAMIC_ORDER_PRIMITIVE_UINT);
|
||||
param = desc.add_param_desc();
|
||||
param->set_param_name("fill_limit");
|
||||
param->mutable_param_type()->set_primitive(DYNAMIC_ORDER_PRIMITIVE_QUANTITY);
|
||||
|
||||
param = desc.add_param_desc();
|
||||
param->set_param_name("stay_in_threshold");
|
||||
param->mutable_param_type()->set_primitive(DYNAMIC_ORDER_PRIMITIVE_QUANTITY);
|
||||
param = desc.add_param_desc();
|
||||
param->set_param_name("enable_scratch_on_overfill");
|
||||
param->mutable_param_type()->set_primitive(DYNAMIC_ORDER_PRIMITIVE_BOOL);
|
||||
param = desc.add_param_desc();
|
||||
param->set_param_name("enable_stay_in");
|
||||
param->mutable_param_type()->set_primitive(DYNAMIC_ORDER_PRIMITIVE_BOOL);
|
||||
|
||||
param = desc.add_param_desc();
|
||||
param->set_param_name("child");
|
||||
param->mutable_param_type()->set_primitive(DYNAMIC_ORDER_PRIMITIVE_ORDER_DEF);
|
||||
param = desc.add_param_desc();
|
||||
param->set_param_name("hedge");
|
||||
param->mutable_param_type()->set_primitive(DYNAMIC_ORDER_PRIMITIVE_ORDER_DEF);
|
||||
param = desc.add_param_desc();
|
||||
param->set_param_name("overfill_hedge");
|
||||
param->mutable_param_type()->set_primitive(DYNAMIC_ORDER_PRIMITIVE_ORDER_DEF);
|
||||
|
||||
|
||||
plugin_services.register_dynamic_algo_order(
|
||||
desc, []() { return std::make_unique<orderman::ProRataAlgo>(); });
|
||||
}
|
||||
|
||||
orderman::OrderServiceServer order_service_server(
|
||||
sc, mdclient, dyn_order_registry, stats, perf_log);
|
||||
|
||||
Reference in new issue
Block a user