-
Notifications
You must be signed in to change notification settings - Fork 48
/
Order.h
153 lines (119 loc) · 3.72 KB
/
Order.h
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright (c) 2017 Object Computing, Inc.
// All rights reserved.
// See the file license.txt for licensing information.
#pragma once
#include "OrderFwd.h"
#include <book/types.h>
#include <string>
#include <vector>
#include <sys/time.h>
namespace orderentry
{
class Order
{
public:
enum State{
Submitted,
Rejected, // Terminal state
Accepted,
ModifyRequested,
ModifyRejected,
Modified,
PartialFilled,
Filled, // Terminal State
CancelRequested,
CancelRejected,
Cancelled, // Terminal state
Unknown
};
struct StateChange
{
State state_;
std::string description_;
StateChange()
: state_(Unknown)
{}
StateChange(State state, const std::string & description = "")
: state_(state)
, description_(description)
{}
};
typedef std::vector<StateChange> History;
public:
Order(const std::string & id,
bool buy_side,
liquibook::book::Quantity quantity,
std::string symbol,
liquibook::book::Price price,
liquibook::book::Price stopPrice,
bool aon,
bool ioc);
//////////////////////////
// Implement the
// liquibook::book::order
// concept.
/// @brief is this a limit order?
bool is_limit() const;
/// @brief is this order a buy?
bool is_buy() const;
/// @brief get the price of this order, or 0 if a market order
liquibook::book::Price price() const;
/// @brief get the stop price (if any) for this order.
/// @returns the stop price or zero if not a stop order
liquibook::book::Price stop_price() const;
/// @brief get the quantity of this order
liquibook::book::Quantity order_qty() const;
/// @brief if no trades should happen until the order
/// can be filled completely.
/// Note: one or more trades may be used to fill the order.
virtual bool all_or_none() const;
/// @brief After generating as many trades as possible against
/// orders already on the market, cancel any remaining quantity.
virtual bool immediate_or_cancel() const;
std::string symbol() const;
std::string order_id() const;
uint32_t quantityFilled() const;
uint32_t quantityOnMarket() const;
uint32_t fillCost() const;
Order & verbose(bool verbose = true);
bool isVerbose()const;
const History & history() const;
const StateChange & currentState() const;
void genTimestamp();
struct timeval timestamp() const { return tstamp_; }
///////////////////////////
// Order life cycle events
void onSubmitted();
void onAccepted();
void onRejected(const char * reason);
void onFilled(
liquibook::book::Quantity fill_qty,
liquibook::book::Cost fill_cost);
void onCancelRequested();
void onCancelled();
void onCancelRejected(const char * reason);
void onReplaceRequested(
const int32_t& size_delta,
liquibook::book::Price new_price);
void onReplaced(const int32_t& size_delta,
liquibook::book::Price new_price);
void onReplaceRejected(const char * reason);
private:
std::string id_;
bool buy_side_;
std::string symbol_;
liquibook::book::Quantity quantity_;
liquibook::book::Price price_;
liquibook::book::Price stopPrice_;
bool ioc_;
bool aon_;
liquibook::book::Quantity quantityFilled_;
int32_t quantityOnMarket_;
uint32_t fillCost_;
std::vector<StateChange> history_;
bool verbose_;
struct timeval tstamp_;
};
std::ostream & operator << (std::ostream & out, const Order & order);
std::ostream & operator << (std::ostream & out, const Order::StateChange & event);
}