This example modifies a field by a configurable factor, affecting its value in the update packet sent between modules and then published onto DataSource
- Note
- This example has been written using the legacy API.
Sample configuration:
symbols /DEMO/*
modify-field Bid
modify-factor 2.0
Source code:
static char **symbols = NULL;
static int symbols_num = 0;
static char *modify_field = "dBestBid";
static double modify_factor = 2.0;
static void demo_recv_update(
int feed,
ds_data_t *pkt, time_t arr_tim,
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);
ds_config_add_option(0,
"modify-field",
"Fieldname to modify",
DS_CONFIG_STR,&modify_field);
ds_config_add_option(0,
"modify-factor",
"Modification factor",
DS_CONFIG_FLOAT,&modify_factor);
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;
}
for ( i = 0; i < symbols_num; i++ ) {
}
return;
}
static void demo_recv_update(
int feed,
ds_data_t *pkt, time_t arr_tim,
int id,
void *data)
{
char newvalue_buf[256];
char *value_str;
double value;
value = atof(value_str);
value *= modify_factor;
snprintf(newvalue_buf,sizeof(newvalue_buf),"%f",value);
}
return;
}