XROAD
strategy.h File Reference
Include dependency graph for strategy.h:

Go to the source code of this file.

Classes

struct  strategy_cancel_orders_args_t
 
struct  strategy_send_order_ex_args_t
 
struct  strategy_add_order_ex_args_t
 
struct  strategy_callback_t
 

Macros

#define ST_PREV_QTY   0
 
#define ST_PREV_PRICE   0.0
 
#define strategy_add_order(s, name, instr, side, ...)
 
#define strategy_replace_order(s, name, instr, side, ...)
 
#define strategy_send_order(s, oname, ...)
 
#define strategy_cancel_orders(s, ...)
 

Typedefs

typedef struct strategy_s strategy_t
 

Functions

strategy_t * strategy_create (xroad_xml_tag_t cfg, strategy_callback_t cback)
 
void strategy_destroy (strategy_t *s)
 
xroad_errno_t strategy_start (strategy_t *s)
 
xroad_errno_t strategy_stop (strategy_t *s)
 
xroad_errno_t strategy_subscribe (strategy_t *s, xroad_instr_t *i, int32_t mask)
 
xroad_errno_t strategy_unsubscribe (strategy_t *s, xroad_instr_t *i)
 
order_t * strategy_add_order_ex (strategy_t *s, xroad_str_t name, xroad_instr_t *instr, xroad_side_t side, 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)
 
order_t * strategy_replace_order_ex (strategy_t *s, xroad_str_t name, xroad_instr_t *instr, xroad_side_t side, 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)
 
xroad_errno_t strategy_del_order (strategy_t *s, xroad_str_t oname)
 
order_t * strategy_get_order (strategy_t *s, xroad_str_t oname)
 
order_state_t strategy_get_order_state (strategy_t *s, xroad_str_t oname)
 
xroad_errno_t strategy_send_order_ex (strategy_t *s, xroad_str_t oname, xroad_qty_t qty, xroad_price_t price)
 
xroad_errno_t strategy_cancel_order (strategy_t *s, xroad_str_t oname)
 
void strategy_init_orders (strategy_t *s, xroad_instr_t *instr, xroad_str_t account, xroad_str_t client_code)
 
void strategy_init_orders_ex (strategy_t *s, xroad_instr_t *instr, xroad_str_t account, xroad_str_t client_code, xroad_str_t ext_ref)
 
xroad_errno_t strategy_send_order_instr (strategy_t *s, const xroad_instr_t *i, xroad_side_t side, xroad_qty_t qty, xroad_price_t price)
 
xroad_errno_t strategy_cancel_orders_ex (strategy_t *s, xroad_instr_t *i, xroad_str_t account, xroad_side_t side, bool use_native)
 
xroad_str_t strategy_gen_order_name (const xroad_instr_t *i, xroad_side_t side, xroad_ord_type_t type)
 
xroad_errno_t strategy_reset_position (strategy_t *s, xroad_instr_t *i, xroad_price_t avg_price, xroad_qty_t qty, xroad_price_t realized_pnl)
 
mdata_engine_t * strategy_get_mdata (strategy_t *s)
 

Detailed Description

Macro Definition Documentation

◆ strategy_add_order

#define strategy_add_order (   s,
  name,
  instr,
  side,
  ... 
)
Value:
({ \
xroad_str_t def_account = xroad_str("XXX"); \
strategy_add_order_ex_args_t args = {.account = def_account, .type = xroad_ord_type_limit, \
.tif = xroad_tif_day, .till_date = xroad_date_nul, __VA_ARGS__}; \
strategy_add_order_ex(s, name, instr, side, args.account, args.client_code, args.type, args.qty, args.price, \
args.ext_ref, args.flags, args.tif, args.till_date); \
})
@ xroad_ord_type_limit
limit order
Definition: xroad_objects_types.h:256
#define xroad_str(str)
Definition: xroad_string.h:165

◆ strategy_cancel_orders

#define strategy_cancel_orders (   s,
  ... 
)
Value:
({ \
strategy_cancel_orders_args_t args_ = (strategy_cancel_orders_args_t){.instr = NULL, \
.side = xroad_side_undef, .use_native = false, __VA_ARGS__}; \
strategy_cancel_orders_ex(s, args_.instr, args_.account, args_.side, args_.use_native); \
})
Definition: strategy.h:24

◆ strategy_replace_order

#define strategy_replace_order (   s,
  name,
  instr,
  side,
  ... 
)
Value:
({ \
xroad_str_t def_account = xroad_str("XXX"); \
strategy_add_order_ex_args_t args = {.account = def_account, .type = xroad_ord_type_limit, \
.tif = xroad_tif_day, .till_date = xroad_date_null, __VA_ARGS__}; \
strategy_replace_order_ex(s, name, instr, side, args.account, args.client_code, args.type, args.qty, args.price, \
args.ext_ref, args.flags, args.tif, args.till_date); \
})

◆ strategy_send_order

#define strategy_send_order (   s,
  oname,
  ... 
)
Value:
({ \
strategy_send_order_ex_args_t args = (strategy_send_order_ex_args_t){ \
.qty = ST_PREV_QTY, .price = ST_PREV_PRICE, __VA_ARGS__}; \
strategy_send_order_ex(s, oname, args.qty, args.price); \
})
Definition: strategy.h:32

Function Documentation

◆ strategy_add_order_ex()

order_t* strategy_add_order_ex ( strategy_t *  s,
xroad_str_t  name,
xroad_instr_t *  instr,
xroad_side_t  side,
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 
)

add new order by hand

Parameters
[in]s- strategy
[in]name- order name. must be unique among strategy orders
[in]instr- instrument
[in]account- order account
[in]client_code- order client_code
[in]side- order side
[in]qty- order qty
[in]price- order price
[in]ext_ref- reference info, which will be sent with order
[in]flags- order flags (see xroad_order_flags_t for details)
[in]tif- order time-in-force
[in]till_date- order till date
Returns
order instance, else error

◆ strategy_cancel_order()

xroad_errno_t strategy_cancel_order ( strategy_t *  s,
xroad_str_t  oname 
)

cancel order

Parameters
[in]s- strategy instance
[in]oname- order name
Returns
XROAD_OK - success, else failed

◆ strategy_cancel_orders_ex()

xroad_errno_t strategy_cancel_orders_ex ( strategy_t *  s,
xroad_instr_t *  i,
xroad_str_t  account,
xroad_side_t  side,
bool  use_native 
)

cancel orders by instrument

Parameters
[in]s- strategy instance
[in]oname- order name
[in]i- instrument
[in]account- account
[in]side- side
[in]use_native- use native cancel_all functionality if exchange support it
Returns
XROAD_OK - success, else failed

◆ strategy_create()

strategy_t* strategy_create ( xroad_xml_tag_t  cfg,
strategy_callback_t  cback 
)

create new strategy

Parameters
[in]cfg- strategy configuration
[in]cback- strategy callbacks
Returns
strategy or NULL in case of error

◆ strategy_del_order()

xroad_errno_t strategy_del_order ( strategy_t *  s,
xroad_str_t  oname 
)

delete order from strategy

Parameters
[in]s- strategy instance
[in]oname- order name
Returns
XROAD_OK - success, else failed

◆ strategy_destroy()

void strategy_destroy ( strategy_t *  s)

destroy strategy

Parameters
[in]s- strategy to destroy

◆ strategy_gen_order_name()

xroad_str_t strategy_gen_order_name ( const xroad_instr_t *  i,
xroad_side_t  side,
xroad_ord_type_t  type 
)

generate order name from instrument, side and type

Parameters
[in]i- instrument
[in]side- order side
[in]type- order type
Returns
order name

◆ strategy_get_order()

order_t* strategy_get_order ( strategy_t *  s,
xroad_str_t  oname 
)

get order

Parameters
[in]s- strategy instance
[in]oname- order name to delete
Returns
non-zero pointer on success, NULL on fail (order not found)

◆ strategy_get_order_state()

order_state_t strategy_get_order_state ( strategy_t *  s,
xroad_str_t  oname 
)

get order state. just a wrapper of order_get_state function

Parameters
[in]s- strategy instance
[in]oname- order name
Returns
order state

◆ strategy_init_orders()

void strategy_init_orders ( strategy_t *  s,
xroad_instr_t *  instr,
xroad_str_t  account,
xroad_str_t  client_code 
)

init orders

Parameters
[in]s- strategy
[in]instr- instrument
[in]account- order account
[in]client_code- order client_code

◆ strategy_replace_order_ex()

order_t* strategy_replace_order_ex ( strategy_t *  s,
xroad_str_t  name,
xroad_instr_t *  instr,
xroad_side_t  side,
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 
)

replace (delete & add) order by hand

Parameters
[in]s- strategy
[in]name- order name. must be unique among strategy orders
[in]instr- instrument
[in]account- order account
[in]client_code- order client_code
[in]side- order side
[in]qty- order qty
[in]price- order price
[in]ext_ref- reference info, which will be sent with order
[in]flags- order flags (see xroad_order_flags_t for details)
[in]tif- order time-in-force
[in]till_date- order till date
Returns
order instance, else error

◆ strategy_send_order_ex()

xroad_errno_t strategy_send_order_ex ( strategy_t *  s,
xroad_str_t  oname,
xroad_qty_t  qty,
xroad_price_t  price 
)

replace order qty/price and when send it on exchange. If order is alredy on exchange it just be replaced

Parameters
[in]s- strategy instance
[in]oname- order name
[in]qty- new order quantity. If qty should send unchanged set PREV_QTY
[in]price- new order price. If price should send unchanged set PREV_PRICE
Returns
XROAD_OK - success, else failed

◆ strategy_send_order_instr()

xroad_errno_t strategy_send_order_instr ( strategy_t *  s,
const xroad_instr_t *  i,
xroad_side_t  side,
xroad_qty_t  qty,
xroad_price_t  price 
)

replace order qty/price and when send it on exchange. If order is alredy on exchange it just be replaced

Parameters
[in]s- strategy instance
[in]oname- order name
[in]qty- new order quantity
[in]price- new order price
Returns
XROAD_OK - success, else failed

◆ strategy_start()

xroad_errno_t strategy_start ( strategy_t *  s)

start strategy. During start strategy subscribing to market data

Parameters
[in]s- strategy to start
Returns
XROAD_OK - started, else something goes wrong

◆ strategy_stop()

xroad_errno_t strategy_stop ( strategy_t *  s)

stop strategy. During stop strategy unsibscribing from market data and cancelling all orders

Parameters
[in]s- strategy to start
Returns
XROAD_OK - started, else something goes wrong

◆ strategy_subscribe()

xroad_errno_t strategy_subscribe ( strategy_t *  s,
xroad_instr_t *  i,
int32_t  mask 
)

subscribe to market data. This is a way to subscribe to market data by hand

Parameters
[in]s- strategy instance
[in]symbol- instrument alias to subscribe to
[in]mask- subscription mask (see enum mdata_proto_type_t in mdata_proto.h for details)
Returns
XROAD_OK - subscribed, else failed

◆ strategy_unsubscribe()

xroad_errno_t strategy_unsubscribe ( strategy_t *  s,
xroad_instr_t *  i 
)

unsubscribe from market data

Parameters
[in]s- strategy instance
[in]symbol- instrument alias to unsubscribe from
Returns
XROAD_OK - subscribed, else failed