BitShares-Core  4.0.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  {
119  };
120 
123 
125  account_id_type funding_account;
128 
129  typedef extension<options_type> extensions_type; // note: this will be jsonified to {...} but no longer [...]
130  extensions_type extensions;
131 
132  account_id_type fee_payer()const { return funding_account; }
133  void validate()const;
134  };
135 
144  {
146 
148  fill_order_operation( object_id_type o, account_id_type a, asset p, asset r, asset f, price fp, bool m )
149  :order_id(o),account_id(a),pays(p),receives(r),fee(f),fill_price(fp),is_maker(m) {}
150 
152  account_id_type account_id;
155  asset fee; // paid by receiving account
157  bool is_maker;
158 
159  pair<asset_id_type,asset_id_type> get_market()const
160  {
161  return pays.asset_id < receives.asset_id ?
162  std::make_pair( pays.asset_id, receives.asset_id ) :
163  std::make_pair( receives.asset_id, pays.asset_id );
164  }
165  account_id_type fee_payer()const { return account_id; }
166  void validate()const { FC_ASSERT( !"virtual operation" ); }
167 
169  share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
170  };
171 
179  {
182 
184  account_id_type bidder;
188 
189  account_id_type fee_payer()const { return bidder; }
190  void validate()const;
191  };
192 
200  {
202 
204  execute_bid_operation( account_id_type a, asset d, asset c )
205  : bidder(a), debt(d), collateral(c) {}
206 
207  account_id_type bidder;
211 
212  account_id_type fee_payer()const { return bidder; }
213  void validate()const { FC_ASSERT( !"virtual operation" ); }
214 
216  share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
217  };
218 } } // graphene::protocol
219 
226 
228 
231 FC_REFLECT( graphene::protocol::call_order_update_operation, (fee)(funding_account)(delta_collateral)(delta_debt)(extensions) )
232 FC_REFLECT( graphene::protocol::fill_order_operation, (fee)(order_id)(account_id)(pays)(receives)(fill_price)(is_maker) )
233 FC_REFLECT( graphene::protocol::bid_collateral_operation, (fee)(bidder)(additional_collateral)(debt_covered)(extensions) )
234 FC_REFLECT( graphene::protocol::execute_bid_operation, (fee)(bidder)(debt)(collateral) )
235 
future_extensions::flat_set_type extensions_type
Definition: base.hpp:128
asset additional_collateral
the amount of collateral to bid for the debt
Definition: market.hpp:185
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:386
bool fill_or_kill
If this flag is set the entire order must be filled or the operation is rejected. ...
Definition: market.hpp:62
share_type calculate_fee(const fee_parameters_type &k) const
This is a virtual operation; there is no fee.
Definition: market.hpp:216
Definition: api.cpp:56
share_type calculate_fee(const fee_parameters_type &k) const
This is a virtual operation; there is no fee.
Definition: market.hpp:169
account_id_type fee_payer() const
Definition: market.hpp:189
account_id_type bidder
pays fee and additional collateral
Definition: market.hpp:184
pair< asset_id_type, asset_id_type > get_market() const
Definition: market.hpp:65
asset delta_collateral
the amount of collateral to add to the margin position
Definition: market.hpp:126
account_id_type funding_account
pays fee, collateral, and cover
Definition: market.hpp:125
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
account_id_type fee_payer() const
Definition: market.hpp:165
account_id_type fee_payer() const
Definition: market.hpp:212
extension< options_type > extensions_type
Definition: market.hpp:129
optional< uint16_t > target_collateral_ratio
maximum CR to maintain when selling collateral on margin call
Definition: market.hpp:118
static time_point_sec maximum()
Definition: time.hpp:86
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
The price struct stores asset prices in the BitShares system.
Definition: asset.hpp:114
#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
pair< asset_id_type, asset_id_type > get_market() const
Definition: market.hpp:159
asset delta_debt
the amount of the debt to be paid off, may be negative to issue new debt
Definition: market.hpp:127
asset_id_type asset_id
Definition: asset.hpp:39
execute_bid_operation(account_id_type a, asset d, asset c)
Definition: market.hpp:204
fill_order_operation(object_id_type o, account_id_type a, asset p, asset r, asset f, price fp, bool m)
Definition: market.hpp:148
asset debt_covered
the amount of debt to take over
Definition: market.hpp:186