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

Price comparison weirdness #2127

Closed
jmjatlanta opened this issue Apr 2, 2020 · 2 comments
Closed

Price comparison weirdness #2127

jmjatlanta opened this issue Apr 2, 2020 · 2 comments

Comments

@jmjatlanta
Copy link
Contributor

I am not sure if this is a "feature" or a bug...

I am here talking about the price object and it's operator <

I assume that the price object compares a ratio, and not the actual numbers. But the code indicates that it first compares the instance IDs, and then compares the product of base and quote of the two objects.

Anomaly 1: I would assume that given asset object with the IDs of 1 and 2, the price does not play into it at all. 1 is less than 2, regardless of the price. So to do a legit comparison, you must assure the base and quote of the two are the same. Otherwise you will get an ID comparison and not price.

Anomaly 2: The prices are compared by multiplication instead of ratios. Hence:

      const auto& a = create_bitasset("ASSETA");
      const auto& b = create_bitasset("ASSETB");

      // now compare IDs
      price p1( asset( 100, a.id), asset( 100, b.id) );
      price p2( asset( 100, b.id), asset( 100, a.id) );

      BOOST_CHECK( p1 < p2 ); // checks ids, and sees P1's base ID is less than P2's
      BOOST_CHECK( p2 > p1 ); // the opposite should also be true

      // now compare prices
      price p3( asset( 1, a.id), asset( 2, b.id) );
      price p4( asset( 100, a.id), asset( 200, b.id) );

      // those prices are equal, but it doesn't come out that way
      BOOST_CHECK( p1 < p2 );
      BOOST_CHECK( p2 > p1 );

passes. Even though prices P3 and P4 are in essence equal. Is this a bug, or simply must be kept in mind as an implementation detail?

Perhaps a related tangent: #1094

@abitmore
Copy link
Member

abitmore commented Apr 2, 2020

These lines of code appeared twice in your test case.

      BOOST_CHECK( p1 < p2 );
      BOOST_CHECK( p2 > p1 );

Prices are compared by asset IDs first because we need to index them with by_price tag in databases, to get orders on the same side of a market one by one. So the direction (base vs quote) matters.

@jmjatlanta
Copy link
Contributor Author

Stupid mistake. Thanks.

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

No branches or pull requests

2 participants