From a518c37c9ee21d0c8881b777232c8048f7e0d4c8 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Thu, 25 Jun 2015 09:38:31 -0400 Subject: [PATCH] adding wallet api to return the market history --- .../plugins/market_history/market_history_plugin.cpp | 10 +++++++++- libraries/wallet/include/graphene/wallet/wallet.hpp | 2 ++ libraries/wallet/wallet.cpp | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libraries/plugins/market_history/market_history_plugin.cpp b/libraries/plugins/market_history/market_history_plugin.cpp index a4ffc482..b4ad56a1 100644 --- a/libraries/plugins/market_history/market_history_plugin.cpp +++ b/libraries/plugins/market_history/market_history_plugin.cpp @@ -73,6 +73,7 @@ struct operation_process_fill_order void operator()( const fill_order_operation& o )const { + ilog( "processing ${o}", ("o",o) ); const auto& buckets = _plugin.tracked_buckets(); auto& db = _plugin.database(); const auto& bucket_idx = db.get_index_type(); @@ -91,7 +92,10 @@ struct operation_process_fill_order * the base > quote */ if( key.base > key.quote ) + { + ilog( " skipping because base > quote" ); continue; + } price trade_price = o.pays / o.receives; @@ -102,7 +106,7 @@ struct operation_process_fill_order auto itr = by_key_idx.find( key ); if( itr == by_key_idx.end() ) { // create new bucket - db.create( [&]( bucket_object& b ){ + const auto& obj = db.create( [&]( bucket_object& b ){ b.key = key; b.quote_volume += trade_price.quote.amount; b.open_base = trade_price.base.amount; @@ -114,9 +118,11 @@ struct operation_process_fill_order b.low_base = b.close_base; b.low_quote = b.close_quote; }); + wlog( " creating bucket ${b}", ("b",obj) ); } else { // update existing bucket + wlog( " before updating bucket ${b}", ("b",*itr) ); db.modify( *itr, [&]( bucket_object& b ){ b.base_volume += trade_price.base.amount; b.quote_volume += trade_price.quote.amount; @@ -133,6 +139,7 @@ struct operation_process_fill_order b.low_quote = b.close_quote; } }); + wlog( " after bucket bucket ${b}", ("b",*itr) ); } if( max_history != 0 ) @@ -146,6 +153,7 @@ struct operation_process_fill_order itr->key.seconds == bucket && itr->key.open < cutoff ) { + elog( " removing old bucket ${b}", ("b", *itr) ); auto old_itr = itr; ++itr; db.remove( *old_itr ); diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index b2d4ed95..39a22437 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -113,6 +113,7 @@ class wallet_api vector list_account_balances(const string& id); vector list_assets(const string& lowerbound, uint32_t limit)const; vector get_account_history(string name, int limit)const; + vector get_market_history(string symbol, string symbol2, uint32_t bucket)const; vector get_limit_orders(string a, string b, uint32_t limit)const; vector get_call_orders(string a, uint32_t limit)const; vector get_settle_orders(string a, uint32_t limit)const; @@ -362,6 +363,7 @@ FC_API( graphene::wallet::wallet_api, (get_block) (get_account_count) (get_account_history) + (get_market_history) (get_global_properties) (get_dynamic_global_properties) (get_object) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 36c7e9c6..1b0a1699 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1693,6 +1693,11 @@ vector wallet_api::get_account_history(string name, in return my->_remote_hist->get_account_history(get_account(name).get_id(), operation_history_id_type(), limit, operation_history_id_type()); } +vector wallet_api::get_market_history( string symbol1, string symbol2, uint32_t bucket )const +{ + return my->_remote_hist->get_market_history( get_asset_id(symbol1), get_asset_id(symbol2), bucket, fc::time_point_sec(), fc::time_point::now() ); +} + vector wallet_api::get_limit_orders(string a, string b, uint32_t limit)const { return my->_remote_db->get_limit_orders(get_asset(a).id, get_asset(b).id, limit);