BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
market.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
25 
26 #include <fc/io/raw.hpp>
27 
28 namespace graphene { namespace protocol {
29 
31 {
32  FC_ASSERT( spread_percent > 0, "The spread percentage must be positive" );
33  FC_ASSERT( size_percent > 0, "The size percentage must be positive" );
34  FC_ASSERT( size_percent <= GRAPHENE_100_PERCENT, "The size percentage must not exceed 100%" );
35  FC_ASSERT( expiration_seconds > 0, "The expiration seconds must be positive" );
36 }
37 
39 {
40  using result_type = void;
41 
42  template<typename ActionType>
43  result_type operator()( const ActionType& action )const
44  {
45  action.validate();
46  }
47 };
48 
50 {
52  FC_ASSERT( fee.amount >= 0 );
55 
56  if( extensions.value.on_fill.valid() )
57  {
58  // Note: an empty on_fill action list is allowed
59  for( const auto& action : *extensions.value.on_fill )
60  action.visit( lo_action_validate_visitor() );
61  }
62 
63 }
64 
66 { try {
67  FC_ASSERT(fee.amount >= 0, "Fee must not be negative");
69  "Cannot update limit order if nothing is specified to update");
70  if (new_price)
71  new_price->validate();
73  FC_ASSERT(delta_amount_to_sell->amount != 0, "Cannot change limit order amount by zero");
74 
75  if( on_fill.valid() )
76  {
77  // Note: an empty on_fill action list is allowed
78  for( const auto& action : *on_fill )
79  action.visit( lo_action_validate_visitor() );
80  }
81 
82 } FC_CAPTURE_AND_RETHROW((*this)) } // GCOVR_EXCL_LINE
83 
85 {
86  FC_ASSERT( fee.amount >= 0 );
87 }
88 
90 { try {
91  FC_ASSERT( fee.amount >= 0 );
94 
95  // note: no validation is needed for extensions so far: the only attribute inside is target_collateral_ratio
96 
97 } FC_CAPTURE_AND_RETHROW((*this)) } // GCOVR_EXCL_LINE
98 
100 { try {
101  FC_ASSERT( fee.amount >= 0 );
103 } FC_CAPTURE_AND_RETHROW((*this)) } // GCOVR_EXCL_LINE
104 
105 } } // graphene::protocol
106 
108 
111 
117 
FC_CAPTURE_AND_RETHROW
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:479
graphene::protocol::limit_order_update_operation::new_price
optional< price > new_price
Definition: market.hpp:126
graphene::protocol::execute_bid_operation
Definition: market.hpp:262
graphene::protocol::call_order_update_operation::delta_debt
asset delta_debt
the amount of the debt to be paid off, may be negative to issue new debt
Definition: market.hpp:190
graphene::protocol::limit_order_create_operation::amount_to_sell
asset amount_to_sell
Definition: market.hpp:89
graphene::protocol::fill_order_operation
Definition: market.hpp:206
graphene::protocol::bid_collateral_operation
Definition: market.hpp:241
graphene::protocol::create_take_profit_order_action
Definition: market.hpp:33
graphene::protocol::call_order_update_operation::validate
void validate() const
Definition: market.cpp:89
graphene::protocol::limit_order_cancel_operation::validate
void validate() const
Definition: market.cpp:84
graphene::protocol::limit_order_create_operation::fee_params_t
Definition: market.hpp:85
graphene::protocol::lo_action_validate_visitor
Definition: market.cpp:38
graphene::protocol::call_order_update_operation::fee
asset fee
Definition: market.hpp:187
graphene::protocol::limit_order_create_operation::options_type
Definition: market.hpp:79
graphene::protocol::limit_order_update_operation::on_fill
optional< vector< limit_order_auto_action > > on_fill
Automatic actions when the limit order is filled or partially filled.
Definition: market.hpp:130
graphene::protocol::bid_collateral_operation::debt_covered
asset debt_covered
the amount of debt to take over
Definition: market.hpp:249
graphene::protocol::call_order_update_operation::delta_collateral
asset delta_collateral
the amount of collateral to add to the margin position
Definition: market.hpp:189
graphene::protocol::bid_collateral_operation::additional_collateral
asset additional_collateral
the amount of collateral to bid for the debt
Definition: market.hpp:248
graphene::protocol::limit_order_update_operation::fee
asset fee
Definition: market.hpp:123
GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION
#define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:86
graphene::protocol::bid_collateral_operation::fee_params_t
Definition: market.hpp:244
graphene::protocol::lo_action_validate_visitor::operator()
result_type operator()(const ActionType &action) const
Definition: market.cpp:43
graphene::protocol::limit_order_update_operation::new_expiration
optional< time_point_sec > new_expiration
Definition: market.hpp:128
graphene::protocol::lo_action_validate_visitor::result_type
void result_type
Definition: market.cpp:40
graphene::protocol::limit_order_create_operation::extensions
extensions_type extensions
Definition: market.hpp:100
graphene::protocol::bid_collateral_operation::validate
void validate() const
Definition: market.cpp:99
graphene::protocol::call_order_update_operation
Definition: market.hpp:171
graphene::protocol::limit_order_update_operation
Definition: market.hpp:117
graphene::protocol::create_take_profit_order_action::size_percent
uint16_t size_percent
A percentage indicating how much amount to sell in the take profit order.
Definition: market.hpp:40
graphene::protocol::asset::asset_id
asset_id_type asset_id
Definition: asset.hpp:37
graphene::protocol::call_order_update_operation::fee_params_t
Definition: market.hpp:185
graphene::protocol::limit_order_cancel_operation::fee_params_t
Definition: market.hpp:147
graphene::protocol::create_take_profit_order_action::expiration_seconds
uint32_t expiration_seconds
How long the take profit order to be kept on the market.
Definition: market.hpp:42
graphene::protocol::limit_order_create_operation::validate
void validate() const
Definition: market.cpp:49
graphene::protocol::limit_order_cancel_operation
Definition: market.hpp:145
graphene::protocol::limit_order_create_operation::min_to_receive
asset min_to_receive
Definition: market.hpp:90
graphene::protocol::create_take_profit_order_action::spread_percent
uint16_t spread_percent
A percentage indicating how far the price of the take profit order differs from the original order.
Definition: market.hpp:38
graphene::protocol::limit_order_create_operation::fee
asset fee
Definition: market.hpp:87
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
graphene::protocol::create_take_profit_order_action::validate
void validate() const
Definition: market.cpp:30
graphene::protocol::limit_order_cancel_operation::fee
asset fee
Definition: market.hpp:149
graphene::protocol::asset::amount
share_type amount
Definition: asset.hpp:36
graphene::protocol::call_order_update_operation::options_type
Definition: market.hpp:178
market.hpp
graphene::protocol::limit_order_update_operation::fee_params_t
Definition: market.hpp:119
graphene::protocol::bid_collateral_operation::fee
asset fee
Definition: market.hpp:246
graphene::protocol::limit_order_create_operation
instructs the blockchain to attempt to sell one asset for another
Definition: market.hpp:72
graphene::protocol::limit_order_create_operation::options_type::on_fill
optional< vector< limit_order_auto_action > > on_fill
Automatic actions when the limit order is filled or partially filled.
Definition: market.hpp:82
graphene::protocol::limit_order_update_operation::delta_amount_to_sell
optional< asset > delta_amount_to_sell
Definition: market.hpp:127
GRAPHENE_100_PERCENT
#define GRAPHENE_100_PERCENT
Definition: config.hpp:102
graphene
Definition: api.cpp:48
graphene::protocol::limit_order_update_operation::validate
void validate() const override
Definition: market.cpp:65
graphene::protocol::extension::value
T value
Definition: ext.hpp:40
raw.hpp