forked from carlcook/OrderManagerTest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorderServer.cc
More file actions
60 lines (50 loc) · 1.66 KB
/
orderServer.cc
File metadata and controls
60 lines (50 loc) · 1.66 KB
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
#ifdef ORDERSERVER_H
template <typename InsertHandler>
OrderServer<InsertHandler>::OrderServer(IMarketModule& marketModule, InsertHandler insertHandler)
: mMarketModule(marketModule),
mOrderInsertHandler(insertHandler)
{
// pass the module the required objects
mMarketModule.Initialise(this, this);
}
template <typename InsertHandler>
bool OrderServer<InsertHandler>::AttemptInsertOrder(const InsertArgs& args, int tag)
{
// record that we received a callback for this tag
mOrderTagToCallbacks[tag] = true;
// do the limit checks
if (CheckLimits(args.mVolume, args.mPrice))
{
// call the module's inserter (using the only instance of the access key)
mOrderInsertHandler(mAccessKey, args);
return true;
}
return false;
}
template <typename InsertHandler>
void OrderServer<InsertHandler>::OnOrderError(int tag)
{
std::cout << tag << ": order error" << std::endl;
}
template <typename InsertHandler>
bool OrderServer<InsertHandler>::CheckLimits(int volume, double price)
{
return volume < 1000 && price < 100;
}
template <typename InsertHandler>
void OrderServer<InsertHandler>::VerifyCallback(int tag)
{
// we should have seen a call to the risk check, if not, bail
if (!mOrderTagToCallbacks[tag])
throw "Risk callback did not happen";
}
template <typename InsertHandler>
void OrderServer<InsertHandler>::InsertOrder(int volume, double price, int tag, bool side)
{
// ask the module to insert the order, resulting in a risk callback
mMarketModule.InsertOrder(volume, price, tag, side);
// verify that the callback happened
VerifyCallback(tag);
// TODO what about calls to CheckOrderInsert that are unsolicited?
}
#endif