Skip to content

Commit

Permalink
add limit order objects
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Feb 12, 2018
1 parent fe4e87b commit fddf08d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
28 changes: 27 additions & 1 deletion libraries/plugins/es_objects/es_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <graphene/chain/proposal_object.hpp>
#include <boost/algorithm/string/join.hpp>
#include <graphene/chain/balance_object.hpp>
#include <graphene/chain/market_object.hpp>


namespace graphene { namespace es_objects {
Expand Down Expand Up @@ -65,6 +66,7 @@ class es_objects_plugin_impl
bool _es_objects_accounts = true;
bool _es_objects_assets = true;
bool _es_objects_balances = true;
bool _es_objects_limit_orders = true;
bool _es_objects_logs = true;
CURL *curl; // curl handler
vector <string> bulk;
Expand All @@ -73,6 +75,7 @@ class es_objects_plugin_impl
void PrepareAccount(const account_object* account_object);
void PrepareAsset(const asset_object* asset_object);
void PrepareBalance(const balance_object* balance_object);
void PrepareLimit(const limit_order_object* limit_object);
void SendBulk();
void createBulk(std::string type, std::string data, std::string id);
};
Expand Down Expand Up @@ -120,6 +123,12 @@ void es_objects_plugin_impl::updateDatabase( const vector<object_id_type>& ids ,
if(b != nullptr)
PrepareBalance(b);
}
else if(value.is<limit_order_object>() && _es_objects_limit_orders) {
auto obj = db.find_object(value);
auto l = static_cast<const limit_order_object*>(obj);
if(l != nullptr)
PrepareLimit(l);
}
}
}

Expand Down Expand Up @@ -259,6 +268,19 @@ void es_objects_plugin_impl::PrepareBalance(const balance_object* balance_object
createBulk("balance", data, fc::json::to_string(balance_object->owner));
}

void es_objects_plugin_impl::PrepareLimit(const limit_order_object* limit_object)
{
limit_order_struct limit;
limit.expiration = limit_object->expiration;
limit.seller = limit_object->seller;
limit.for_sale = limit_object->for_sale;
limit.sell_price = limit_object->sell_price;
limit.deferred_fee = limit_object->deferred_fee;

std::string data = fc::json::to_string(limit);
createBulk("limitorder", data, fc::json::to_string(limit_object->id));
}

es_objects_plugin_impl::~es_objects_plugin_impl()
{
return;
Expand Down Expand Up @@ -298,7 +320,8 @@ void es_objects_plugin::plugin_set_program_options(
("es-objects-proposals", boost::program_options::value<bool>(), "Store proposal objects")
("es-objects-accounts", boost::program_options::value<bool>(), "Store account objects")
("es-objects-assets", boost::program_options::value<bool>(), "Store asset objects")
("es-objects-balances", boost::program_options::value<bool>(), "Store balances object")
("es-objects-balances", boost::program_options::value<bool>(), "Store balances objects")
("es-objects-limit-orders", boost::program_options::value<bool>(), "Store limit order objects")

;
cfg.add(cli);
Expand Down Expand Up @@ -333,6 +356,9 @@ void es_objects_plugin::plugin_initialize(const boost::program_options::variable
if (options.count("es-objects-balances")) {
my->_es_objects_balances = options["es-objects-balances"].as<bool>();
}
if (options.count("es-objects-limit-orders")) {
my->_es_objects_limit_orders = options["es-objects-limit-orders"].as<bool>();
}
}

void es_objects_plugin::plugin_startup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,19 @@ struct balance_struct {
asset_id_type asset_id;
share_type amount;
};
struct limit_order_struct {
limit_order_id_type id;
time_point_sec expiration;
account_id_type seller;
share_type for_sale;
price sell_price;
share_type deferred_fee;
};

} } //graphene::es_objects

FC_REFLECT( graphene::es_objects::proposal_struct, (id)(expiration_time)(review_period_time)(proposed_transaction)(required_active_approvals)(available_active_approvals)(required_owner_approvals)(available_owner_approvals)(available_key_approvals) )
FC_REFLECT( graphene::es_objects::account_struct, (id)(membership_expiration_date)(registrar)(referrer)(lifetime_referrer)(network_fee_percentage)(lifetime_referrer_fee_percentage)(referrer_rewards_percentage)(name)(owner_account_auths)(owner_key_auths)(owner_address_auths)(active_account_auths)(active_key_auths)(active_address_auths)(voting_account) )
FC_REFLECT( graphene::es_objects::asset_struct, (id)(symbol)(issuer) )
FC_REFLECT( graphene::es_objects::balance_struct, (id)(owner)(asset_id)(amount) )
FC_REFLECT( graphene::es_objects::balance_struct, (id)(owner)(asset_id)(amount) )
FC_REFLECT( graphene::es_objects::limit_order_struct, (id)(expiration)(seller)(for_sale)(sell_price)(deferred_fee) )

0 comments on commit fddf08d

Please sign in to comment.