never thought I'd use rxcpp...it's truly terrible; I feel physical pain
This commit is contained in:
1 parent
e1c2d8aaaf
commit
6ef0808f49
10 files changed
+538
-55
No files matched your search
@@ -0,0 +1,156 @@
|
||||
#include "DropCopySession.h"
|
||||
#include "FixRouter.h"
|
||||
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/utils/helper_macros.h"
|
||||
|
||||
#include <quickfix/fix44/OrderStatusRequest.h>
|
||||
#include <quickfix/fix44/SecurityDefinitionRequest.h>
|
||||
#include <quickfix/fix44/SecurityDefinition.h>
|
||||
#include <quickfix/fix44/ExecutionReport.h>
|
||||
|
||||
namespace bts {
|
||||
namespace fix {
|
||||
|
||||
DropCopySession::DropCopySession(bts::api::ServiceContext& sc, IFixRouter& rt, const FIX::SessionID& id) :
|
||||
SessionBase(sc, rt, id),
|
||||
_orderservice( sc.locate<api::orderman::OrderService>() ),
|
||||
_order_cache()
|
||||
{
|
||||
}
|
||||
|
||||
DropCopySession::~DropCopySession()
|
||||
{
|
||||
}
|
||||
|
||||
void DropCopySession::onLogon(const FIX::SessionID& sessionID)
|
||||
{
|
||||
bts_assert(sessionID == _sess);
|
||||
LOG(Fix, Info, "Logged on {}", sessionID.toString());
|
||||
subscribe_fills_and_orders(sessionID);
|
||||
}
|
||||
|
||||
void DropCopySession::onLogout(const FIX::SessionID& sessionID)
|
||||
{
|
||||
bts_assert(sessionID == _sess);
|
||||
LOG(Fix, Info, "Logged out {}", sessionID.toString());
|
||||
|
||||
}
|
||||
|
||||
void DropCopySession::fromApp(const FIX::Message &message,const FIX::SessionID &sessionID)
|
||||
throw(FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType)
|
||||
{
|
||||
bts_assert(sessionID == _sess);
|
||||
auto mt = message.getHeader().getField(FIX::FIELD::MsgType);
|
||||
if(mt == FIX44::OrderStatusRequest::MsgType() ||
|
||||
mt == FIX44::SecurityDefinitionRequest::MsgType()
|
||||
)
|
||||
{
|
||||
LOG(Fix, Info, "DC IN: {}", message.toString() );
|
||||
crack(message, sessionID);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(Fix, Info, "DC IN: Unsupported message in {}", mt );
|
||||
throw FIX::UnsupportedMessageType(mt);
|
||||
}
|
||||
}
|
||||
|
||||
void DropCopySession::onMessage(const FIX44::OrderStatusRequest& req, const FIX::SessionID& s)
|
||||
{
|
||||
uint oid = atoi(req.getField(FIX::FIELD::OrderID).c_str());
|
||||
auto it = _order_cache.find(oid);
|
||||
if(it != _order_cache.end())
|
||||
{
|
||||
auto&& ostat = build_order_status(s, *it->second);
|
||||
ostat.setField(FIX::FIELD::OrdStatusReqID, req.getField(FIX::FIELD::OrdStatusReqID));
|
||||
_router.send(ostat, s);
|
||||
}
|
||||
}
|
||||
|
||||
void DropCopySession::onMessage(const FIX44::SecurityDefinitionRequest& req, const FIX::SessionID& s)
|
||||
{
|
||||
if (req.getField(FIX::FIELD::SecurityRequestType) == std::to_string(FIX::SecurityRequestType_ALL_SECURITIES))
|
||||
{
|
||||
auto&& secs = _router.get_securities();
|
||||
// if (req.isSetField(FIX::FIELD::Symbol))
|
||||
// secs = secs.Where(x => x.Symbol.ToLower() == req.Symbol.getValue().ToLower());
|
||||
// if (req.IsSetSecurityType())
|
||||
// secs = secs.Where(x => security_types_equal(x.security_type(), req.SecurityType));
|
||||
// if (req.IsSetSecurityExchange())
|
||||
// secs = secs.Where(x => exchanges_equal(x.Exchange, req.SecurityExchange));
|
||||
|
||||
auto def = FIX44::SecurityDefinition(FIX::SecurityReqID(req.getField(FIX::FIELD::SecurityReqID)),
|
||||
FIX::SecurityResponseID(""),
|
||||
FIX::SecurityResponseType(FIX::SecurityResponseType_LIST_OF_SECURITIES_RETURNED_PER_REQUEST));
|
||||
_router.send(def, s);
|
||||
}
|
||||
else
|
||||
throw FIX::IncorrectTagValue(FIX::FIELD::SecurityRequestType);
|
||||
}
|
||||
|
||||
void DropCopySession::subscribe_fills_and_orders(const FIX::SessionID sessionID)
|
||||
{
|
||||
//TODO put this in our C++ pipe and smoke it
|
||||
//var on_orders = _orderservice.Value.subscribei_orders().Naggle(interval, scheduler).PermissionFilter(_adminobservable).Table().Cache();
|
||||
//var on_fills = _orderservice.Value.subscribei_fills().Naggle(interval, scheduler).PermissionFilter(_adminobservable).Table().Cache();
|
||||
|
||||
// auto filter = rxcpp::observable<>::create([] (auto& observer)
|
||||
// {
|
||||
// return _adminobservable.subscribe([] (auto& x)
|
||||
// {
|
||||
// auto filter = [&x] (auto& z)
|
||||
// {
|
||||
// return x.can_view_account(z.def().account());
|
||||
// };
|
||||
// observer.on_next(filter);
|
||||
// });
|
||||
// });
|
||||
|
||||
auto orders = _orderservice.subscribe_orders() |
|
||||
rxcpp::operators::buffer_with_time( std::chrono::milliseconds(500) );
|
||||
|
||||
// auto admin = _adminobservable |
|
||||
// rxcpp::operators::combine_latest([] (auto& admin, auto& order)
|
||||
// {
|
||||
// return std::make_pair(admin, order);
|
||||
// }, orders) |
|
||||
// rxcpp::operators::filter([] (const auto& pair)
|
||||
// {
|
||||
// //return pair.first.can_view_account(pair.second.def().account());
|
||||
// return true;
|
||||
// });
|
||||
|
||||
orders.subscribe([this](const auto& update)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> l(_lock);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
void DropCopySession::process_order_state(const bts::api::orderman::OrderState& state, uint& filled, uint leaves, double& avgprx,
|
||||
FIX::OrdStatus& fstatus, bts::api::orderman::NativeOrderState& native, const bts::api::orderman::Fill* fill)
|
||||
{
|
||||
}
|
||||
|
||||
const bts::api::Security* DropCopySession::resolve_execution_report_security(const bts::api::Security* sec, FIX44::ExecutionReport& report)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FIX44::ExecutionReport DropCopySession::build_fill(const FIX::SessionID& sess,
|
||||
const bts::api::orderman::Fill& fill, bool change)
|
||||
{
|
||||
return FIX44::ExecutionReport();
|
||||
}
|
||||
|
||||
FIX44::ExecutionReport DropCopySession::build_order_status(const FIX::SessionID& sess,
|
||||
const bts::api::orderman::OrderRecord& order, bool change )
|
||||
{
|
||||
return FIX44::ExecutionReport();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}}
|
||||
Reference in new issue
Block a user