/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { catchUnrecognizedEnum, OpenEnum, Unrecognized, } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { OptionOrderLegExecution, OptionOrderLegExecution$inboundSchema, OptionOrderLegExecution$Outbound, OptionOrderLegExecution$outboundSchema, } from "./optionorderlegexecution.js"; /** * The type of the asset in this option order leg. Orders with only a single leg may only contain an OPTION asset type. Orders with multiple legs must contain at least one OPTION leg, and no more than one EQUITY leg. */ export enum OptionOrderLegAssetType { Equity = "EQUITY", Option = "OPTION", } /** * The type of the asset in this option order leg. Orders with only a single leg may only contain an OPTION asset type. Orders with multiple legs must contain at least one OPTION leg, and no more than one EQUITY leg. */ export type OptionOrderLegAssetTypeOpen = OpenEnum< typeof OptionOrderLegAssetType >; /** * The computed average price for this leg, which is a weighted average (by quantity) of the executed prices. */ export type AveragePrice = { /** * The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details */ value?: string | undefined; }; /** * The computed direction for this leg. When `side` is BUY, `direction` will be DEBIT. When `side` is SELL, `direction` will be CREDIT. */ export enum OptionOrderLegDirection { DebitCreditTypeUnspecified = "DEBIT_CREDIT_TYPE_UNSPECIFIED", Debit = "DEBIT", Credit = "CREDIT", } /** * The computed direction for this leg. When `side` is BUY, `direction` will be DEBIT. When `side` is SELL, `direction` will be CREDIT. */ export type OptionOrderLegDirectionOpen = OpenEnum< typeof OptionOrderLegDirection >; /** * The format of the identifier value used to look up the security. When `asset_type` is OPTION, the identifier_type must be OSI. */ export enum OptionOrderLegIdentifierType { LegIdentifierTypeUnspecified = "LEG_IDENTIFIER_TYPE_UNSPECIFIED", Osi = "OSI", } /** * The format of the identifier value used to look up the security. When `asset_type` is OPTION, the identifier_type must be OSI. */ export type OptionOrderLegIdentifierTypeOpen = OpenEnum< typeof OptionOrderLegIdentifierType >; /** * The side of the option order to be sent to the market. */ export enum OptionOrderLegSide { SideUnspecified = "SIDE_UNSPECIFIED", Buy = "BUY", Sell = "SELL", } /** * The side of the option order to be sent to the market. */ export type OptionOrderLegSideOpen = OpenEnum; /** * The open/close modification of the side, signaling whether this option order leg intends to OPEN a new position, or to CLOSE an existing one. */ export enum OptionOrderLegSideModifier { SideModifierUnspecified = "SIDE_MODIFIER_UNSPECIFIED", Open = "OPEN", Close = "CLOSE", } /** * The open/close modification of the side, signaling whether this option order leg intends to OPEN a new position, or to CLOSE an existing one. */ export type OptionOrderLegSideModifierOpen = OpenEnum< typeof OptionOrderLegSideModifier >; /** * The message describing an option order leg. */ export type OptionOrderLeg = { /** * The unique identifier of the asset in the Apex system. If the requested identifier does not match any known Apex asset, then this field will not be set. */ assetId?: string | undefined; /** * The type of the asset in this option order leg. Orders with only a single leg may only contain an OPTION asset type. Orders with multiple legs must contain at least one OPTION leg, and no more than one EQUITY leg. */ assetType?: OptionOrderLegAssetTypeOpen | undefined; /** * The computed average price for this leg, which is a weighted average (by quantity) of the executed prices. */ averagePrice?: AveragePrice | null | undefined; /** * The computed direction for this leg. When `side` is BUY, `direction` will be DEBIT. When `side` is SELL, `direction` will be CREDIT. */ direction?: OptionOrderLegDirectionOpen | undefined; /** * The list of executions contributing to the fill of this leg of the option order. */ executions?: Array | undefined; /** * The identifier of the asset, in the format specified by `identifier_type`. When `identifier_type` is OSI, this field must be a valid OSI identifier, which is between 16 and 21 characters. (This value must not contain any spaces between the symbol and expiry date.) When `identifier_type` is SYMBOL, this field must contain the ticker value of the security, which is between 1 and 6 characters and must conform the same input constraints called out in the non-options single option order API. */ identifier?: string | undefined; /** * The format of the identifier value used to look up the security. When `asset_type` is OPTION, the identifier_type must be OSI. */ identifierType?: OptionOrderLegIdentifierTypeOpen | undefined; /** * This specifies the quantity of security to be ordered in this leg. For a single-leg order, this value must be 1 (one). For a multi-leg order, this value must be greater than zero, and the total number of shares or contracts ordered at the market will be `order.quantity * leg.ratio_quantity`. */ ratioQuantity?: number | undefined; /** * The side of the option order to be sent to the market. */ side?: OptionOrderLegSideOpen | undefined; /** * The open/close modification of the side, signaling whether this option order leg intends to OPEN a new position, or to CLOSE an existing one. */ sideModifier?: OptionOrderLegSideModifierOpen | undefined; }; /** @internal */ export const OptionOrderLegAssetType$inboundSchema: z.ZodType< OptionOrderLegAssetTypeOpen, z.ZodTypeDef, unknown > = z .union([ z.nativeEnum(OptionOrderLegAssetType), z.string().transform(catchUnrecognizedEnum), ]); /** @internal */ export const OptionOrderLegAssetType$outboundSchema: z.ZodType< OptionOrderLegAssetTypeOpen, z.ZodTypeDef, OptionOrderLegAssetTypeOpen > = z.union([ z.nativeEnum(OptionOrderLegAssetType), z.string().and(z.custom>()), ]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace OptionOrderLegAssetType$ { /** @deprecated use `OptionOrderLegAssetType$inboundSchema` instead. */ export const inboundSchema = OptionOrderLegAssetType$inboundSchema; /** @deprecated use `OptionOrderLegAssetType$outboundSchema` instead. */ export const outboundSchema = OptionOrderLegAssetType$outboundSchema; } /** @internal */ export const AveragePrice$inboundSchema: z.ZodType< AveragePrice, z.ZodTypeDef, unknown > = z.object({ value: z.string().optional(), }); /** @internal */ export type AveragePrice$Outbound = { value?: string | undefined; }; /** @internal */ export const AveragePrice$outboundSchema: z.ZodType< AveragePrice$Outbound, z.ZodTypeDef, AveragePrice > = z.object({ value: z.string().optional(), }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace AveragePrice$ { /** @deprecated use `AveragePrice$inboundSchema` instead. */ export const inboundSchema = AveragePrice$inboundSchema; /** @deprecated use `AveragePrice$outboundSchema` instead. */ export const outboundSchema = AveragePrice$outboundSchema; /** @deprecated use `AveragePrice$Outbound` instead. */ export type Outbound = AveragePrice$Outbound; } export function averagePriceToJSON(averagePrice: AveragePrice): string { return JSON.stringify(AveragePrice$outboundSchema.parse(averagePrice)); } export function averagePriceFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => AveragePrice$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'AveragePrice' from JSON`, ); } /** @internal */ export const OptionOrderLegDirection$inboundSchema: z.ZodType< OptionOrderLegDirectionOpen, z.ZodTypeDef, unknown > = z .union([ z.nativeEnum(OptionOrderLegDirection), z.string().transform(catchUnrecognizedEnum), ]); /** @internal */ export const OptionOrderLegDirection$outboundSchema: z.ZodType< OptionOrderLegDirectionOpen, z.ZodTypeDef, OptionOrderLegDirectionOpen > = z.union([ z.nativeEnum(OptionOrderLegDirection), z.string().and(z.custom>()), ]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace OptionOrderLegDirection$ { /** @deprecated use `OptionOrderLegDirection$inboundSchema` instead. */ export const inboundSchema = OptionOrderLegDirection$inboundSchema; /** @deprecated use `OptionOrderLegDirection$outboundSchema` instead. */ export const outboundSchema = OptionOrderLegDirection$outboundSchema; } /** @internal */ export const OptionOrderLegIdentifierType$inboundSchema: z.ZodType< OptionOrderLegIdentifierTypeOpen, z.ZodTypeDef, unknown > = z .union([ z.nativeEnum(OptionOrderLegIdentifierType), z.string().transform(catchUnrecognizedEnum), ]); /** @internal */ export const OptionOrderLegIdentifierType$outboundSchema: z.ZodType< OptionOrderLegIdentifierTypeOpen, z.ZodTypeDef, OptionOrderLegIdentifierTypeOpen > = z.union([ z.nativeEnum(OptionOrderLegIdentifierType), z.string().and(z.custom>()), ]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace OptionOrderLegIdentifierType$ { /** @deprecated use `OptionOrderLegIdentifierType$inboundSchema` instead. */ export const inboundSchema = OptionOrderLegIdentifierType$inboundSchema; /** @deprecated use `OptionOrderLegIdentifierType$outboundSchema` instead. */ export const outboundSchema = OptionOrderLegIdentifierType$outboundSchema; } /** @internal */ export const OptionOrderLegSide$inboundSchema: z.ZodType< OptionOrderLegSideOpen, z.ZodTypeDef, unknown > = z .union([ z.nativeEnum(OptionOrderLegSide), z.string().transform(catchUnrecognizedEnum), ]); /** @internal */ export const OptionOrderLegSide$outboundSchema: z.ZodType< OptionOrderLegSideOpen, z.ZodTypeDef, OptionOrderLegSideOpen > = z.union([ z.nativeEnum(OptionOrderLegSide), z.string().and(z.custom>()), ]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace OptionOrderLegSide$ { /** @deprecated use `OptionOrderLegSide$inboundSchema` instead. */ export const inboundSchema = OptionOrderLegSide$inboundSchema; /** @deprecated use `OptionOrderLegSide$outboundSchema` instead. */ export const outboundSchema = OptionOrderLegSide$outboundSchema; } /** @internal */ export const OptionOrderLegSideModifier$inboundSchema: z.ZodType< OptionOrderLegSideModifierOpen, z.ZodTypeDef, unknown > = z .union([ z.nativeEnum(OptionOrderLegSideModifier), z.string().transform(catchUnrecognizedEnum), ]); /** @internal */ export const OptionOrderLegSideModifier$outboundSchema: z.ZodType< OptionOrderLegSideModifierOpen, z.ZodTypeDef, OptionOrderLegSideModifierOpen > = z.union([ z.nativeEnum(OptionOrderLegSideModifier), z.string().and(z.custom>()), ]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace OptionOrderLegSideModifier$ { /** @deprecated use `OptionOrderLegSideModifier$inboundSchema` instead. */ export const inboundSchema = OptionOrderLegSideModifier$inboundSchema; /** @deprecated use `OptionOrderLegSideModifier$outboundSchema` instead. */ export const outboundSchema = OptionOrderLegSideModifier$outboundSchema; } /** @internal */ export const OptionOrderLeg$inboundSchema: z.ZodType< OptionOrderLeg, z.ZodTypeDef, unknown > = z.object({ asset_id: z.string().optional(), asset_type: OptionOrderLegAssetType$inboundSchema.optional(), average_price: z.nullable(z.lazy(() => AveragePrice$inboundSchema)) .optional(), direction: OptionOrderLegDirection$inboundSchema.optional(), executions: z.array(OptionOrderLegExecution$inboundSchema).optional(), identifier: z.string().optional(), identifier_type: OptionOrderLegIdentifierType$inboundSchema.optional(), ratio_quantity: z.number().int().optional(), side: OptionOrderLegSide$inboundSchema.optional(), side_modifier: OptionOrderLegSideModifier$inboundSchema.optional(), }).transform((v) => { return remap$(v, { "asset_id": "assetId", "asset_type": "assetType", "average_price": "averagePrice", "identifier_type": "identifierType", "ratio_quantity": "ratioQuantity", "side_modifier": "sideModifier", }); }); /** @internal */ export type OptionOrderLeg$Outbound = { asset_id?: string | undefined; asset_type?: string | undefined; average_price?: AveragePrice$Outbound | null | undefined; direction?: string | undefined; executions?: Array | undefined; identifier?: string | undefined; identifier_type?: string | undefined; ratio_quantity?: number | undefined; side?: string | undefined; side_modifier?: string | undefined; }; /** @internal */ export const OptionOrderLeg$outboundSchema: z.ZodType< OptionOrderLeg$Outbound, z.ZodTypeDef, OptionOrderLeg > = z.object({ assetId: z.string().optional(), assetType: OptionOrderLegAssetType$outboundSchema.optional(), averagePrice: z.nullable(z.lazy(() => AveragePrice$outboundSchema)) .optional(), direction: OptionOrderLegDirection$outboundSchema.optional(), executions: z.array(OptionOrderLegExecution$outboundSchema).optional(), identifier: z.string().optional(), identifierType: OptionOrderLegIdentifierType$outboundSchema.optional(), ratioQuantity: z.number().int().optional(), side: OptionOrderLegSide$outboundSchema.optional(), sideModifier: OptionOrderLegSideModifier$outboundSchema.optional(), }).transform((v) => { return remap$(v, { assetId: "asset_id", assetType: "asset_type", averagePrice: "average_price", identifierType: "identifier_type", ratioQuantity: "ratio_quantity", sideModifier: "side_modifier", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace OptionOrderLeg$ { /** @deprecated use `OptionOrderLeg$inboundSchema` instead. */ export const inboundSchema = OptionOrderLeg$inboundSchema; /** @deprecated use `OptionOrderLeg$outboundSchema` instead. */ export const outboundSchema = OptionOrderLeg$outboundSchema; /** @deprecated use `OptionOrderLeg$Outbound` instead. */ export type Outbound = OptionOrderLeg$Outbound; } export function optionOrderLegToJSON(optionOrderLeg: OptionOrderLeg): string { return JSON.stringify(OptionOrderLeg$outboundSchema.parse(optionOrderLeg)); } export function optionOrderLegFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OptionOrderLeg$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OptionOrderLeg' from JSON`, ); }