Merge branch 'SPARK-1944-attach/detach/update' of bitbucket.org:bluetradesys/spark into ice_exec3
This commit is contained in:
commit
54dd30245f
75 files changed
+2184
-651
No files matched your search
@@ -10,12 +10,14 @@
|
||||
#include "lib/md/Shm/FixedSecurity.h"
|
||||
#include "lib/md/Shm/MDStructure.h"
|
||||
#include "lib/md/get_symbols.h"
|
||||
#include "lib/md/MBOProcessor.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
#include "server/sparkd/exchange_sim/book/Order.h"
|
||||
#include "server/sparkd/exchange_sim/book/OrderMatcher.h"
|
||||
#include "server/sparkd/exchange_sim/book/book_transform.h"
|
||||
#include "lib/persistence/SqliteStore.h"
|
||||
#include "lib/orderman/orderman_utils/fix_order_codec.h"
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <fmt/format.h>
|
||||
@@ -99,15 +101,21 @@ struct ExchangeSimApplication::MDConsumerRec {
|
||||
utils::TimeStamp last_read;
|
||||
};
|
||||
|
||||
inline FIX::OrderID exchange_key(const std::string& clOrdID) {
|
||||
return FIX::OrderID(clOrdID.substr(3));
|
||||
}
|
||||
|
||||
struct ExchangeSimApplication::PImpl {
|
||||
PImpl(bts::api::Venue venue)
|
||||
PImpl(bts::api::Venue venue, md::MBOWriter* mbo)
|
||||
: venue(venue),
|
||||
producer(co2::PLATFORM_SIM),
|
||||
md_sn(1),
|
||||
timer(utils::Dispatcher::background(), 200,
|
||||
[=]() { producer.heartbeat(); }),
|
||||
do_merge_with_md(config::get<config::ExchangeSim>().merge_with_md()),
|
||||
store(new persistence::SqliteStore("ex_sim_orders_" + api::Venue_Name(venue))) {}
|
||||
store(new persistence::SqliteStore("ex_sim_orders_" + api::Venue_Name(venue))),
|
||||
lock(),
|
||||
mbo(mbo) {}
|
||||
|
||||
IDGenerator m_generator;
|
||||
bts::api::Venue venue;
|
||||
@@ -120,9 +128,10 @@ struct ExchangeSimApplication::PImpl {
|
||||
bool do_merge_with_md;
|
||||
std::unique_ptr<persistence::IStore> store;
|
||||
std::mutex lock;
|
||||
md::MBOWriter* mbo;
|
||||
};
|
||||
|
||||
ExchangeSimApplication::ExchangeSimApplication(bts::api::Venue venue) : me(new PImpl(venue)) {
|
||||
ExchangeSimApplication::ExchangeSimApplication(bts::api::Venue venue, md::MBOWriter* mbo) : me(new PImpl(venue, mbo)) {
|
||||
auto previous_book = me->store->retrieve_all();
|
||||
|
||||
auto all = me->store->retrieve_all()["books"];
|
||||
@@ -374,7 +383,7 @@ void ExchangeSimApplication::updateOrder(const Order &order, char status) {
|
||||
FIX::TargetSubID(order.sender_sub_id());
|
||||
|
||||
FIX42::ExecutionReport fixOrder;
|
||||
fixOrder.set(FIX::OrderID("12345678901234567"));
|
||||
fixOrder.set(exchange_key(order.clordid()));
|
||||
fixOrder.set(FIX::ExecID(me->m_generator.genExecutionID()));
|
||||
fixOrder.set(FIX::ExecTransType(FIX::ExecTransType_NEW));
|
||||
fixOrder.set(FIX::ExecType(status));
|
||||
@@ -424,7 +433,7 @@ void ExchangeSimApplication::rejectOrder(
|
||||
FIX::SenderCompID senderCompID(target.getValue());
|
||||
|
||||
FIX42::ExecutionReport fixOrder;
|
||||
fixOrder.set(FIX::OrderID("12345678901234567"));
|
||||
fixOrder.set(exchange_key(clOrdID.getString()));
|
||||
fixOrder.set(FIX::ExecID(me->m_generator.genExecutionID()));
|
||||
fixOrder.set(FIX::ExecTransType(FIX::ExecTransType_NEW));
|
||||
fixOrder.set(FIX::ExecType(FIX::ExecType_REJECTED));
|
||||
@@ -499,7 +508,7 @@ void ExchangeSimApplication::update_md(std::string const &sec_desc) {
|
||||
handle.update_direct(utils::TimeStamp::now(), bids_temp, asks_temp, me->md_sn++);
|
||||
|
||||
auto new_trades = matcher.get_new_trades();
|
||||
for (auto &t : new_trades)
|
||||
for (auto &t : new_trades) {
|
||||
handle.add_trade(
|
||||
utils::TimeStamp::now(),
|
||||
md::PriceSize_from_double<ex_sim::precision>(t.price.value() * price_factor,t.quantity.value()),
|
||||
@@ -507,6 +516,29 @@ void ExchangeSimApplication::update_md(std::string const &sec_desc) {
|
||||
t.bid_aggressor ? co2::AGGRESSOR_SIDE_BUY
|
||||
: ( t.ask_aggressor ? co2::AGGRESSOR_SIDE_SELL
|
||||
: co2::AGGRESSOR_SIDE_NONE) );
|
||||
}
|
||||
|
||||
// publish mbo
|
||||
auto mbo = me->mbo;
|
||||
if (mbo) {
|
||||
// get the list of trades
|
||||
auto ob = matcher.get_order_book(nullptr);
|
||||
auto snap = mbo->allocate_snapshot();
|
||||
for (const auto& order : ob.order()) {
|
||||
auto ek = exchange_key(order.clordid());
|
||||
md::SnapshotOrder sno {
|
||||
md::ExchangeOrderKey(std::atoll(ek.getString().c_str())),
|
||||
md::IntPrice_from_double<precision>(order.price() * price_factor),
|
||||
(int)order.open_quantity() };
|
||||
if (order.side() == api::SIDE_BUY) {
|
||||
snap->bids.push_back(sno);
|
||||
}
|
||||
else if (order.side() == api::SIDE_SELL) {
|
||||
snap->asks.push_back(sno);
|
||||
}
|
||||
}
|
||||
mbo->publish_snapshot(SecurityKey(it->second.key()), &snap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user