Issue #47 market history added to api
This commit is contained in:
parent
03c362b9e4
commit
20a10a074b
6 changed files with 37 additions and 3 deletions
|
|
@ -6,7 +6,7 @@ add_library( graphene_app
|
||||||
plugin.cpp
|
plugin.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries( graphene_app graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities )
|
target_link_libraries( graphene_app graphene_market_history graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities )
|
||||||
target_include_directories( graphene_app
|
target_include_directories( graphene_app
|
||||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
|
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -445,6 +445,28 @@ namespace graphene { namespace app {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
vector<bucket_object> history_api::get_market_history( asset_id_type a, asset_id_type b, uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end )const
|
||||||
|
{ try {
|
||||||
|
FC_ASSERT(_app.chain_database());
|
||||||
|
const auto& db = *_app.chain_database();
|
||||||
|
vector<bucket_object> result;
|
||||||
|
result.reserve(100);
|
||||||
|
|
||||||
|
if( a > b ) std::swap(a,b);
|
||||||
|
|
||||||
|
const auto& bidx = db.get_index_type<bucket_index>();
|
||||||
|
const auto& by_key_idx = bidx.indices().get<by_key>();
|
||||||
|
|
||||||
|
auto itr = by_key_idx.lower_bound( bucket_key( a, b, bucket_seconds, start ) );
|
||||||
|
while( itr != by_key_idx.end() && itr->key.open <= end && result.size() < 100 )
|
||||||
|
{
|
||||||
|
if( !(itr->key.base == a && itr->key.quote == b && itr->key.seconds == bucket_seconds) )
|
||||||
|
return result;
|
||||||
|
result.push_back(*itr);
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (a)(b)(bucket_seconds)(start)(end) ) }
|
||||||
|
|
||||||
/** TODO: add secondary index that will accelerate this process */
|
/** TODO: add secondary index that will accelerate this process */
|
||||||
vector<proposal_object> database_api::get_proposed_transactions( account_id_type id )const
|
vector<proposal_object> database_api::get_proposed_transactions( account_id_type id )const
|
||||||
|
|
@ -464,4 +486,5 @@ namespace graphene { namespace app {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} } // graphene::app
|
} } // graphene::app
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,14 @@
|
||||||
#include <graphene/chain/proposal_object.hpp>
|
#include <graphene/chain/proposal_object.hpp>
|
||||||
#include <graphene/net/node.hpp>
|
#include <graphene/net/node.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
#include <graphene/market_history/market_history_plugin.hpp>
|
||||||
|
|
||||||
#include <fc/api.hpp>
|
#include <fc/api.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace app {
|
namespace graphene { namespace app {
|
||||||
using namespace graphene::chain;
|
using namespace graphene::chain;
|
||||||
|
using namespace graphene::market_history;
|
||||||
|
|
||||||
class application;
|
class application;
|
||||||
|
|
||||||
|
|
@ -270,6 +274,7 @@ namespace graphene { namespace app {
|
||||||
int limit = 100,
|
int limit = 100,
|
||||||
operation_history_id_type start = operation_history_id_type())const;
|
operation_history_id_type start = operation_history_id_type())const;
|
||||||
|
|
||||||
|
vector<bucket_object> get_market_history( asset_id_type a, asset_id_type b, uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end )const;
|
||||||
private:
|
private:
|
||||||
application& _app;
|
application& _app;
|
||||||
};
|
};
|
||||||
|
|
@ -372,7 +377,7 @@ FC_API(graphene::app::database_api,
|
||||||
(get_transaction_hex)
|
(get_transaction_hex)
|
||||||
(get_proposed_transactions)
|
(get_proposed_transactions)
|
||||||
)
|
)
|
||||||
FC_API(graphene::app::history_api, (get_account_history))
|
FC_API(graphene::app::history_api, (get_account_history)(get_market_history))
|
||||||
FC_API(graphene::app::network_api, (broadcast_transaction)(add_node)(get_connected_peers))
|
FC_API(graphene::app::network_api, (broadcast_transaction)(add_node)(get_connected_peers))
|
||||||
FC_API(graphene::app::login_api,
|
FC_API(graphene::app::login_api,
|
||||||
(login)
|
(login)
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,10 @@ namespace bpo = boost::program_options;
|
||||||
|
|
||||||
struct bucket_key
|
struct bucket_key
|
||||||
{
|
{
|
||||||
|
bucket_key( asset_id_type a, asset_id_type b, uint32_t s, fc::time_point_sec o )
|
||||||
|
:base(a),quote(b),seconds(s),open(o){}
|
||||||
|
bucket_key(){}
|
||||||
|
|
||||||
asset_id_type base;
|
asset_id_type base;
|
||||||
asset_id_type quote;
|
asset_id_type quote;
|
||||||
uint32_t seconds = 0;
|
uint32_t seconds = 0;
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,4 @@ endif()
|
||||||
#endif()
|
#endif()
|
||||||
|
|
||||||
target_link_libraries( witness_node
|
target_link_libraries( witness_node
|
||||||
PRIVATE graphene_app graphene_account_history graphene_witness graphene_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )
|
PRIVATE graphene_app graphene_account_history graphene_market_history graphene_witness graphene_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include <graphene/witness/witness.hpp>
|
#include <graphene/witness/witness.hpp>
|
||||||
#include <graphene/account_history/account_history_plugin.hpp>
|
#include <graphene/account_history/account_history_plugin.hpp>
|
||||||
|
#include <graphene/market_history/market_history_plugin.hpp>
|
||||||
|
|
||||||
#include <fc/thread/thread.hpp>
|
#include <fc/thread/thread.hpp>
|
||||||
#include <fc/interprocess/signals.hpp>
|
#include <fc/interprocess/signals.hpp>
|
||||||
|
|
@ -49,6 +50,7 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
auto witness_plug = node.register_plugin<witness_plugin::witness_plugin>();
|
auto witness_plug = node.register_plugin<witness_plugin::witness_plugin>();
|
||||||
auto history_plug = node.register_plugin<account_history::account_history_plugin>();
|
auto history_plug = node.register_plugin<account_history::account_history_plugin>();
|
||||||
|
auto market_history_plug = node.register_plugin<market_history::market_history_plugin>();
|
||||||
|
|
||||||
{
|
{
|
||||||
bpo::options_description cli, cfg;
|
bpo::options_description cli, cfg;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue