55 lines
1.6 KiB
C
55 lines
1.6 KiB
C
#ifndef FILL_HANDLER_H
|
|
#define FILL_HANDLER_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
|
|
#define MAX_CLIENT_OID 41
|
|
|
|
/* A single match event pushed from hot thread to executor thread. */
|
|
typedef struct {
|
|
char client_oid[MAX_CLIENT_OID];
|
|
double match_size;
|
|
double match_price;
|
|
double match_fee;
|
|
bool is_terminal; /* canceled+done with matches */
|
|
bool is_timeout; /* true = fill timeout */
|
|
char order_id[32];
|
|
} fill_event_t;
|
|
|
|
/* Accumulated fill result returned to the executor. */
|
|
typedef struct {
|
|
double total_size;
|
|
double total_funds;
|
|
double total_fee;
|
|
double avg_price;
|
|
int match_count;
|
|
char order_id[32];
|
|
} fill_result_t;
|
|
|
|
/* Per-thread fill channel (SPSC queue + wake fd). */
|
|
typedef struct fill_channel_s fill_channel_t;
|
|
|
|
fill_channel_t *fill_channel_create(void);
|
|
void fill_channel_destroy(fill_channel_t *ch);
|
|
|
|
/* Push a fill event (hot thread, non-blocking). */
|
|
bool fill_channel_push(fill_channel_t *ch, const fill_event_t *ev);
|
|
|
|
/* Wait for a fill matching client_oid (executor thread, blocking).
|
|
Returns the accumulated result. Times out after timeout_ms. */
|
|
bool fill_channel_await(fill_channel_t *ch, const char *client_oid,
|
|
int64_t timeout_ms, fill_result_t *out);
|
|
|
|
/* Pop a single event (non-blocking drain). */
|
|
bool fill_channel_pop(fill_channel_t *ch, fill_event_t *ev);
|
|
|
|
/* Get the wake fd for poll(). */
|
|
int fill_channel_wake_fd(fill_channel_t *ch);
|
|
|
|
/* Reset for next execution. */
|
|
void fill_channel_reset(fill_channel_t *ch);
|
|
|
|
#endif
|