From 25d4c5428434db29e867db20820ddfcaaeed3609 Mon Sep 17 00:00:00 2001 From: taha afzal Date: Mon, 23 May 2022 11:51:10 -0400 Subject: [PATCH] Added account_id to ExchangePosition --- .../api/service_helpers/AdminServiceUtils.cpp | 19 +++++++++++++++++++ src/lib/api/services/OrderService.proto | 12 +++++++----- src/lib/orderman/OrderServiceServer.cpp | 17 +++++++++++------ .../orderman/gateways/EMExecutionGateway.cpp | 18 +++++++++++++++--- .../orderman_utils/ExchangePosition.h | 3 +++ 5 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/lib/api/service_helpers/AdminServiceUtils.cpp b/src/lib/api/service_helpers/AdminServiceUtils.cpp index 4a437af39..5f55af65c 100644 --- a/src/lib/api/service_helpers/AdminServiceUtils.cpp +++ b/src/lib/api/service_helpers/AdminServiceUtils.cpp @@ -1710,6 +1710,16 @@ void AdminServiceUtils::bootstrap_data(bts::api::admin::AdminData &data) { data, parent_account->id(), std::string("BLUETST"), std::string("description"), true, account_result); account_4->set_is_active(true); + // BTC, ETH accounts + auto account_btc = create_account( + data, parent_account->id(), std::string("ACC_BTC"), + std::string("description"), true, account_result); + account_btc->set_is_active(true); + auto account_eth = create_account( + data, parent_account->id(), std::string("ACC_ETH"), + std::string("description"), true, account_result); + account_eth->set_is_active(true); + // create_account( data, parent_account->id(), std::string("ACC A4"), std::string("description"), true, account_result); @@ -1756,6 +1766,15 @@ void AdminServiceUtils::bootstrap_data(bts::api::admin::AdminData &data) { google::protobuf::MapPair< uint32_t, bts::api::admin::UserAccountPermissionUnit>( account_4->id(), permission_unit)); + account_permissions.mutable_account_permissions()->insert( + google::protobuf::MapPair< + uint32_t, bts::api::admin::UserAccountPermissionUnit>( + account_btc->id(), permission_unit)); + account_permissions.mutable_account_permissions()->insert( + google::protobuf::MapPair< + uint32_t, bts::api::admin::UserAccountPermissionUnit>( + account_eth->id(), permission_unit)); + set_user_accounts(user_1, account_permissions); set_user_accounts(user_2, account_permissions); set_user_accounts(user_3, account_permissions); diff --git a/src/lib/api/services/OrderService.proto b/src/lib/api/services/OrderService.proto index b773e0e5e..cc0429752 100644 --- a/src/lib/api/services/OrderService.proto +++ b/src/lib/api/services/OrderService.proto @@ -715,9 +715,11 @@ message RetrievedExchangePosition{ string record_id = 1 [(bts.api.key)=true]; uint32 security_key = 10; bool security_resolved = 20; - string exchange_desc = 30; - Venue exchange = 40; - string account_name = 50; - double avg_filled_price = 60; - double position = 70; + string account_name = 30; + uint32 account_id = 40; + bool account_resolved = 50; + string exchange_desc = 60; + Venue exchange = 70; + double avg_filled_price = 80; + double position = 90; } \ No newline at end of file diff --git a/src/lib/orderman/OrderServiceServer.cpp b/src/lib/orderman/OrderServiceServer.cpp index 8e5af3865..28f689bdb 100644 --- a/src/lib/orderman/OrderServiceServer.cpp +++ b/src/lib/orderman/OrderServiceServer.cpp @@ -33,6 +33,7 @@ #include "lib/utils/type_name.h" #include +#include namespace bts { namespace orderman { @@ -444,19 +445,23 @@ void OrderServiceServer::_on_exchange_position( ret_pos.set_record_id(id); ret_pos.set_security_key(p.security == nullptr ? 0 : p.security->id()); ret_pos.set_security_resolved(p.security != nullptr); - ret_pos.set_exchange_desc(p.exchange_sec_desc); ret_pos.set_account_name(p.account_name); + ret_pos.set_account_id( + p.account_id == std::nullopt ? 0 : p.account_id.value()); + ret_pos.set_account_resolved(p.account_id != std::nullopt); + ret_pos.set_exchange_desc(p.exchange_sec_desc); + ret_pos.set_exchange(ev.position.exchange); ret_pos.set_avg_filled_price(p.avg_filled_price.value()); ret_pos.set_position(p.position); - ret_pos.set_exchange(ev.position.exchange); me->exchange_pos_publisher.add_or_update(ret_pos); LOG(OrderMan, Info, "OrderServiceServer::_on_exchange_position publishing pos id: {} " - "key: {} res: {} desc: {} exchange: {} account: {} filled_price: {} " - "fills: {}", + "key: {} res: {} account_name: {} account_id: {} account_resolved: " + "{} desc: {} exchange: {} filled_price: {} fills: {}", ret_pos.record_id(), ret_pos.security_key(), - ret_pos.security_resolved(), ret_pos.exchange_desc(), - bts::api::Venue_Name(ret_pos.exchange()), ret_pos.account_name(), + ret_pos.security_resolved(), ret_pos.account_name(), + ret_pos.account_id(), ret_pos.account_resolved(), + ret_pos.exchange_desc(), bts::api::Venue_Name(ret_pos.exchange()), ret_pos.avg_filled_price(), ret_pos.position()); } me->exchange_pos_publisher.flush(); diff --git a/src/lib/orderman/gateways/EMExecutionGateway.cpp b/src/lib/orderman/gateways/EMExecutionGateway.cpp index 1a905c77b..c4f8b8d77 100644 --- a/src/lib/orderman/gateways/EMExecutionGateway.cpp +++ b/src/lib/orderman/gateways/EMExecutionGateway.cpp @@ -1,4 +1,5 @@ #include "EMExecutionGateway.h" +#include "lib/api/service_helpers/AdminServiceUtils.h" #include "lib/api/services/AdminService.pb.h" #include "lib/api/services/OrderService.pb.h" #include "lib/domain_model/Security.pb.h" @@ -24,12 +25,14 @@ #include "server/sparkd/md/platforms/emumba/EmMDListener.h" #include "server/sparkd/md/platforms/emumba/IEMOrderMuxer.h" +#include "lib/api/service_helpers/AdminServiceUtils.h" #include "lib/config/config.h" #include "lib/config/protos/toggles.pb.h" #include "lib/domain_model/Security.h" #include "lib/utils/PBUtils.h" #include "lib/utils/Uuid.h" #include +#include #include #include #include @@ -38,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -467,7 +471,11 @@ void EMExecutionGateway::_process_cb_and_fire_er(const EMCallbackMsg &em_cb) { void EMExecutionGateway::_process_pos_cb_and_fire( const EMExchangePositionCallbackMsg &pos_cb_msg) { auto get_account = [this](api::Security const *sec) { - return me->account_resolver.get_default_account(sec); + auto account_name = me->account_resolver.get_default_account(sec); + auto bts_account_ptr = + admin::AdminServiceUtils::find_account(me->admin_data, account_name); + return std::tuple( + account_name, bts_account_ptr); }; auto get_sec = [this](const auto &exch_sec_desc) { for (auto sec : me->sec_oracle.get_securities()) { @@ -487,9 +495,13 @@ void EMExecutionGateway::_process_pos_cb_and_fire( std::get(pos.sec_id.value()); auto sec = get_sec(exch_sec_desc); double pos_qty = std::get(pos.qty.value()); - std::string account_name = get_account(sec); + auto [account_name, bts_account_ptr] = get_account(sec); + std::optional account_id = + bts_account_ptr == nullptr + ? std::nullopt + : std::optional(bts_account_ptr->id()); me->exchange_position.total_exchange_positions.push_back( - {exch_sec_desc, sec, account_name, pos_qty, + {exch_sec_desc, sec, account_name, account_id, pos_qty, Price(pos.average_price.to_double())}); } LOG(OrderMan, Info, "EMExecutionGateway::_process_pos_cb_and_fire n_pos: {}", diff --git a/src/lib/orderman/orderman_utils/ExchangePosition.h b/src/lib/orderman/orderman_utils/ExchangePosition.h index 1d4a9ae81..4b977a914 100644 --- a/src/lib/orderman/orderman_utils/ExchangePosition.h +++ b/src/lib/orderman/orderman_utils/ExchangePosition.h @@ -4,7 +4,9 @@ #include "lib/mercury/common/mercury_common.h" #include "lib/orderman/orderman_utils/orderman_common.h" #include "lib/utils/overloaded.h" +#include #include +#include #include #include @@ -17,6 +19,7 @@ class ExchangePosition { std::string exchange_sec_desc; api::Security const *security; std::string account_name; + std::optional account_id; double position; Price avg_filled_price; };