Added order streams to api.

This commit is contained in:
Pedro Pinto committed 2017-10-02 21:30:44 +00:00
1 parent 726e42850d
commit 9a10089ea9
3 files changed
+27 -7

No files matched your search

+17 -6
View File
@@ -70,8 +70,19 @@ int TestOrderman::execute(std::vector<std::string> const &)
OrderServiceServer server(ctx);
api::orderman::OrderService client(ctx.locate<api::orderman::OrderService> ());
client.subscribe_orders().subscribe([](const api::orderman::OrdersUpdate &update) {
for (auto const &os : update.added())
std::cout << utils::pb::to_string(*os);
for (auto const &os : update.removed())
std::cout << "Removed: " << os->order_key() << "\n";
});
while (true) {
std::cout << "create order: c sec_key b/s price quantity\nupdate order: u price quantity\ncancel order: x\nchange current order: o order_key\n";
std::cout <<
"create order: c sec_key b/s price quantity\n"
"update order: u price quantity\n"
"cancel order: x\nchange current order: o order_key\n";
char choice;
std::cin >> choice;
switch (choice) {
@@ -79,9 +90,9 @@ int TestOrderman::execute(std::vector<std::string> const &)
uint32_t sec_key;char side; double price; int quantity;
std::cin >> sec_key >> side >> price >> quantity;
auto resp = client.create_order(make_create_request(SecurityKey(sec_key),
side == 'b' ? api::BUY : api::SELL,
Price(price),
Quantity(quantity)));
side == 'b' ? api::BUY : api::SELL,
Price(price),
Quantity(quantity)));
if (resp.success()) {
current_order = OrderKey(resp.result()->order_key());
std::cout << utils::pb::to_string(*resp.result()) << "\n";
@@ -94,8 +105,8 @@ int TestOrderman::execute(std::vector<std::string> const &)
double price; int quantity;
std::cin >> price >> quantity;
auto resp = client.update_order(make_update_request(current_order,
Price(price),
Quantity(quantity)));
Price(price),
Quantity(quantity)));
if (resp.success())
std::cout << utils::pb::to_string(*resp.result()) << "\n";
else
@@ -28,3 +28,4 @@ private:
};
}}
@@ -35,6 +35,7 @@
#include "lib/api/public/ServiceContext.h"
#include "server/sparkd/event_grid/events/Init.h"
#include "lib/utils/PBUtils.h"
#include "lib/logging/logging.h"
namespace bts {
namespace orderman {
@@ -181,9 +182,14 @@ struct SlowExecutor {
node.observe<event::ExecutionReport> ([this] (const auto &ev) {fill_recorder.on(ev);});
node.observe<event_grid::event::Init> ([this] (const auto &ev) {fill_recorder.on(ev);});
// order storage
// order storage
node.observe<event::NativeOrderStateChange> ([this] (const auto &ev) {order_recorder.on(ev);});
node.observe<event_grid::event::Init> ([this] (const auto &ev) {order_recorder.on(ev);});
// order PB publication
order_recorder.order_state_change_signal = [this] (const auto &ev) { node.send<event::OrderStateChange>(ev);};
// fill PB publication
fill_recorder.native_fill_signal = [this] (const auto &ev) { node.send<event::NativeFills>(ev);};
}
~SlowExecutor()
@@ -266,6 +272,7 @@ OrderServiceServer::OrderServiceServer (bts::api::ServiceContext& ctx)
me->slow.node.observe<event::OrderStateChange> ([&ctx,this] (auto const&os) {
ctx.post([this,os] () {
LOG(OrderMan,Info,"Post Received order update for publishing");
this->on_order_updates(os);
});
});
@@ -311,6 +318,7 @@ void OrderServiceServer::on_fills(event::NativeFills const&f)
void OrderServiceServer::on_order_updates(event::OrderStateChange const&os)
{
LOG(OrderMan,Info,"Received order update for publishing");
std::vector<api::orderman::OrderState> created;
created.reserve(os.state.size());
std::vector<api::orderman::OrderState> updated;