34 order_book_side_buy = xroad_side_buy,
35 order_book_side_sell = xroad_side_sell
40 order_book_replace_send = 1,
42 order_book_sell_short = 4,
43 order_book_buy_long = 8
48 bool (*on_can_send)(order_book_t*, order_t*,
xroad_qty_t, xroad_price_t);
49 void (*on_activated)(order_book_t*, xroad_timestamp_t);
50 void (*on_canceled)(order_book_t*, xroad_timestamp_t);
51 void (*on_rejected)(order_book_t*, xroad_rej_reason_t,
xroad_str_t, xroad_timestamp_t);
52 void (*on_replaced)(order_book_t*, xroad_timestamp_t);
54 void (*on_trade)(order_book_t*, xroad_trade_t*);
55 void (*on_destroyed)(order_book_t*);
57 xroad_errno_t (*gen_qty)(order_book_t*, uint64_t, order_book_side_t,
xroad_qty_t*, size_t, bool, xroad_sstream_t*);
58 void (*on_resend)(order_book_t*);
80 xroad_price_t best_bid;
81 xroad_price_t best_ask;
84 uint32_t cancel_attempts;
85 uint64_t cancel_timeout_us;
86 uint32_t resend_attempts;
87 uint64_t resend_timeout_us;
95 xroad_price_t best_bid;
96 xroad_price_t best_ask;
98 xroad_portfolio_t* portfolio_buy;
99 xroad_portfolio_t* portfolio_sell;
104 xroad_broker_t* broker_buy;
105 xroad_broker_t* broker_sell;
111 xroad_currency_t* hedge_currency;
112 uint32_t destroy_timeout_us;
113 uint32_t cancel_attempts;
114 uint64_t cancel_timeout_us;
115 uint32_t resend_attempts;
116 uint64_t resend_timeout_us;
154 #define order_book_create(instr, buy_size, sell_size, ...) \
156 order_book_create_args_t args = {.buy_levels = 1, .sell_levels = 1, .price_step = 1U, \
157 .destroy_timeout_us = 5000000, ## __VA_ARGS__}; \
158 order_book_create_ex(instr, buy_size, sell_size, args.buy_levels, args.sell_levels, args.best_bid, args.best_ask, \
159 args.price_step, args.portfolio_buy, args.portfolio_sell, args.account_buy, args.account_sell, \
160 args.client_code_buy, args.client_code_sell, args.broker_buy, args.broker_sell, \
161 args.cback, args.logger, args.ss, args.flags, args.order_flags, args.hedge_currency, \
162 args.destroy_timeout_us, args.cancel_attempts, args.cancel_timeout_us, \
163 args.resend_attempts, args.resend_timeout_us, args.sender, args.comment_buy, args.comment_sell); \
203 xroad_instr_t* instr,
207 uint32_t sell_levels,
208 xroad_price_t best_bid,
209 xroad_price_t best_ask,
211 xroad_portfolio_t* portfolio_buy,
212 xroad_portfolio_t* portfolio_sell,
217 xroad_broker_t* broker_buy,
218 xroad_broker_t* broker_sell,
224 xroad_currency_t* hedge_currency,
225 uint64_t destroy_timeout_us,
226 uint32_t cancel_attempts,
227 uint64_t cancel_timeout_us,
228 uint32_t resend_attempts,
229 uint64_t resend_timeout_us,
287 #define order_book_replace(order_book, ...) \
289 order_book_replace_args_t _args_ = (order_book_replace_args_t){ \
290 .best_bid = DBL_MAX, \
291 .best_ask = DBL_MAX, \
292 .buy_size = INT64_MAX, \
293 .sell_size = INT64_MAX, \
294 .cancel_attempts = UINT32_MAX, \
295 .cancel_timeout_us = UINT64_MAX, \
296 .resend_attempts = UINT32_MAX, \
297 .resend_timeout_us = UINT64_MAX, \
299 _args_.mask |= !xroad_dbl_cmp(_args_.best_bid, DBL_MAX) ? 0 : order_book_replace_best_bid; \
300 _args_.mask |= !xroad_dbl_cmp(_args_.best_ask, DBL_MAX) ? 0 : order_book_replace_best_ask; \
301 _args_.mask |= _args_.buy_size == INT64_MAX ? 0 : order_book_replace_buy_size; \
302 _args_.mask |= _args_.sell_size == INT64_MAX ? 0 : order_book_replace_sell_size; \
303 _args_.mask |= (_args_.cancel_attempts == UINT32_MAX) ? 0 : order_book_replace_cancel_attempts; \
304 _args_.mask |= (_args_.cancel_timeout_us == UINT64_MAX) ? 0 : order_book_replace_cancel_timeout_us;\
305 _args_.mask |= (_args_.resend_attempts == UINT32_MAX) ? 0 : order_book_replace_resend_attempts; \
306 _args_.mask |= (_args_.resend_timeout_us == UINT64_MAX) ? 0 : order_book_replace_resend_timeout_us;\
307 order_book_replace_ex(order_book, _args_); \
324 #define order_book_destroy(book, ...) \
326 order_book_destroy_args_t args = (order_book_destroy_args_t){__VA_ARGS__}; \
327 order_book_destroy_ex(book, args.force); \
order_t * order_book_get_order(order_book_t *order_book, order_book_side_t side, uint32_t idx)
order_book_replace_mask_t
Definition: order_book.h:66
@ order_book_replace_resend_attempts
replace resend_attemts
Definition: order_book.h:73
@ order_book_replace_sell_size
replace sell size
Definition: order_book.h:70
@ order_book_replace_cancel_timeout_us
replace cancel_timeout_us
Definition: order_book.h:72
@ order_book_replace_cancel_attempts
replace cancel_attempts
Definition: order_book.h:71
@ order_book_replace_best_ask
replace best ask
Definition: order_book.h:68
@ order_book_replace_buy_size
replace buy size
Definition: order_book.h:69
@ order_book_replace_resend_timeout_us
replace resend_timeout_us
Definition: order_book.h:74
@ order_book_replace_best_bid
replace best bid
Definition: order_book.h:67
void order_book_destroy_ex(order_book_t *order_book, bool force)
xroad_errno_t order_book_cancel(order_book_t *order_book)
order_book_state_t order_book_get_state(order_book_t *order_book)
xroad_errno_t order_book_replace_ex(order_book_t *order_book, order_book_replace_args_t args)
order_book_state_t
Definition: order_book.h:16
@ order_book_state_active
order_book is in active state
Definition: order_book.h:18
@ order_book_state_resend_replace
order_book is in resend state (one of order going to resend)
Definition: order_book.h:29
@ order_book_state_awaiting_active
order_book is in awaiting active state
Definition: order_book.h:22
@ order_book_state_destroyed
order_book is in destroyed state
Definition: order_book.h:19
@ order_book_state_resend_active
order_book is in resend state (one of order going to resend)
Definition: order_book.h:28
@ order_book_state_error
order_book is in errorneus state
Definition: order_book.h:27
@ order_book_state_awaiting_replace
order_book is in awaiting replace state
Definition: order_book.h:25
@ order_book_state_canceled
order_book is in canceled state
Definition: order_book.h:20
@ order_book_state_awaiting_destroy
order_book is in awaiting destroyed state
Definition: order_book.h:23
@ order_book_state_initial
order_book is in initial state
Definition: order_book.h:17
@ order_book_state_awaiting_reject
order_book is awaiting to cancel all after reject
Definition: order_book.h:26
@ order_book_state_rejected
order_book is in rejected state
Definition: order_book.h:21
@ order_book_state_awaiting_cancel
order_book is in awaiting cancel state
Definition: order_book.h:24
void order_book_print(order_book_t *order_book, xroad_log_level_t llevel)
xroad_errno_t order_book_send(order_book_t *order_book)
order_book_flags_t
Definition: order_book.h:39
@ order_book_replace_delay
delay replace until previous replace still processed
Definition: order_book.h:41
xroad_price_t order_book_get_best_price(order_book_t *order_book, order_book_side_t side)
order_book_t * order_book_create_ex(xroad_instr_t *instr, xroad_qty_t buy_size, xroad_qty_t sell_size, uint32_t buy_levels, uint32_t sell_levels, xroad_price_t best_bid, xroad_price_t best_ask, uint32_t price_step, xroad_portfolio_t *portfolio_buy, xroad_portfolio_t *portfolio_sell, xroad_str_t account_buy, xroad_str_t account_sell, xroad_str_t client_code_buy, xroad_str_t client_code_sell, xroad_broker_t *broker_buy, xroad_broker_t *broker_sell, order_book_callback_t cback, xroad_logger_t *logger, xroad_sstream_t *ss, int32_t flags, int32_t order_flags, xroad_currency_t *hedge_currency, uint64_t destroy_timeout_us, uint32_t cancel_attempts, uint64_t cancel_timeout_us, uint32_t resend_attempts, uint64_t resend_timeout_us, xroad_str_t sender, xroad_str_t comment_buy, xroad_str_t comment_sell)
void * order_book_get_ctx(order_book_t *)
uint32_t order_book_get_levels(order_book_t *order_book, order_book_side_t side)
xroad_qty_t order_book_get_size(order_book_t *order_book, order_book_side_t side)
xroad_instr_t * order_book_get_instr(order_book_t *order_book)
Definition: order_book.h:47
void * ctx
stored context
Definition: order_book.h:59
Definition: order_book.h:92
Definition: order_book.h:123
Definition: order_book.h:78
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
xroad_log_level_t
Definition: xroad_log_defs.h:14
int64_t xroad_qty_t
Definition: xroad_objects_types.h:191
#define xroad_str(str)
Definition: xroad_string.h:194