File size: 2,731 Bytes
44cddac
8f4d2d0
 
 
44cddac
a3b10ab
 
 
8f4d2d0
 
 
44cddac
8f4d2d0
 
 
 
44cddac
8f4d2d0
 
 
 
44cddac
8f4d2d0
 
 
 
 
 
 
44cddac
8f4d2d0
 
 
 
 
 
 
 
44cddac
8f4d2d0
 
 
 
 
 
 
 
 
44cddac
a3b10ab
 
 
 
44cddac
a3b10ab
 
 
44cddac
a3b10ab
 
 
 
44cddac
a3b10ab
 
 
44cddac
8f4d2d0
a3b10ab
 
 
 
 
8f4d2d0
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "actors/OEGActor.hpp"

namespace eunex {

OEGActor::OEGActor() {
    registerEventHandler<NewOrderEvent>(*this);
    registerEventHandler<CancelOrderEvent>(*this);
    registerEventHandler<ModifyOrderEvent>(*this);
    registerEventHandler<ExecReportEvent>(*this);
}

void OEGActor::mapSymbol(SymbolIndex_t symbolIdx,
                                const tredzone::ActorId& bookActorId) {
    symbolMap_[symbolIdx] = bookActorId;
}

void OEGActor::submitNewOrder(ClOrdId_t clOrdId, SymbolIndex_t symbolIdx,
                                     Side side, OrderType ordType, TimeInForce tif,
                                     Price_t price, Quantity_t qty, SessionId_t session) {
    auto it = symbolMap_.find(symbolIdx);
    if (it == symbolMap_.end()) {
        std::cerr << "OEG: unknown symbol " << symbolIdx << "\n";
        return;
    }

    Event::Pipe pipe(*this, it->second);
    pipe.push<NewOrderEvent>(clOrdId, symbolIdx, side, ordType, tif, price, qty, session);
}

void OEGActor::submitCancel(OrderId_t orderId, ClOrdId_t origClOrdId,
                                   SymbolIndex_t symbolIdx, SessionId_t session) {
    auto it = symbolMap_.find(symbolIdx);
    if (it == symbolMap_.end()) return;

    Event::Pipe pipe(*this, it->second);
    pipe.push<CancelOrderEvent>(orderId, origClOrdId, symbolIdx, session);
}

void OEGActor::submitModify(OrderId_t orderId, ClOrdId_t origClOrdId,
                                   SymbolIndex_t symbolIdx, Price_t newPrice,
                                   Quantity_t newQty, SessionId_t session) {
    auto it = symbolMap_.find(symbolIdx);
    if (it == symbolMap_.end()) return;

    Event::Pipe pipe(*this, it->second);
    pipe.push<ModifyOrderEvent>(orderId, origClOrdId, symbolIdx, newPrice, newQty, session);
}

void OEGActor::onEvent(const NewOrderEvent& event) {
    submitNewOrder(event.clOrdId, event.symbolIdx, event.side, event.ordType,
                    event.tif, event.price, event.quantity, event.sessionId);
}

void OEGActor::onEvent(const CancelOrderEvent& event) {
    submitCancel(event.orderId, event.origClOrdId, event.symbolIdx, event.sessionId);
}

void OEGActor::onEvent(const ModifyOrderEvent& event) {
    submitModify(event.orderId, event.origClOrdId, event.symbolIdx,
                  event.newPrice, event.newQuantity, event.sessionId);
}

void OEGActor::addExecReportSubscriber(const tredzone::ActorId& subscriberId) {
    execReportSubscribers_.push_back(subscriberId);
}

void OEGActor::onEvent(const ExecReportEvent& event) {
    reports_.push_back(event);

    for (auto& subId : execReportSubscribers_) {
        Event::Pipe pipe(*this, subId);
        pipe.push<ExecReportEvent>(event);
    }
}

} // namespace eunex