-
Notifications
You must be signed in to change notification settings - Fork 649
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
#463, Add API to query for open orders of one account in one market #849
Changes from all commits
0d1d389
205d389
466e150
fca8cbf
352817f
a102db8
8f41ab0
4c1fd77
59b5b1b
ec7ef61
1e0c369
50b6d62
7e67682
a5077e8
fc0fc1d
cbc4d05
7f18c59
5ff8fea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,12 +104,19 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl> | |
|
||
// Markets / feeds | ||
vector<limit_order_object> get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const; | ||
vector<limit_order_object> get_account_limit_orders( const string& name_or_id, | ||
const string &base, | ||
const string "e, uint32_t limit, | ||
optional<limit_order_id_type> ostart_id, | ||
optional<price> ostart_price ); | ||
vector<call_order_object> get_call_orders(asset_id_type a, uint32_t limit)const; | ||
vector<force_settlement_object> get_settle_orders(asset_id_type a, uint32_t limit)const; | ||
vector<call_order_object> get_margin_positions( const std::string account_id_or_name )const; | ||
vector<collateral_bid_object> get_collateral_bids(const asset_id_type asset, uint32_t limit, uint32_t start)const; | ||
|
||
void subscribe_to_market(std::function<void(const variant&)> callback, asset_id_type a, asset_id_type b); | ||
void unsubscribe_from_market(asset_id_type a, asset_id_type b); | ||
|
||
market_ticker get_ticker( const string& base, const string& quote, bool skip_order_book = false )const; | ||
market_volume get_24_volume( const string& base, const string& quote )const; | ||
order_book get_order_book( const string& base, const string& quote, unsigned limit = 50 )const; | ||
|
@@ -655,6 +662,101 @@ vector<optional<account_object>> database_api_impl::get_accounts(const vector<st | |
return result; | ||
} | ||
|
||
vector<limit_order_object> database_api::get_account_limit_orders( const string& name_or_id, const string &base, | ||
const string "e, uint32_t limit, optional<limit_order_id_type> ostart_id, optional<price> ostart_price) | ||
{ | ||
return my->get_account_limit_orders( name_or_id, base, quote, limit, ostart_id, ostart_price ); | ||
} | ||
|
||
vector<limit_order_object> database_api_impl::get_account_limit_orders( const string& name_or_id, const string &base, | ||
const string "e, uint32_t limit, optional<limit_order_id_type> ostart_id, optional<price> ostart_price) | ||
{ | ||
FC_ASSERT( limit <= 101 ); | ||
|
||
vector<limit_order_object> results; | ||
const account_object* account = nullptr; | ||
uint32_t count = 0; | ||
|
||
if (std::isdigit(name_or_id[0])) | ||
account = _db.find(fc::variant(name_or_id, 1).as<account_id_type>(1)); | ||
else | ||
{ | ||
const auto& idx = _db.get_index_type<account_index>().indices().get<by_name>(); | ||
auto itr = idx.find(name_or_id); | ||
if (itr != idx.end()) | ||
account = &*itr; | ||
} | ||
if (account == nullptr) | ||
return results; | ||
|
||
auto assets = lookup_asset_symbols( {base, quote} ); | ||
FC_ASSERT( assets[0], "Invalid base asset symbol: ${s}", ("s",base) ); | ||
FC_ASSERT( assets[1], "Invalid quote asset symbol: ${s}", ("s",quote) ); | ||
|
||
auto base_id = assets[0]->id; | ||
auto quote_id = assets[1]->id; | ||
|
||
if (ostart_price.valid()) { | ||
FC_ASSERT(ostart_price->base.asset_id == base_id, "Base asset inconsistent with start price"); | ||
FC_ASSERT(ostart_price->quote.asset_id == quote_id, "Quote asset inconsistent with start price"); | ||
} | ||
|
||
const auto& index_by_account = _db.get_index_type<limit_order_index>().indices().get<by_account>(); | ||
limit_order_multi_index_type::index<by_account>::type::const_iterator lower_itr; | ||
limit_order_multi_index_type::index<by_account>::type::const_iterator upper_itr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually Update: actually it's better to initialize it after the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. has initialize |
||
|
||
// if both order_id and price are invalid, query the first page | ||
if ( !ostart_id.valid() && !ostart_price.valid() ) | ||
{ | ||
lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, price::max(base_id, quote_id))); | ||
} | ||
else if ( ostart_id.valid() ) | ||
{ | ||
// in case of the order been deleted during page querying | ||
const limit_order_object *p_loo = _db.find(*ostart_id); | ||
|
||
if ( !p_loo ) | ||
{ | ||
if ( ostart_price.valid() ) | ||
{ | ||
lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, *ostart_price, *ostart_id)); | ||
} | ||
else | ||
{ | ||
// start order id been deleted, yet not provided price either | ||
FC_THROW("Order id invalid (maybe just been canceled?), and start price not provided"); | ||
} | ||
} | ||
else | ||
{ | ||
const limit_order_object &loo = *p_loo; | ||
|
||
// in case of the order not belongs to specified account or market | ||
FC_ASSERT(loo.sell_price.base.asset_id == base_id, "Order base asset inconsistent"); | ||
FC_ASSERT(loo.sell_price.quote.asset_id == quote_id, "Order quote asset inconsistent with order"); | ||
FC_ASSERT(loo.seller == account->get_id(), "Order not owned by specified account"); | ||
|
||
lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, loo.sell_price, *ostart_id)); | ||
} | ||
} | ||
else | ||
{ | ||
// if reach here start_price must be valid | ||
lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, *ostart_price)); | ||
} | ||
|
||
upper_itr = index_by_account.upper_bound(std::make_tuple(account->id, price::min(base_id, quote_id))); | ||
|
||
// Add the account's orders | ||
for ( ; lower_itr != upper_itr && count < limit; ++lower_itr, ++count) | ||
{ | ||
const limit_order_object &order = *lower_itr; | ||
results.emplace_back(order); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
std::map<string,full_account> database_api::get_full_accounts( const vector<string>& names_or_ids, bool subscribe ) | ||
{ | ||
return my->get_full_accounts( names_or_ids, subscribe ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the best place to check whether the start price is consistent with
base
andquote
parameters. If not, IMHO best to throw out an exception.