This example generates a Bid/Ask spread based on the incoming Last price for a symbol.
- Note
- This example has been written using the legacy API.
Sample Configuraiton:
symbols /DEMO/*
spread TEST 2.0
Source code:
static char **symbols = NULL;
static int symbols_num = 0;
static char **spread = NULL;
static int spread_num = 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_array_option(
"spread",
"Configuration of the spread",
DS_CONFIG_STR_ARRAY,&spread,&spread_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;
}
if ( spread_num == 0 || spread_num % 2 ) {
ds_printf_time(
rtas_log,
"(%s) Invalid spread configuration\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 subject_buf[1024];
char *last_str;
double last;
int i;
for ( i = 0; i < spread_num ; i += 2 ) {
snprintf(subject_buf,
sizeof(subject_buf),
"%s-%s",pkt->
subject,spread[i]);
if ( last_str != NULL ) {
last = atof(last_str);
if ( last != 0.0 ) {
ds_add_record_float(dsdata,"dBid",last / atof(spread[i+1]));
ds_add_record_float(dsdata,"dAsk",last * atof(spread[i+1]));
}
}
}
return;
}