40 lines
1013 B
TypeScript
40 lines
1013 B
TypeScript
|
|
import { requestJson } from "@/shared/api/request-json"
|
||
|
|
|
||
|
|
import type {
|
||
|
|
SelectionResults,
|
||
|
|
SelectionRunAccepted,
|
||
|
|
SelectionRunRequest,
|
||
|
|
SelectionStrategy,
|
||
|
|
} from "./selection.types"
|
||
|
|
|
||
|
|
export function getSelectionResults(
|
||
|
|
strategy: SelectionStrategy,
|
||
|
|
targetTradeDate?: string,
|
||
|
|
signal?: AbortSignal,
|
||
|
|
) {
|
||
|
|
const params = new URLSearchParams({ strategy })
|
||
|
|
if (targetTradeDate) params.set("target_trade_date", targetTradeDate)
|
||
|
|
return requestJson<SelectionResults>(
|
||
|
|
`/api/v1/selection/results?${params.toString()}`,
|
||
|
|
{ signal },
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getSelectionRun(runId: string, signal?: AbortSignal) {
|
||
|
|
return requestJson<SelectionResults>(`/api/v1/selection/runs/${runId}`, {
|
||
|
|
signal,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
export function triggerSelectionRun(
|
||
|
|
request: SelectionRunRequest,
|
||
|
|
signal?: AbortSignal,
|
||
|
|
) {
|
||
|
|
return requestJson<SelectionRunAccepted>("/api/v1/selection/runs", {
|
||
|
|
body: JSON.stringify(request),
|
||
|
|
headers: { "Content-Type": "application/json" },
|
||
|
|
method: "POST",
|
||
|
|
signal,
|
||
|
|
})
|
||
|
|
}
|