Skip to content

Commit ad23d58

Browse files
committed
Change market API's to return more data, bitshares#448
* get_trade_history returns sequence * get_ticker returns current time
1 parent 4124f5f commit ad23d58

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

libraries/app/database_api.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@ market_ticker database_api_impl::get_ticker( const string& base, const string& q
11631163
const fc::time_point_sec yesterday = fc::time_point_sec( now.sec_since_epoch() - 86400 );
11641164

11651165
market_ticker result;
1166+
result.time = now;
11661167
result.base = base;
11671168
result.quote = quote;
11681169
result.latest = 0;
@@ -1364,6 +1365,7 @@ vector<market_trade> database_api_impl::get_trade_history( const string& base,
13641365
start = fc::time_point_sec( fc::time_point::now() );
13651366

13661367
uint32_t count = 0;
1368+
uint32_t skipped = 0;
13671369
auto itr = history_idx.lower_bound( hkey );
13681370
vector<market_trade> result;
13691371

@@ -1388,7 +1390,10 @@ vector<market_trade> database_api_impl::get_trade_history( const string& base,
13881390
trade.price = price_to_real( itr->op.fill_price );
13891391

13901392
if( itr->op.is_maker )
1393+
{
1394+
trade.sequence = -itr->key.sequence;
13911395
trade.side1_account_id = itr->op.account_id;
1396+
}
13921397
else
13931398
trade.side2_account_id = itr->op.account_id;
13941399

@@ -1398,7 +1403,10 @@ vector<market_trade> database_api_impl::get_trade_history( const string& base,
13981403
&& next_itr->time == itr->time && next_itr->op.is_maker != itr->op.is_maker )
13991404
{ // next_itr now could be the other direction // FIXME not 100% sure
14001405
if( next_itr->op.is_maker )
1406+
{
1407+
trade.sequence = -next_itr->key.sequence;
14011408
trade.side1_account_id = next_itr->op.account_id;
1409+
}
14021410
else
14031411
trade.side2_account_id = next_itr->op.account_id;
14041412
// skip the other direction
@@ -1408,6 +1416,12 @@ vector<market_trade> database_api_impl::get_trade_history( const string& base,
14081416
result.push_back( trade );
14091417
++count;
14101418
}
1419+
else // should skip
1420+
{
1421+
// TODO refuse to execute if need to skip too many entries
1422+
// ++skipped;
1423+
// FC_ASSERT( skipped <= 200 );
1424+
}
14111425

14121426
++itr;
14131427
}

libraries/app/include/graphene/app/database_api.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ struct order_book
8181

8282
struct market_ticker
8383
{
84+
time_point_sec time;
8485
string base;
8586
string quote;
8687
double latest;
@@ -101,6 +102,7 @@ struct market_volume
101102

102103
struct market_trade
103104
{
105+
int64_t sequence = 0;
104106
fc::time_point_sec date;
105107
double price;
106108
double amount;
@@ -613,9 +615,10 @@ class database_api
613615

614616
FC_REFLECT( graphene::app::order, (price)(quote)(base) );
615617
FC_REFLECT( graphene::app::order_book, (base)(quote)(bids)(asks) );
616-
FC_REFLECT( graphene::app::market_ticker, (base)(quote)(latest)(lowest_ask)(highest_bid)(percent_change)(base_volume)(quote_volume) );
618+
FC_REFLECT( graphene::app::market_ticker,
619+
(time)(base)(quote)(latest)(lowest_ask)(highest_bid)(percent_change)(base_volume)(quote_volume) );
617620
FC_REFLECT( graphene::app::market_volume, (base)(quote)(base_volume)(quote_volume) );
618-
FC_REFLECT( graphene::app::market_trade, (date)(price)(amount)(value)(side1_account_id)(side2_account_id) );
621+
FC_REFLECT( graphene::app::market_trade, (sequence)(date)(price)(amount)(value)(side1_account_id)(side2_account_id) );
619622

620623
FC_API(graphene::app::database_api,
621624
// Objects

0 commit comments

Comments
 (0)