Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Order-Sends-Take-Profit-Order feature #2749

Merged
merged 6 commits into from
Jun 19, 2023
Merged

Conversation

abitmore
Copy link
Member

@abitmore abitmore commented Jun 13, 2023

PR for #2535.

Changes:

  • 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.

@sonarcloud
Copy link

sonarcloud bot commented Jun 17, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

87.3% 87.3% Coverage
0.0% 0.0% Duplication

@abitmore abitmore merged commit 9a36b7c into hardfork Jun 19, 2023
@abitmore abitmore deleted the pr-2535-oso branch June 19, 2023 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant