refactor: Change exch-open-order record_id to auto-incremented int
To insulate ourselves from potential duplicate-id bugs at the exchange
This commit is contained in:
1 parent
f93bc592cb
commit
31897a1b2e
2 files changed
+22
-4
No files matched your search
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
@@ -99,6 +100,22 @@ ActorThread *find_thread_for_actor(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
class OpenOrderRecordIDStore {
|
||||
public:
|
||||
std::uint32_t get_rec_id(std::string exch_order_id) {
|
||||
auto [it, is_new] =
|
||||
rec_ids_.try_emplace(exch_order_id, rec_id_counter_);
|
||||
if (is_new) {
|
||||
rec_id_counter_++;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
private:
|
||||
std::uint32_t rec_id_counter_ = 1;
|
||||
std::unordered_map<std::string, std::uint32_t> rec_ids_;
|
||||
};
|
||||
|
||||
struct OrderServiceServer::PImpl {
|
||||
PImpl(
|
||||
bts::api::ServiceContext &ctx,
|
||||
@@ -141,6 +158,7 @@ struct OrderServiceServer::PImpl {
|
||||
std::unordered_map<uint32_t, api::Response<api::orderman::Response>>
|
||||
in_flight_order_ops;
|
||||
uint32_t current_req_op_id;
|
||||
OpenOrderRecordIDStore open_order_id_store;
|
||||
};
|
||||
|
||||
OrderServiceServer::OrderServiceServer(
|
||||
@@ -495,8 +513,8 @@ void OrderServiceServer::_on_exchange_open_orders(
|
||||
ev.open_orders.all_open_orders.size());
|
||||
for (const auto &o : ev.open_orders.all_open_orders) {
|
||||
bts::api::orderman::RetrievedExchangeOpenOrder o_ord = {};
|
||||
std::string id = o.exchange_order_id;
|
||||
o_ord.set_record_id(id);
|
||||
auto rec_id = me->open_order_id_store.get_rec_id(o.exchange_order_id);
|
||||
o_ord.set_record_id(rec_id);
|
||||
o_ord.set_exchange_order_id(o.exchange_order_id);
|
||||
o_ord.set_exchange_sec_desc(o.exchange_sec_desc);
|
||||
o_ord.set_exchange_account(o.exchange_account);
|
||||
|
||||
Reference in new issue
Block a user