-
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
Conversation
libraries/app/database_api.cpp
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Calling get_ticker
directly is inefficient, since it will query the database again for same data. We already have itr
here so just need to get the data. I recommend that we move the code in get_ticket
to a new static function and call it in both get_ticker
and here.
libraries/app/database_api.cpp
Outdated
@@ -244,6 +244,57 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl> | |||
graphene::chain::database& _db; | |||
const application_options* _app_options = nullptr; | |||
|
|||
static market_ticker get_ticker_data(const market_ticker_object mto, |
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.
- Actually this is not a typical
getter
function, more suitable as a constructor ofmarket_ticker
class/struct. - Please use constant references as parameters.
- better to use
optional
for order book.
libraries/app/database_api.cpp
Outdated
const auto orders = get_order_book( base, quote, 1 ); | ||
if( !orders.asks.empty() ) result.lowest_ask = orders.asks[0].price; | ||
if( !orders.bids.empty() ) result.highest_bid = orders.bids[0].price; | ||
mt = market_ticker(*itr, now, *assets[0], *assets[1], orders); |
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 think this should be placed out of if( itr != ticker_idx.end() )
block.
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.
you mean the following outside?
order_book orders;
if( !skip_order_book )
{
orders = get_order_book(assets[0]->symbol, assets[1]->symbol, 1);
}
i saw you have that outside the if
in the original code inside get_ticker
.
or you mean this outside?
mt = market_ticker(*itr, now, *assets[0], *assets[1], orders);
sorry, not fully clear this time with the github inline code comment. pls clarify so i can make the proper changes. thanks!
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.
Yes, as original code, both should be outside.
by human eye we can quickly see there are only a limited number of base currencies which matter in terms of top markets by real volume; namely BTS, bitCNY, bitUSD, OPEN.BTC, USDT, GDEX.BTC; perhaps a few others. I think best way to sort out "spam" and get a true sense of "top markets by volume" would be to first only consider volume vs one of the whitelisted base coins. then convert all volume to a common base amongst the whitelist; eg I believe BTS trades to each of those mentioned. then API returns sorted list of markets that has been normalized to "relative" BTS volume as additional base currencies become relevant they could then be added to the whitelist in future development |
@litepresence thanks for the discussion. Firstly we need to define UI/UX appropriately including logic, then decide what should be done by UI and what be done by the back end. So, actually this discussion especially your comments should be started in the UI project/respository. |
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.
Note: I haven't finished the review so far.
libraries/app/database_api.cpp
Outdated
|
||
order_book orders; |
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.
Should use optional<order_book>
here.
libraries/app/database_api.cpp
Outdated
|
||
result.base_volume = uint128_amount_to_string( base_volume, assets[0]->precision ); | ||
result.quote_volume = uint128_amount_to_string( quote_volume, assets[1]->precision ); | ||
if( itr == ticker_idx.end() ) return mt; |
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 should not return.
Actually should change mt
to optional
as well.
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 recommend NOT change behavior of existing API's. That said, don't return null
if was returning an empty object.
you are right, reversed those changes. |
} | ||
|
||
return result; | ||
return mt; |
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.
Need to include order data if skip_order_book is false, even when no ticker data.
That's why I said to change mt
to optional
, actually it was a typo, I meant to use a local variable which is optional
type or is a pointer, to store *itr
(skip if it's end()
), then construct mt
with it.
|
||
while( itr != volume_idx.rend() && result.size() < limit) | ||
{ | ||
market_volume mv; | ||
mv.time = now; | ||
const auto assets = get_assets( { itr->base, itr->quote } ); |
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.
I have 2 cents from bitshares-qt standpoint. First of all, the Secondly, I think it would be great, if the API could be expanded to allow setting base asset. Say, a user is interested in trading OPEN.BTC -- I want to show top OPEN.BTC markets. The current behavior (listing everything) is also extremely useful, so I'm not proposing to replace it. Sorry if this is the wrong ticket, which only deals with the return format. |
I too want to leave something here for reference, but don't want to write a feature request yet: |
for issue #842 api call now returning market_ticker object data.