This example demonstrates how to publish a derived symbol when a base symbol has a field value within a configured range. If the field value is outside of the range the symbol is deleted.
- Note
- This example has been written using the legacy API.
Sample configuration:
symbols /DEMO/*
check-field Bid
check-upper 10
check-lower 5
Source code:
static char **symbols = NULL;
static int symbols_num = 0;
static char *check_field = "dBestBid";
static double check_upper = 2.0;
static double check_lower = 1.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,
"check-field",
"Fieldname to modify",
DS_CONFIG_STR,&check_field);
ds_config_add_option(0,
"check-upper",
"Upper value for range",
DS_CONFIG_FLOAT,&check_upper);
ds_config_add_option(0,
"check-lower",
"Lower value for range",
DS_CONFIG_FLOAT,&check_lower);
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 derived_subject[1024];
char *value_str;
double value;
return;
}
snprintf(derived_subject,
sizeof(derived_subject),
"%s-DERIVED",pkt->
subject);
value = atof(value_str);
if ( value < check_lower || value > check_upper ) {
return;
} else {
dsdata->
subject = strdup(derived_subject);
}
}
return;
}