This example demonstrates how to calculate a derived field from input data. An interest is registered in a selection of symbols, and a Mid price is derived from the incoming Bid Ask values.
- Note
- This example has been written using the legacy API.
Sample configuration:
symbols /DEMO/*
Source code:
static char **symbols = NULL;
static int symbols_num = 0;
static int demo_recv_update(
tf_handle_t *handle,
int feed,
ds_data_t *pkt,
int flags,
int id,
void *data);
{
char buf[FILENAME_MAX+1];
int i;
ds_config_add_array_option(
"symbols",
"Symbols to process",
DS_CONFIG_STR_ARRAY,&symbols,&symbols_num);
snprintf(buf,sizeof(buf),"%s.conf",module_name);
if ( symbols_num == 0 ) {
ds_printf_time(
rtas_log,
"(%s) No symbols required\n",module_name);
return;
}
handles = calloc(symbols_num, sizeof(handles[0]));
for ( i = 0; i < symbols_num; i++ ) {
handles[i] =
tf_add_listener(symbols[i], 0, demo_recv_update, NULL, NULL, 0, NULL, NULL);
}
return;
}
static int demo_recv_update(
tf_handle_t *handle,
int feed,
ds_data_t *pkt,
int flags,
int id,
void *data)
{
char *bid_str, *ask_str;
double bid,ask;
bid = atof(bid_str);
ask = atof(ask_str);
ds_add_record_float(dsdata,"Mid", ( ask - bid ) / 2. + bid );
}
}
return 1;
}