BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
market.hpp
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  */
24 #pragma once
27 
28 namespace graphene { namespace protocol {
29 
49  {
51 
53  account_id_type seller;
56 
60 
62  bool fill_or_kill = false;
64 
65  pair<asset_id_type,asset_id_type> get_market()const
66  {
67  return amount_to_sell.asset_id < min_to_receive.asset_id ?
68  std::make_pair(amount_to_sell.asset_id, min_to_receive.asset_id) :
69  std::make_pair(min_to_receive.asset_id, amount_to_sell.asset_id);
70  }
71  account_id_type fee_payer()const { return seller; }
72  void validate()const;
73  price get_price()const { return amount_to_sell / min_to_receive; }
74  };
75 
84  {
85  struct fee_parameters_type { uint64_t fee = 0; };
86 
88  limit_order_id_type order;
90  account_id_type fee_paying_account;
92 
93  account_id_type fee_payer()const { return fee_paying_account; }
94  void validate()const;
95  };
96 
110  {
117  {
120  };
121 
124 
126  account_id_type funding_account;
129 
130  typedef extension<options_type> extensions_type; // note: this will be jsonified to {...} but no longer [...]
131  extensions_type extensions;
132 
133  account_id_type fee_payer()const { return funding_account; }
134  void validate()const;
135  };
136 
145  {
147 
149  fill_order_operation( object_id_type o, account_id_type a, asset p, asset r, asset f, price fp, bool m )
150  :order_id(o),account_id(a),pays(p),receives(r),fee(f),fill_price(fp),is_maker(m) {}
151 
153  account_id_type account_id;
156  asset fee; // paid by receiving account
158  bool is_maker = true;
159 
160  pair<asset_id_type,asset_id_type> get_market()const
161  {
162  return pays.asset_id < receives.asset_id ?
163  std::make_pair( pays.asset_id, receives.asset_id ) :
164  std::make_pair( receives.asset_id, pays.asset_id );
165  }
166  account_id_type fee_payer()const { return account_id; }
167  void validate()const { FC_ASSERT( !"virtual operation" ); }
168 
170  share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
171  };
172 
180  {
183 
185  account_id_type bidder;
189 
190  account_id_type fee_payer()const { return bidder; }
191  void validate()const;
192  };
193 
201  {
203 
205  execute_bid_operation( account_id_type a, asset d, asset c )
206  : bidder(a), debt(d), collateral(c) {}
207 
208  account_id_type bidder;
212 
213  account_id_type fee_payer()const { return bidder; }
214  void validate()const { FC_ASSERT( !"virtual operation" ); }
215 
217  share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
218  };
219 } } // graphene::protocol
220 
227 
229 
233  (fee)(fee_paying_account)(order)(extensions) )
235  (fee)(funding_account)(delta_collateral)(delta_debt)(extensions) )
237  (fee)(order_id)(account_id)(pays)(receives)(fill_price)(is_maker) )
239  (fee)(bidder)(additional_collateral)(debt_covered)(extensions) )
241  (fee)(bidder)(debt)(collateral) )
242 
future_extensions::flat_set_type extensions_type
Definition: base.hpp:156
asset additional_collateral
the amount of collateral to bid for the debt
Definition: market.hpp:186
share_type calculate_fee(const fee_parameters_type &k) const
This is a virtual operation; there is no fee.
Definition: market.hpp:170
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:388
bool fill_or_kill
If this flag is set the entire order must be filled or the operation is rejected. ...
Definition: market.hpp:62
pair< asset_id_type, asset_id_type > get_market() const
Definition: market.hpp:65
account_id_type fee_payer() const
Definition: market.hpp:166
Definition: api.cpp:48
account_id_type bidder
pays fee and additional collateral
Definition: market.hpp:185
asset delta_collateral
the amount of collateral to add to the margin position
Definition: market.hpp:127
account_id_type funding_account
pays fee, collateral, and cover
Definition: market.hpp:126
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
extension< options_type > extensions_type
Definition: market.hpp:130
optional< uint16_t > target_collateral_ratio
Maximum CR to maintain when selling collateral on margin call.
Definition: market.hpp:119
static time_point_sec maximum()
Definition: time.hpp:86
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
The price struct stores asset prices in the BitShares system.
Definition: asset.hpp:108
#define GRAPHENE_BLOCKCHAIN_PRECISION
Definition: config.hpp:29
instructs the blockchain to attempt to sell one asset for anotherThe blockchain will atempt to sell a...
Definition: market.hpp:48
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
account_id_type fee_payer() const
Definition: market.hpp:213
asset delta_debt
the amount of the debt to be paid off, may be negative to issue new debt
Definition: market.hpp:128
asset_id_type asset_id
Definition: asset.hpp:37
execute_bid_operation(account_id_type a, asset d, asset c)
Definition: market.hpp:205
pair< asset_id_type, asset_id_type > get_market() const
Definition: market.hpp:160
fill_order_operation(object_id_type o, account_id_type a, asset p, asset r, asset f, price fp, bool m)
Definition: market.hpp:149
asset debt_covered
the amount of debt to take over
Definition: market.hpp:187
share_type calculate_fee(const fee_parameters_type &k) const
This is a virtual operation; there is no fee.
Definition: market.hpp:217