XROAD
order.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "order_fwd.h"
9 #include <common/xroad_string.h>
10 #include <common/xroad_date.h>
11 #include <cache/xroad_objects.h>
12 #include <logger/xroad_logger.h>
13 #include <stdbool.h>
14 #include <float.h>
15 
16 #ifdef __cplusplus
17 extern "C"
18 {
19 #endif
20 
24 typedef enum
25 {
43 
44 typedef enum
45 {
46  order_exec_check_role = 1,
47  order_exec_fix_qty = 2,
48  order_exec_replace_send = 4
49 } order_exec_t;
50 
54 typedef enum
55 {
63 
70 
74 typedef struct
75 {
76  int32_t mask;
77  xroad_qty_t qty;
78  xroad_price_t price;
79  uint32_t cancel_attempts;
80  uint64_t cancel_timeout_us;
81  uint32_t resend_attempts;
82  uint64_t resend_timeout_us;
84 
88 typedef struct
89 {
90  xroad_str_t name;
91  xroad_str_t account;
92  xroad_str_t client_code;
93  xroad_ord_type_t type;
94  xroad_qty_t qty;
95  xroad_price_t price;
96  xroad_str_t ext_ref;
97  int32_t flags;
98  xroad_tif_t tif;
99  xroad_date_t till_date;
100  uint32_t cancel_attempts;
101  uint64_t cancel_timeout_us;
102  int32_t exec_flags;
103  xroad_str_t comment;
104  void* ctx;
105  xroad_logger_t* logger;
106  uint32_t resend_attempts;
107  uint64_t resend_timeout_us;
108  xroad_str_t sender;
109  xroad_str_t* err;
110  xroad_broker_t* broker;
111  xroad_currency_t* hedge_cur;
112  xroad_portfolio_t* portfolio;
114 
115 typedef struct
116 {
117  bool send;
119 
123 typedef struct
124 {
128  void (*on_activated)(order_t*, xroad_str_t, xroad_timestamp_t);
132  void (*on_before_send)(order_t*);
136  bool (*on_can_send)(order_t*, xroad_qty_t, xroad_price_t);
140  void (*on_trade)(order_t*, xroad_trade_t*);
144  void (*on_canceled)(order_t*, xroad_rej_reason_t, xroad_str_t, xroad_timestamp_t);
148  void (*on_unexpected_canceled)(order_t*, xroad_rej_reason_t, xroad_str_t, xroad_timestamp_t);
152  void (*on_destroyed)(order_t*);
156  void (*on_replaced)(order_t*, xroad_str_t, xroad_timestamp_t);
160  void (*on_rejected)(order_t*, xroad_rej_reason_t, xroad_str_t, xroad_timestamp_t);
164  void (*on_cancel_rejected)(order_t*, xroad_rej_reason_t, xroad_str_t, xroad_timestamp_t);
168  void (*on_replace_rejected)(order_t*, xroad_rej_reason_t, xroad_str_t, xroad_timestamp_t);
172  void (*on_pre_trade)(order_t*, xroad_pre_trade_t*);
176  void (*on_resend)(order_t*);
178 
210  xroad_instr_t* instr,
211  xroad_side_t side,
212  order_callback_t callback,
213  xroad_str_t name,
214  xroad_str_t account,
215  xroad_str_t client_code,
216  xroad_ord_type_t type,
217  xroad_qty_t qty,
218  xroad_price_t price,
219  xroad_str_t ext_ref,
220  int32_t flags,
221  xroad_tif_t tif,
222  xroad_date_t till_date,
223  uint32_t cancel_attempts,
224  uint64_t cancel_timeout_us,
225  int32_t exec_flags,
226  xroad_str_t comment,
227  void* ctx,
228  xroad_logger_t* logger,
229  uint32_t resend_attempts,
230  uint64_t resend_timeout_us,
231  xroad_str_t sender,
232  xroad_str_t* err,
233  xroad_portfolio_t* portfolio,
234  xroad_broker_t* broker,
235  xroad_currency_t* hedge_cur);
236 
237 #define order_create(instr, side, callback, ...) \
238 ({ \
239  order_create_args_t _args_ = {.type = xroad_ord_type_limit, .tif = xroad_tif_day, ## __VA_ARGS__}; \
240  if (_args_.till_date.year == 0 && _args_.till_date.month == 0 && _args_.till_date.day == 0) \
241  { \
242  _args_.till_date = xroad_date_null; \
243  } \
244  order_create_ex(instr, side, callback, _args_.name, _args_.account, _args_.client_code, _args_.type, _args_.qty, \
245  _args_.price, _args_.ext_ref, _args_.flags, _args_.tif, _args_.till_date, _args_.cancel_attempts, \
246  _args_.cancel_timeout_us, _args_.exec_flags, _args_.comment, _args_.ctx, _args_.logger, \
247  _args_.resend_attempts, _args_.resend_timeout_us, _args_.sender, _args_.err, _args_.portfolio, \
248  _args_.broker, _args_.hedge_cur); \
249 })
250 
257 xroad_errno_t order_destroy(order_t* o, bool force);
258 
264 xroad_errno_t order_send(order_t* o);
265 
272 xroad_errno_t order_cancel_ex(order_t* o, bool send);
273 
280 xroad_errno_t order_pre_trade_ack(order_t* o, xroad_pre_trade_t* pre_trade, xroad_pre_trade_status_t status);
281 
282 #define order_cancel(o, ...) \
283 ({ \
284  order_cancel_args_t args = {.send = true, ## __VA_ARGS__}; \
285  order_cancel_ex(o, args.send); \
286 })
287 
294 xroad_errno_t order_replace_ex(order_t* o, order_replace_args_t args);
295 
296 #define order_replace(o, ...) \
297 ({ \
298  order_replace_args_t _args_ = (order_replace_args_t){ \
299  .qty = INT64_MAX, \
300  .price = DBL_MAX, \
301  .cancel_attempts = UINT32_MAX, \
302  .cancel_timeout_us = UINT64_MAX, \
303  .resend_attempts = UINT32_MAX, \
304  .resend_timeout_us = UINT64_MAX, ## __VA_ARGS__}; \
305  _args_.mask |= (_args_.qty == INT64_MAX) ? 0 : order_replace_qty; \
306  _args_.mask |= !xroad_dbl_cmp(_args_.price, DBL_MAX) ? 0 : order_replace_price; \
307  _args_.mask |= (_args_.cancel_attempts == UINT32_MAX) ? 0 : order_replace_cancel_attempts; \
308  _args_.mask |= (_args_.cancel_timeout_us == UINT64_MAX) ? 0 : order_replace_cancel_timeout_us; \
309  _args_.mask |= (_args_.resend_attempts == UINT32_MAX) ? 0 : order_replace_resend_attempts; \
310  _args_.mask |= (_args_.resend_timeout_us == UINT64_MAX) ? 0 : order_replace_resend_timeout_us; \
311  order_replace_ex(o, _args_); \
312 })
313 
318 void order_reset(order_t* o);
319 
325 xroad_str_t order_get_name(const order_t* o);
326 
332 xroad_instr_t* order_get_instr(const order_t* o);
333 
339 xroad_side_t order_get_side(const order_t* o);
340 
346 xroad_qty_t order_get_qty(const order_t* o);
347 
354 
360 xroad_price_t order_get_price(const order_t* o);
361 
367 xroad_price_t order_get_replace_price(const order_t* o);
368 
375 
381 void* order_get_ctx(const order_t* o);
382 
388 order_state_t order_get_state(const order_t* o);
389 
396 
402 xroad_price_t order_get_avg_price(const order_t* o);
403 
410 
416 xroad_str_t order_print(const order_t* o);
417 
423 xroad_order_t* order_get_xorder(const order_t* o);
424 
430 int32_t order_get_flags(const order_t* o);
431 
432 void order_log_debug(order_t* o, char* title);
433 
436 {
437  uint64_t corr_id;
438  uint16_t corr_tag;
441 };
443 
444 enum
445 {
446  order_bad_corr_id = ~0ul
447 };
448 
454 
455 #ifdef __cplusplus
456 }
457 #endif
order_state_t
Definition: order.h:25
@ order_state_awaiting_replace
order is in awaiting replace state
Definition: order.h:36
@ order_state_awaiting_destroy
order is in awaiting destroyed state
Definition: order.h:34
@ order_state_expired
order is in expired state
Definition: order.h:32
@ order_state_awaiting_cancel
order is in awaiting cancel state
Definition: order.h:35
@ order_state_filled
order is in filled state
Definition: order.h:31
@ order_state_destroyed
order is in destroyed state
Definition: order.h:28
@ order_state_awaiting_cancel_resend
order is in awaiting cancel resend state
Definition: order.h:41
@ order_state_initial
order is in initial state
Definition: order.h:26
@ order_state_canceled
order is in canceled state
Definition: order.h:29
@ order_state_resend
order is in resend state
Definition: order.h:40
@ order_state_rejected
order is in rejected state
Definition: order.h:30
@ order_state_awaiting_cancel_replace
order is in awaiting cancel replace state
Definition: order.h:37
@ order_state_active
order is in active state
Definition: order.h:27
@ order_state_awaiting_suspend
order is in awaiting suspended state
Definition: order.h:38
@ order_state_awaiting_active
order is in awaiting active state
Definition: order.h:33
@ order_state_suspended
order is in suspended state
Definition: order.h:39
order_trace_corr_t * order_trace_init(xroad_str_t path, size_t max_rec)
Allocates and initializes structures for orders tracing.
int32_t order_get_flags(const order_t *o)
xroad_str_t order_get_name(const order_t *o)
xroad_qty_t order_get_replace_qty(const order_t *o)
xroad_errno_t order_replace_ex(order_t *o, order_replace_args_t args)
xroad_order_t * order_get_xorder(const order_t *o)
order_t * order_create_ex(xroad_instr_t *instr, xroad_side_t side, order_callback_t callback, xroad_str_t name, xroad_str_t account, xroad_str_t client_code, xroad_ord_type_t type, xroad_qty_t qty, xroad_price_t price, xroad_str_t ext_ref, int32_t flags, xroad_tif_t tif, xroad_date_t till_date, uint32_t cancel_attempts, uint64_t cancel_timeout_us, int32_t exec_flags, xroad_str_t comment, void *ctx, xroad_logger_t *logger, uint32_t resend_attempts, uint64_t resend_timeout_us, xroad_str_t sender, xroad_str_t *err, xroad_portfolio_t *portfolio, xroad_broker_t *broker, xroad_currency_t *hedge_cur)
xroad_instr_t * order_get_instr(const order_t *o)
xroad_ord_type_t order_get_type(const order_t *o)
xroad_price_t order_get_price(const order_t *o)
xroad_qty_t order_get_qty(const order_t *o)
xroad_errno_t order_send(order_t *o)
xroad_qty_t order_get_leaves_qty(const order_t *o)
void order_reset(order_t *o)
xroad_price_t order_get_avg_price(const order_t *o)
order_state_t order_get_state(const order_t *o)
xroad_errno_t order_cancel_ex(order_t *o, bool send)
xroad_price_t order_get_replace_price(const order_t *o)
xroad_errno_t order_destroy(order_t *o, bool force)
xroad_side_t order_get_side(const order_t *o)
xroad_qty_t order_get_total_qty(const order_t *o)
xroad_errno_t order_pre_trade_ack(order_t *o, xroad_pre_trade_t *pre_trade, xroad_pre_trade_status_t status)
order_replace_mask_t
Definition: order.h:55
@ order_replace_price
replace price
Definition: order.h:57
@ order_replace_resend_timeout_us
replace resend_timeout_us
Definition: order.h:61
@ order_replace_cancel_timeout_us
replace cancel_timeout_us
Definition: order.h:59
@ order_replace_cancel_attempts
replace cancel_attempts
Definition: order.h:58
@ order_replace_qty
replace qty
Definition: order.h:56
@ order_replace_resend_attempts
replace resend_attemts
Definition: order.h:60
void * order_get_ctx(const order_t *o)
xroad_str_t order_print(const order_t *o)
xroad_str_t order_state_to_str(order_state_t state)
Definition: order.h:124
Definition: order.h:116
Definition: order.h:89
Definition: order.h:75
Correlation information for tracing.
Definition: order.h:436
uint64_t corr_id
ID of an event triggered the order.
Definition: order.h:437
uint16_t corr_tag
Definition: order.h:438
Definition: xroad_date.h:37
Struct of logger.
Definition: xroad_logger_types.h:21
Definition: xroad_string.h:29
struct xroad_str_s xroad_str_t
see common/xroad_string.h for details
Definition: xroad_common_fwd.h:39
CAUTION: do not change this file - it is autogenerated.
xroad_ord_type_t
Definition: xroad_objects_types.h:290
int64_t xroad_qty_t
Definition: xroad_objects_types.h:191
xroad_pre_trade_status_t
Definition: xroad_objects_types.h:601