export type CreateApiOrdersTradeArgs = {accountId: string, body: {orderId?: string | undefined}}; export type CreateApiOrdersTradeOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create an order * * POST /orders/trade */ export const createApiOrdersTrade = async (args: CreateApiOrdersTradeArgs, options?: CreateApiOrdersTradeOptions) => { const {baseUrl = "https://api.equalsmoney.com/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.accountId != null) query.append("accountId", String(args.accountId)) const url = `${baseUrl.replace(/\/+$/, '')}/orders/trade${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };