18 {100.0, 102.0, 99.0, 101.0, 4.0, 0},
19 {102.0, 103.0, 101.0, 102.0, 4.0, 300000},
20 {103.0, 104.0, 102.0, 103.5, 4.0, 600000},
21 {103.5, 105.0, 103.0, 104.0, 4.0, 900000}
33 struct host_state* state = (
struct host_state*)user;
39 if (state->bars != 1 && state->bars != 3)
return 0;
41 memset(&request, 0,
sizeof(request));
44 if (state->bars == 1) {
47 request.
label =
"hello-long";
50 request.
label =
"hello-flat";
55 fprintf(stderr,
"submit refused at bar %d\n", state->bars);
64 memset(&spec, 0,
sizeof(spec));
92 struct host_state state;
98 memset(&state, 0,
sizeof(state));
99 memset(&report, 0,
sizeof(report));
101 memset(&callbacks, 0,
sizeof(callbacks));
102 callbacks.struct_size = (uint32_t)
sizeof(callbacks);
104 callbacks.user = &state;
105 callbacks.on_bar =
on_bar;
109 fprintf(stderr,
"create: the runtime refused the callback table\n");
129 printf(
" %s qty=%g entry=%g exit=%g pnl=%g\n",
130 trade->
is_long ?
"long " :
"short", trade->
qty,
138 return trades > 0 ? 0 : 1;
const char * strategy_get_last_error(pf_strategy_t s)
Returns the error message captured by the most recent run_backtest / run_backtest_full call on this s...
int strategy_configure_native_v1(pf_strategy_t s, const pf_native_run_spec_v1 *spec)
Apply a native v1 specification.
int strategy_native_run_v1(pf_strategy_t s, const pf_bar_t *bars, int n, pf_report_t *out)
Run n bars as one batch and fill out.
void strategy_native_host_free(pf_strategy_t s)
Release a handle from strategy_native_host_create_v1.
pf_strategy_t strategy_native_host_create_v1(const pf_native_callbacks_v1 *callbacks)
Allocate a native host that forwards every kernel callback to callbacks.
int strategy_native_submit_v1(pf_strategy_t s, const pf_native_request_v1 *request, uint64_t *incarnation, uint32_t *reject)
Submit request.
void strategy_native_report_free_v1(pf_report_t *report)
Free the heap arrays inside a report filled by strategy_native_run_v1.
@ PF_NATIVE_INTENT_TRANSACT
intent_value signed units.
@ PF_NATIVE_INTENT_FLATTEN
Close the whole book.
#define PF_NATIVE_OK
Success.
static const pf_bar_t kBars[]
static pf_native_run_spec_v1 make_spec(void)
static int on_bar(void *user, const pf_bar_t *bar, const pf_native_decision_v1 *at)
#define PF_NATIVE_API_VERSION
Monotonic version of this header's native-C layouts.
void * pf_strategy_t
Opaque handle to a compiled strategy instance.
Single OHLCV bar pushed into the engine.
The C host's strategy logic.
Where the kernel is, presented to every callback.
uint32_t struct_size
sizeof(pf_native_request_v1).
uint32_t intent
pf_native_intent_t.
uint32_t version
PF_NATIVE_API_VERSION.
double intent_value
The intent's own scalar; see pf_native_intent_t.
Versioned native run specification.
uint32_t allowed_open_directions
const char * basecurrency
const char * chart_timezone
Backtest report filled by run_backtest / run_backtest_full.
int total_trades
Closed-trade count (== trades_len), including the range-end close of a position still open after the ...
pf_trade_t * trades
Heap array of closed trades; script-driven exits first, then the range-end rows (open_at_end=1).
Closed-trade record returned in pf_report_t::trades.
double exit_price
Exit fill price (incl.
double pnl
Net realized PnL in account currency (commission-inclusive).
int is_long
1 if long, 0 if short.
double qty
Filled quantity.
double entry_price
Entry fill price (incl.