|
| 1 | +#include "strategy.h" |
| 2 | +#include "config.def.h" |
| 3 | + |
| 4 | +static void usage(const char *prog) { |
| 5 | + fprintf(stderr, |
| 6 | + "Usage: %s [-c center] [-l levels] [-s spacing] [-q quantity] [-d]\n", prog); |
| 7 | + exit(1); |
| 8 | +} |
| 9 | + |
| 10 | +int main(int argc, char *argv[]) { |
| 11 | + double center = DEFAULT_CENTER; |
| 12 | + int levels = DEFAULT_LEVELS; |
| 13 | + double spacing = DEFAULT_SPACING; |
| 14 | + double quantity = DEFAULT_QUANTITY; |
| 15 | + |
| 16 | + int opt, debug = 0, tick = 0; |
| 17 | + while ((opt = getopt(argc, argv, "c:l:s:q:dh")) != -1) { |
| 18 | + switch (opt) { |
| 19 | + case 'c': center = atof(optarg); break; |
| 20 | + case 'l': levels = atoi(optarg); break; |
| 21 | + case 's': spacing = atof(optarg); break; |
| 22 | + case 'q': quantity = atof(optarg); break; |
| 23 | + case 'd': ++debug; break; |
| 24 | + case 'h': default: usage(argv[0]); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + strategy_t *strategy = strategy_create(center, |
| 29 | + levels, spacing, quantity); |
| 30 | + if (strategy == NULL) { |
| 31 | + fputs("Failed to initialize strategy.\n", stderr); |
| 32 | + return 1; |
| 33 | + } |
| 34 | + |
| 35 | + char line[MAX_LINE_LENGTH]; |
| 36 | + while (fgets(line, sizeof(line), stdin)) { |
| 37 | + double price = atof(line); |
| 38 | + printf("\nTICK %d @ %.2f\n", ++tick, price); |
| 39 | + strategy_on_tick(strategy, price); |
| 40 | + if (debug > 0) { |
| 41 | + strategy_print_status(strategy); |
| 42 | + } |
| 43 | + fflush(stdout); |
| 44 | + } |
| 45 | + |
| 46 | + strategy_free(strategy); |
| 47 | + return 0; |
| 48 | +} |
0 commit comments