Update type of extensions field of limit_order_create_operation struct, add an on_fill field inside, so that traders can setup automatic actions which will trigger when the order is fully filled or partially filled.
/**
* Creates a take profit limit order
*/
struct create_take_profit_order_action
{
/// Asset ID that will be used to pay operation fee for placing the take profit order
asset_id_type fee_asset_id;
/// A percentage indicating how far the price of the take profit order
/// differs from the original order
uint16_t spread_percent = 0;
/// A percentage indicating how much amount to sell in the take profit order
uint16_t size_percent = GRAPHENE_100_PERCENT;
/// How long the take profit order to be kept on the market
uint32_t expiration_seconds = 0;
/// Whether to create another take profit order for this take profit order if
/// this take profit order is matched
bool repeat = false;
extensions_type extensions; ///< Unused. Reserved for future use.
void validate()const;
};
/// Automatic actions for limit orders
using limit_order_auto_action = static_variant< create_take_profit_order_action >;
struct limit_order_create_operation : public base_operation
{
struct options_type
{
/// Automatic actions when the limit order is filled or partially filled
optional< vector< limit_order_auto_action > > on_fill;
};
asset fee;
account_id_type seller;
asset amount_to_sell;
asset min_to_receive;
time_point_sec expiration = time_point_sec::maximum();
bool fill_or_kill = false;
using extensions_type = extension<options_type>; // note: will be jsonified to {...}
extensions_type extensions;
};
Add an on_fill field in limit_order_update_operation struct, so that traders can add, update or remove automatic actions which will trigger when the order is fully filled or partially filled.
struct limit_order_update_operation : public base_operation
{
asset fee;
account_id_type seller;
limit_order_id_type order;
optional<price> new_price;
optional<asset> delta_amount_to_sell;
optional<time_point_sec> new_expiration;
/// Automatic actions when the limit order is filled or partially filled
optional< vector< limit_order_auto_action > > on_fill;
extensions_type extensions;
};
Add an on_fill field and a take_profit_order_id field in limit_order_object to store related data
class limit_order_object : public abstract_object<limit_order_object, protocol_ids, limit_order_object_type>
{
public:
time_point_sec expiration;
account_id_type seller;
share_type for_sale; ///< asset id is sell_price.base.asset_id
price sell_price;
share_type deferred_fee; ///< fee converted to CORE
asset deferred_paid_fee; ///< originally paid fee
bool is_settled_debt = false; ///< Whether this order is an individual settlement fund
/// Automatic actions when the limit order is filled or partially filled
vector< limit_order_auto_action > on_fill;
/// ID of the take profit limit order linked to this limit order
optional<limit_order_id_type> take_profit_order_id;
};
NOTE:
Automatic actions pay normal operation fees to create and update orders.
Automatic actions may not be performed in some cases, E.G. insufficient account balance or asset fee pool balance to pay operation fees, or asset authorization limits, etc. But this does not prevent the order itself from being filled.
PR for #2535.
Changes:
Update type of
extensions
field oflimit_order_create_operation
struct, add anon_fill
field inside, so that traders can setup automatic actions which will trigger when the order is fully filled or partially filled.Add an
on_fill
field inlimit_order_update_operation
struct, so that traders can add, update or remove automatic actions which will trigger when the order is fully filled or partially filled.Add an
on_fill
field and atake_profit_order_id
field inlimit_order_object
to store related dataNOTE: