export type PositionRequestDTO = {comment?: string | undefined, magicNumber?: string | undefined, openPrice: number, orderType: 'Buy' | 'Sell' | 'BuyLimit' | 'SellLimit' | 'BuyStop' | 'SellStop', pendingExpirySeconds?: number | undefined, relativeTpSl?: boolean | undefined, requestId: number, stopLoss: number, symbol: string, takeProfit: number, volume: number}; export type CreateApiRestApiV1AccountsAccountIdOrdersArgs = {accountId: string, body: PositionRequestDTO}; export type CreateApiRestApiV1AccountsAccountIdOrdersOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Send an account order * * POST /rest/api/v1/accounts/{accountId}/orders */ export const createApiRestApiV1AccountsAccountIdOrders = async (args: CreateApiRestApiV1AccountsAccountIdOrdersArgs, options?: CreateApiRestApiV1AccountsAccountIdOrdersOptions) => { const {baseUrl = "https://api.metacopier.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rest/api/v1/accounts/${encodeURIComponent(String(args.accountId))}/orders${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 };