trading strategy in C
#include <stdio.h>
#include <stdlib.h>
/**
* homogenous strategy prototyping
* two types of orders, market and limit.
* strategy has target item, compares to the price,
* then picks action
*/
typedef size_t PID;
typedef enum {
COMP_LT,
COMP_EQ,
COMP_GT
} Comp;
typedef enum {
ORDER_SELL_M,
ORDER_SELL_L,
ORDER_BUY_M,
ORDER_BUY_L
} Order;
typedef struct {
PID customer;
PID item;
Comp op;
double amount;
double cprice;
Order act;
double lprice; // not used for market orders.
} Strategy;
size_t Strategy_max_orders(const Strategy* sts, PID item, size_t n, int isbuy)
{
size_t total = 0;
const Strategy* endptr = sts + n;
while(sts != endptr) {
if (sts->item == item) {
switch (sts->act) {
case ORDER_BUY_L:
case ORDER_BUY_M:
if (isbuy) ++total;
break;
case ORDER_SELL_L:
case ORDER_SELL_M:
if (!isbuy) ++total;
break;
}
}
++sts;
}
return total;
}
int main(void) {
printf("Hello World\n");
return 0;
}