-
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
expand get_top_markets #924
Closed
+77
−61
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a83cbd5
expand get_top_markets
oxarbitrage 2635cab
create initial get_ticker_data()
oxarbitrage c09bd0c
move get_ticker_data to constructor
oxarbitrage ee53019
move some code outside if
oxarbitrage 444c970
change order_book to optional
oxarbitrage 46ffa19
add more optionals, fix empty volume
oxarbitrage be0e0c5
reverse optional in production calls
oxarbitrage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,7 +112,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl> | |
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; | ||
vector<market_volume> get_top_markets(uint32_t limit)const; | ||
vector<market_ticker> get_top_markets(uint32_t limit)const; | ||
vector<market_trade> get_trade_history( const string& base, const string& quote, fc::time_point_sec start, fc::time_point_sec stop, unsigned limit = 100 )const; | ||
vector<market_trade> get_trade_history_by_sequence( const string& base, const string& quote, int64_t start, fc::time_point_sec stop, unsigned limit = 100 )const; | ||
|
||
|
@@ -1308,34 +1308,30 @@ order_book database_api_impl::get_order_book( const string& base, const string& | |
return result; | ||
} | ||
|
||
vector<market_volume> database_api::get_top_markets(uint32_t limit)const | ||
vector<market_ticker> database_api::get_top_markets(uint32_t limit)const | ||
{ | ||
return my->get_top_markets(limit); | ||
} | ||
|
||
vector<market_volume> database_api_impl::get_top_markets(uint32_t limit)const | ||
vector<market_ticker> database_api_impl::get_top_markets(uint32_t limit)const | ||
{ | ||
FC_ASSERT( _app_options && _app_options->has_market_history_plugin, "Market history plugin is not enabled." ); | ||
|
||
FC_ASSERT( limit <= 100 ); | ||
|
||
const auto& volume_idx = _db.get_index_type<graphene::market_history::market_ticker_index>().indices().get<by_volume>(); | ||
auto itr = volume_idx.rbegin(); | ||
vector<market_volume> result; | ||
vector<market_ticker> result; | ||
result.reserve(limit); | ||
|
||
const fc::time_point_sec now = fc::time_point::now(); | ||
const fc::time_point_sec now = _db.head_block_time(); | ||
|
||
while( itr != volume_idx.rend() && result.size() < limit) | ||
{ | ||
market_volume mv; | ||
mv.time = now; | ||
const auto assets = get_assets( { itr->base, itr->quote } ); | ||
mv.base = assets[0]->symbol; | ||
mv.quote = assets[1]->symbol; | ||
mv.base_volume = uint128_amount_to_string( itr->base_volume, assets[0]->precision ); | ||
mv.quote_volume = uint128_amount_to_string( itr->quote_volume, assets[1]->precision ); | ||
result.emplace_back( std::move(mv) ); | ||
market_ticker mt = get_ticker( assets[0]->symbol, assets[1]->symbol, true ); | ||
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. Calling |
||
|
||
result.emplace_back( std::move(mt) ); | ||
++itr; | ||
} | ||
return result; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'd suggest that we use a small local cache in this
get_top_markets
function to reduce quantity of queries to the database.