Skip to content
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
wants to merge 7 commits into from
Closed

Conversation

oxarbitrage
Copy link
Member

@oxarbitrage oxarbitrage commented May 14, 2018

for issue #842 api call now returning market_ticker object data.

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 );
Copy link
Member

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.

@@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Actually this is not a typical getter function, more suitable as a constructor of market_ticker class/struct.
  2. Please use constant references as parameters.
  3. better to use optional for order book.

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);
Copy link
Member

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.

Copy link
Member Author

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!

Copy link
Member

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.

@abitmore abitmore modified the milestones: 201806 - Non-Consensus-Changing Release, 201807 - Next Non-Consensus-Changing Release May 21, 2018
@abitmore abitmore self-requested a review May 23, 2018 09:06
@abitmore abitmore self-assigned this May 23, 2018
@litepresence
Copy link
Contributor

litepresence commented May 23, 2018

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

@abitmore
Copy link
Member

abitmore commented May 25, 2018

@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.

Copy link
Member

@abitmore abitmore left a 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.


order_book orders;
Copy link
Member

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.


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;
Copy link
Member

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.

Copy link
Member

@abitmore abitmore left a 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.

@oxarbitrage
Copy link
Member Author

you are right, reversed those changes.

}

return result;
return mt;
Copy link
Member

@abitmore abitmore May 28, 2018

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 } );
Copy link
Member

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.

@ryanRfox ryanRfox requested review from jmjatlanta and pmconrad June 14, 2018 15:03
@abitmore abitmore removed the request for review from jmjatlanta July 21, 2018 20:14
@jhtitor
Copy link

jhtitor commented Jul 26, 2018

I have 2 cents from bitshares-qt standpoint.

First of all, the get_top_markets API itself is a great idea, and I'm really glad we finally have such a feature. Going to use it extensively.

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.

@abitmore
Copy link
Member

I too want to leave something here for reference, but don't want to write a feature request yet:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants