An open API service indexing awesome lists of open source software.

https://github.com/zhh2001/fix-protocol

A Go package for mapping FIX protocol field tags to semantic constants. This package defines FIX protocol fields (such as Account, BeginString, CheckSum, ClOrdID, etc.) as Go constants using iota, avoiding hardcoded numeric values in FIX protocol development.
https://github.com/zhh2001/fix-protocol

enum field fix fix-protocol go golang package tag

Last synced: 6 days ago
JSON representation

A Go package for mapping FIX protocol field tags to semantic constants. This package defines FIX protocol fields (such as Account, BeginString, CheckSum, ClOrdID, etc.) as Go constants using iota, avoiding hardcoded numeric values in FIX protocol development.

Awesome Lists containing this project

README

          

# FIX Protocol

[![Go Reference](https://pkg.go.dev/badge/github.com/zhh2001/fix-protocol/v42.svg)](https://pkg.go.dev/github.com/zhh2001/fix-protocol/v42)
[![Go Report Card](https://goreportcard.com/badge/github.com/zhh2001/fix-protocol)](https://goreportcard.com/report/github.com/zhh2001/fix-protocol)
[![GitHub License](https://img.shields.io/github/license/zhh2001/fix-protocol)](https://opensource.org/licenses/MIT)
[![GitHub Release](https://img.shields.io/github/release/zhh2001/fix-protocol)](https://github.com/zhh2001/fix-protocol/releases)
[![GitHub Tag](https://img.shields.io/github/tag/zhh2001/fix-protocol)](https://github.com/zhh2001/fix-protocol/tags)

A Go package for mapping FIX protocol field tags to semantic constants. This package defines FIX protocol fields (such as Account, BeginString, CheckSum, ClOrdID, etc.) as Go constants using iota, avoiding hardcoded numeric values in FIX protocol development. Each constant is accompanied by detailed comments explaining the corresponding FIX field's meaning, usage scenarios, and protocol constraints, which helps to improve code readability, reduce errors, and simplify the maintenance of FIX-related projects (such as trading systems, financial message parsing systems).

## Core Features

1. **Semantic Field Tags**: Defined in `tag.go`, FIX protocol field tags are mapped to named constants via `iota` (e.g., `TagAccount`, `TagBeginString`, `TagCheckSum`), eliminating magic numbers in business code.
2. **Business Enumeration Constants**: Defined in `enum.go`, common FIX protocol enumeration values are encapsulated as named string constants (e.g., `AdvSideBuy`/`AdvSideSell` for advertisement sides, `ExecInstNotHeld`/`ExecInstAON` for execution instructions), avoiding hardcoded string literals and reducing typos.
3. **Detailed Documentation**: Each constant is annotated with clear explanations of its FIX protocol meaning, usage scenarios, and constraints, improving team collaboration efficiency and reducing the cost of understanding the FIX protocol.

## Usage Examples

### Basic Usage: Field Tag Constants

```go
package main

import (
"fmt"

fields "github.com/zhh2001/fix-protocol/v42"
)

func main() {
// Print the numeric value of the FIX BeginString field tag
fmt.Println(fields.TagBeginString) // 8

// Print the numeric value of the FIX Account field tag
fmt.Println(fields.TagAccount) // 1
}

```

### Advanced Usage: Business Enumeration Constants

```go
package main

import (
"fmt"

fields "github.com/zhh2001/fix-protocol/v42"
)

func main() {
// FIX protocol message version string
fmt.Println("FIX Protocol Version:", fields.BeginStringFIX42) // FIX.4.2

// Advertisement side enumeration
fmt.Println("Adv Side - Buy:", fields.AdvSideBuy) // B
fmt.Println("Adv Side - Sell:", fields.AdvSideSell) // S

// Execution instruction enumeration
fmt.Println("Exec Instruction - Not Held:", fields.ExecInstNotHeld) // 1
fmt.Println("Exec Instruction - All or None:", fields.ExecInstAON) // G
fmt.Println("Exec Instruction - Do Not Reduce:", fields.ExecInstDNR) // F
}
```

### Reverse Lookup and Typed Tag

The package also exposes a typed `Tag` with bidirectional lookups — useful
for FIX parsers, loggers, and validators that need to turn raw wire numbers
or human-authored field names into semantic identifiers.

```go
package main

import (
"fmt"

fields "github.com/zhh2001/fix-protocol/v42"
)

func main() {
// Look up a tag by wire number; the second value distinguishes dictionary
// fields from user-defined/vendor-extension tags.
if tag, ok := fields.TagByNumber(35); ok {
fmt.Println(tag) // MsgType(35)
fmt.Println(tag.Name()) // MsgType
}

// Look up a tag by its canonical FIX name (case-sensitive).
if tag, ok := fields.TagByName("OrderQty"); ok {
fmt.Println(tag.Int()) // 38
}

// An unknown tag still stringifies to its numeric form so logs don't drop
// information on custom fields.
fmt.Println(fields.Tag(5001)) // 5001
}
```

## Core File Explanation

| File | Responsibility |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `tag.go` | Defines FIX protocol field tags as `iota` constants (numeric values), with detailed comments for each field. |
| `enum.go` | Defines common FIX protocol enumeration values as string constants, covering transaction sides, execution instructions, commission types, etc. |
| `field.go` | Declares the `Tag` type and lookup helpers (`TagByName`, `TagByNumber`, `AllTags`). |
| `field_names.go` | Generated name/number lookup tables. Regenerate with `go generate ./...` after editing `tag.go`. |

## Advantages

- **Improve Code Readability**: Semantic constants replace hardcoded numbers/strings, making the purpose of FIX-related code self-explanatory.
- **Reduce Development Errors**: Avoid typos and incorrect value usage caused by manual hardcoding.
- **Simplify Project Maintenance**: Centralized management of FIX protocol constants, easy to update and iterate with protocol versions.
- **Lower Learning Costs**: Detailed annotations help developers who are new to the FIX protocol quickly grasp the meaning and usage of each field.

## Notes

1. This package currently targets the **FIX.4.2** protocol version, with the import path suffix /v42 corresponding to the protocol version.
2. All constants are defined as unexported (lowercase) or exported (uppercase) according to Go's visibility rules, and exported constants can be directly used in external projects.
3. The package only provides constant mappings and does not include FIX message parsing, serialization, or other business logic, which can be extended based on actual project needs.