af1e1eaa66
Co-authored-by: Cursor <cursoragent@cursor.com>
78 lines
2.1 KiB
TypeScript
78 lines
2.1 KiB
TypeScript
import { requestJson } from "@/shared/api/request-json"
|
|
|
|
import {
|
|
selectionResultPageSize,
|
|
type SelectionChart,
|
|
type SelectionResults,
|
|
type SelectionResultsQuery,
|
|
type SelectionRunAccepted,
|
|
type SelectionRunRequest,
|
|
type SelectionStrategy,
|
|
} from "./selection.types"
|
|
|
|
export function getSelectionChart(
|
|
tsCode: string,
|
|
targetTradeDate: string,
|
|
signal?: AbortSignal,
|
|
) {
|
|
const params = new URLSearchParams({
|
|
target_trade_date: targetTradeDate,
|
|
})
|
|
return requestJson<SelectionChart>(
|
|
`/api/v1/selection/stocks/${encodeURIComponent(tsCode)}/chart?${params.toString()}`,
|
|
{ signal },
|
|
)
|
|
}
|
|
|
|
export function getSelectionResults(
|
|
strategy: SelectionStrategy,
|
|
targetTradeDate?: string,
|
|
query: SelectionResultsQuery = { page: 1, pageSize: selectionResultPageSize },
|
|
signal?: AbortSignal,
|
|
) {
|
|
const params = buildSelectionQueryParams(query)
|
|
params.set("strategy", strategy)
|
|
if (targetTradeDate) params.set("target_trade_date", targetTradeDate)
|
|
return requestJson<SelectionResults>(
|
|
`/api/v1/selection/results?${params.toString()}`,
|
|
{ signal },
|
|
)
|
|
}
|
|
|
|
export function getSelectionRun(
|
|
runId: string,
|
|
query: SelectionResultsQuery = { page: 1, pageSize: selectionResultPageSize },
|
|
signal?: AbortSignal,
|
|
) {
|
|
const params = buildSelectionQueryParams(query)
|
|
return requestJson<SelectionResults>(
|
|
`/api/v1/selection/runs/${runId}?${params.toString()}`,
|
|
{
|
|
signal,
|
|
},
|
|
)
|
|
}
|
|
|
|
function buildSelectionQueryParams(query: SelectionResultsQuery) {
|
|
const params = new URLSearchParams({
|
|
page: String(query.page),
|
|
page_size: String(query.pageSize),
|
|
})
|
|
if (query.search) params.set("search", query.search)
|
|
if (query.category) params.set("category", query.category)
|
|
if (query.sort) params.set("sort", query.sort)
|
|
return params
|
|
}
|
|
|
|
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,
|
|
})
|
|
}
|