Encoding API

From a tag-keyed message to a framed wire string in dictionary order, plus the byte-accurate framing math — BodyLength and CheckSum over UTF-8 bytes. Generated from @boarteam/fix 0.5.2 as installed; the doc text is the library’s own. Guide: Encoding FIX messages.

encodefunctionsince 0.1.0

function encode(message: EncodeMessage, dictionaries: Dictionary | FixtDictionaries, options?: EncodeOptions): string

Source: packages/fix/src/codec/encode.ts:63

Encode a message into a complete, framed FIX string: fields are emitted in the order the dictionary prescribes for the message (expanding components and repeating groups), then BeginString/BodyLength are prefixed and CheckSum appended.

The framing math is byte-accurate (UTF-8), so non-ASCII values produce spec-correct BodyLength/CheckSum. The function is pure: it reads only the supplied data and the dictionary — no wall-clock, sequence numbers, or comp-ID lookups (supply those in EncodeMessage.fields). Presence/enum validity are not checked here; run validate for that. Throws only on programming errors, never on absent fields: when EncodeMessage.msgType is unknown to the dictionary, or when a numeric value cannot be rendered as a valid FIX value (non-finite, or one that String() would emit in exponent notation — pass such values as pre-formatted strings).

dict may also be a FIXT transport/application pair (FixtDictionaries): the message is then encoded over the pair's merged view — tag 8 carries the transport's FIXT.1.1, session messages take the transport's definitions, and application bodies are wrapped in the transport envelope. A supplied ApplVerID(1128) field (falling back to the pair's defaultApplVerID) routes a resolveApp hook.

ParameterTypeDescription
messageEncodeMessageThe MsgType plus tag-keyed fields and groups to render.
dictionariesDictionary | FixtDictionariesThe dictionary — or FIXT transport/application pair — that prescribes field order.
options?EncodeOptionsOutput separator (EncodeOptions).

Returns stringthe framed message, terminated by a trailing separator.

EncodeMessageinterfacesince 0.1.0

interface EncodeMessage

Source: packages/fix/src/codec/encode.ts:19

The message to encode. Framing tags (8/9/10) are computed and need not be supplied.

  • msgType: string

    The MsgType (tag 35) value.

  • fields?: Record<number, FieldValue>

    Top-level field values, keyed by tag. SendingTime/MsgSeqNum/comp-IDs go here.

  • groups?: Record<number, GroupEntry[]>

    Top-level repeating groups, keyed by counter tag.

EncodeOptionsinterfacesince 0.1.0

interface EncodeOptions

Source: packages/fix/src/codec/encode.ts:29

Options for encode.

  • soh?: string

    Field separator for the output. Defaults to SOH.

GroupEntryinterfacesince 0.1.0

interface GroupEntry

Source: packages/fix/src/codec/encode.ts:11

One entry of a repeating group: its own fields and any nested groups.

  • fields?: Record<number, FieldValue>

    Field values for this entry, keyed by tag.

  • groups?: Record<number, GroupEntry[]>

    Nested groups within this entry, keyed by counter tag.

FieldValuetypesince 0.1.0

type FieldValue = string | number | boolean

Source: packages/fix/src/codec/encode.ts:8

A scalar field value the caller can supply. Booleans map to Y/N.

calculateChecksumfunctionsince 0.1.0

function calculateChecksum(message: string | Uint8Array): string

Source: packages/fix/src/codec/checksum.ts:20

FIX CheckSum (tag 10): the sum of all bytes of the message — from BeginString up to and including the SOH immediately preceding the checksum field — taken modulo 256 and rendered as a zero-padded three-digit string.

The sum is computed over UTF-8 bytes, not JavaScript string code units, so a message containing non-ASCII field values (for example an EncodedText payload) yields a spec-correct checksum. This is the correctness fix over the original implementation, which summed String.prototype.charCodeAt code units.

ParameterTypeDescription
messagestring | Uint8ArrayThe message bytes (or a string, encoded as UTF-8) to checksum.

Returns stringThe checksum as a three-character, zero-padded decimal string ("000""255").

bodyLengthfunctionsince 0.1.0

function bodyLength(body: string | Uint8Array): number

Source: packages/fix/src/codec/checksum.ts:40

FIX BodyLength (tag 9): the number of bytes in the message following the BodyLength field's terminating SOH, up to and including the SOH immediately preceding the CheckSum field.

Measured in UTF-8 bytes, not string length, for the same reason as calculateChecksum.

ParameterTypeDescription
bodystring | Uint8ArrayThe portion of the message the body length covers.

Returns numberThe body length in bytes.