diff --git a/libraries/app/api_objects.cpp b/libraries/app/api_objects.cpp index a9be85244c..49d911189c 100644 --- a/libraries/app/api_objects.cpp +++ b/libraries/app/api_objects.cpp @@ -27,6 +27,30 @@ namespace graphene { namespace app { +order::order( const string& _price, + const string& _quote, + const string& _base, + const limit_order_id_type& _id, + const account_id_type& _oid, + const string& _oname, + const time_point_sec& _exp ) +: price( _price ), + quote( _quote ), + base( _base ), + id( _id ), + owner_id( _oid ), + owner_name( _oname ), + expiration( _exp ) +{ + // Nothing to do +} + +order_book::order_book( const string& _base, const string& _quote ) +: base( _base ), quote( _quote ) +{ + // Do nothing else +} + market_ticker::market_ticker(const market_ticker_object& mto, const fc::time_point_sec& now, const asset_object& asset_base, diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index e474075fef..6aab692409 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -1417,9 +1417,7 @@ order_book database_api_impl::get_order_book( const string& base, const string& "limit can not be greater than ${configured_limit}", ("configured_limit", configured_limit) ); - order_book result; - result.base = base; - result.quote = quote; + order_book result( base, quote ); auto assets = lookup_asset_symbols( {base, quote} ); FC_ASSERT( assets[0], "Invalid base asset symbol: ${s}", ("s",base) ); @@ -1431,25 +1429,24 @@ order_book database_api_impl::get_order_book( const string& base, const string& for( const auto& o : orders ) { + auto order_price = price_to_string( o.sell_price, *assets[0], *assets[1] ); if( o.sell_price.base.asset_id == base_id ) { - order ord; - ord.price = price_to_string( o.sell_price, *assets[0], *assets[1] ); - ord.quote = assets[1]->amount_to_string( share_type( fc::uint128_t( o.for_sale.value ) + auto quote_amt = assets[1]->amount_to_string( share_type( fc::uint128_t( o.for_sale.value ) * o.sell_price.quote.amount.value / o.sell_price.base.amount.value ) ); - ord.base = assets[0]->amount_to_string( o.for_sale ); - result.bids.push_back( ord ); + auto base_amt = assets[0]->amount_to_string( o.for_sale ); + result.bids.emplace_back( order_price, quote_amt, base_amt, o.id, + o.seller, o.seller(_db).name, o.expiration ); } else { - order ord; - ord.price = price_to_string( o.sell_price, *assets[0], *assets[1] ); - ord.quote = assets[1]->amount_to_string( o.for_sale ); - ord.base = assets[0]->amount_to_string( share_type( fc::uint128_t( o.for_sale.value ) + auto quote_amt = assets[1]->amount_to_string( o.for_sale ); + auto base_amt = assets[0]->amount_to_string( share_type( fc::uint128_t( o.for_sale.value ) * o.sell_price.quote.amount.value / o.sell_price.base.amount.value ) ); - result.asks.push_back( ord ); + result.asks.emplace_back( order_price, quote_amt, base_amt, o.id, + o.seller, o.seller(_db).name, o.expiration ); } } diff --git a/libraries/app/include/graphene/app/api_objects.hpp b/libraries/app/include/graphene/app/api_objects.hpp index 328fd0b946..6e77291fb8 100644 --- a/libraries/app/include/graphene/app/api_objects.hpp +++ b/libraries/app/include/graphene/app/api_objects.hpp @@ -84,6 +84,19 @@ namespace graphene { namespace app { string price; string quote; string base; + limit_order_id_type id; + account_id_type owner_id; + string owner_name; + time_point_sec expiration; + + order() = default; + order( const string& _price, + const string& _quote, + const string& _base, + const limit_order_id_type& _id, + const account_id_type& _oid, + const string& _oname, + const time_point_sec& _exp ); }; struct order_book @@ -92,6 +105,8 @@ namespace graphene { namespace app { string quote; vector< order > bids; vector< order > asks; + order_book() = default; + order_book( const string& _base, const string& _quote ); }; struct market_ticker @@ -191,7 +206,7 @@ FC_REFLECT( graphene::app::full_account, (more_data_available) ) -FC_REFLECT( graphene::app::order, (price)(quote)(base) ) +FC_REFLECT( graphene::app::order, (price)(quote)(base)(id)(owner_id)(owner_name)(expiration) ) FC_REFLECT( graphene::app::order_book, (base)(quote)(bids)(asks) ) FC_REFLECT( graphene::app::market_ticker, (time)(base)(quote)(latest)(lowest_ask)(lowest_ask_base_size)(lowest_ask_quote_size) diff --git a/tests/tests/api_limit_tests.cpp b/tests/tests/api_limit_tests.cpp index c2bc8db184..3dd518cf9c 100644 --- a/tests/tests/api_limit_tests.cpp +++ b/tests/tests/api_limit_tests.cpp @@ -215,7 +215,7 @@ BOOST_AUTO_TEST_CASE( api_limit_get_settle_orders ){ } } BOOST_AUTO_TEST_CASE( api_limit_get_order_book ){ - try{ + try { graphene::app::database_api db_api( db, &( app.get_options() )); auto nathan_private_key = generate_private_key("nathan"); auto dan_private_key = generate_private_key("dan"); @@ -223,21 +223,26 @@ BOOST_AUTO_TEST_CASE( api_limit_get_order_book ){ account_id_type dan_id = create_account("dan", dan_private_key.get_public_key()).id; transfer(account_id_type(), nathan_id, asset(100)); transfer(account_id_type(), dan_id, asset(100)); - asset_id_type bitusd_id = create_bitasset( - "USDBIT", nathan_id, 100, disable_force_settle).id; - asset_id_type bitdan_id = create_bitasset( - "DANBIT", dan_id, 100, disable_force_settle).id; + asset_id_type bitusd_id = create_user_issued_asset( "USDBIT", nathan_id(db), charge_market_fee).id; + asset_id_type bitdan_id = create_user_issued_asset( "DANBIT", dan_id(db), charge_market_fee).id; + issue_uia( nathan_id, asset(100, bitusd_id) ); + issue_uia( dan_id, asset(100, bitdan_id) ); + create_sell_order( nathan_id, asset(100, bitusd_id), asset(10000, bitdan_id) ); + create_sell_order( dan_id, asset(100, bitdan_id), asset(10000, bitusd_id) ); generate_block(); fc::usleep(fc::milliseconds(100)); GRAPHENE_CHECK_THROW(db_api.get_order_book(std::string(static_cast(bitusd_id)), std::string(static_cast(bitdan_id)),89), fc::exception); graphene::app::order_book result =db_api.get_order_book(std::string( static_cast(bitusd_id)), std::string(static_cast(bitdan_id)),78); - BOOST_REQUIRE_EQUAL( result.bids.size(), 0u); - }catch (fc::exception& e) { + BOOST_REQUIRE_EQUAL( result.bids.size(), 1u ); + BOOST_CHECK( result.bids.front().owner_name == "nathan" ); + BOOST_REQUIRE_EQUAL( result.asks.size(), 1u ); + BOOST_CHECK( result.asks.front().owner_name == "dan" ); + } catch (fc::exception& e) { edump((e.to_detail_string())); throw; - } + } } BOOST_AUTO_TEST_CASE( api_limit_lookup_accounts ) {