Coder Social home page Coder Social logo

simplefix-go's Introduction

Simple Fix

Generic badge Generic badge Generic badge Generic badge Generic badge

⚠️ This is beta-version. It may contain errors.

Table of content

Table of contents

What is FIX API?

The exhaustive material of FIX API

Installation

Download SimpleFix-Go library

$ go get -u github.com/b2broker/simplefix-go

Install generator if you want to use your own scheme.

$ cd $GOPATH/src/github.com/b2broker/simplefix-go && go install ./...

Generator

Generator create message structures, tag and msg type constants and methods for work with any FIX API.

You can see basic result of Generator working at tests directory. It is short version of FIX 4.4 generated from scheme located in ./source directory.

Simple generating example

fixgen -o=./fix44 -s=./source/fix44.xml -t=./source/types.xml

So, now you have your library code in ./fix44 directory.

Parameters

-o – output directory

-s – path to main XML-scheme, you can see examples in ./source directory

-t – path to XML file with types mapping. This file provides generator information about type casting. FIX protocol has a lot of types, but in Go we should have small set of types for use FIX API.

According to parameters we must have two XML files for make our own library. You can use existing files or modify them as you want.

Getting started

Session Options

This is message builder, field and message tags for session pipelines. This structure will be generated by fixgen command very soon.

// fixgen is your generated fix package

var sessionOpts = session.Opts{
	MessageBuilders: session.MessageBuilders{
		HeaderBuilder:        fixgen.Header{}.New(),
		TrailerBuilder:       fixgen.Trailer{}.New(),
		LogonBuilder:         fixgen.Logon{}.New(),
		LogoutBuilder:        fixgen.Logout{}.New(),
		RejectBuilder:        fixgen.Reject{}.New(),
		HeartbeatBuilder:     fixgen.Heartbeat{}.New(),
		TestRequestBuilder:   fixgen.TestRequest{}.New(),
		ResendRequestBuilder: fixgen.ResendRequest{}.New(),
	},
	Tags: &messages.Tags{
		MsgType:         mustConvToInt(fixgen.FieldMsgType),
		MsgSeqNum:       mustConvToInt(fixgen.FieldMsgSeqNum),
		HeartBtInt:      mustConvToInt(fixgen.FieldHeartBtInt),
		EncryptedMethod: mustConvToInt(fixgen.FieldEncryptMethod),
	},
	AllowedEncryptedMethods: map[string]struct{}{
		fixgen.EnumEncryptMethodNoneother: {},
	},
	SessionErrorCodes: &messages.SessionErrorCodes{
		InvalidTagNumber:            mustConvToInt(fixgen.EnumSessionRejectReasonInvalidtagnumber),
		RequiredTagMissing:          mustConvToInt(fixgen.EnumSessionRejectReasonRequiredtagmissing),
		TagNotDefinedForMessageType: mustConvToInt(fixgen.EnumSessionRejectReasonTagNotDefinedForThisMessageType),
		UndefinedTag:                mustConvToInt(fixgen.EnumSessionRejectReasonUndefinedtag),
		TagSpecialWithoutValue:      mustConvToInt(fixgen.EnumSessionRejectReasonTagspecifiedwithoutavalue),
		IncorrectValue:              mustConvToInt(fixgen.EnumSessionRejectReasonValueisincorrectoutofrangeforthistag),
		IncorrectDataFormatValue:    mustConvToInt(fixgen.EnumSessionRejectReasonIncorrectdataformatforvalue),
		DecryptionProblem:           mustConvToInt(fixgen.EnumSessionRejectReasonDecryptionproblem),
		SignatureProblem:            mustConvToInt(fixgen.EnumSessionRejectReasonSignatureproblem),
		CompIDProblem:               mustConvToInt(fixgen.EnumSessionRejectReasonCompidproblem),
		Other:                       mustConvToInt(fixgen.EnumSessionRejectReasonOther),
	},
}

Starting as client

Initiator is a FIX API client, which connect to an existing server by.

You can see example here.

Starting as server

Acceptor is a listener. It accepts and handles client connections. According to the FIX protocol acceptor could be provider or receiver of data. It means acceptor can send requests to the clients and read data streams of them.

You can see example here.

Customize messages

Custom message field

Session package provides you ready functional for work with default processes of FIX API such as authentication, logout, heartbeats, rejects and typical errors. It means that if you want to customize you default messages such as Logon (A) or Heartbeat (0), you should customize Session structure. There are two ways to do this:

  1. Aggregate existing structure in your new one or just copy and edit it in you client code.

  2. Modify builder for message which you want to change.

How to modify builder?

Standard Session structure accepts MessageBuilders as Opts field. Each of message builders is an interface. So it means you can create your own builder and library will use it as default.

For example, you want to add a new field "CounterPartyID" (tag number 22000) in you Logon message. You modified your XML document by adding new field in 'fields' section and in your Logon message:

<fix>
    . . .
    <messages>
        <message name='Logon' msgcat='admin' msgtype='A'>
            . . .
            <field name='CounterPartyID' required='Y'/>
            ...
        </message>
    </messages>
    . . .
    <fields>
        <field number="22000" name="CounterPartyID" type="STRING"/>
    </fields>
    . . .
</fix>

Then you generated code by fixgen. But you want to fill this fields manually. And this is time for custom builder:

// fixgen is your generated fix package

type CustomLogon struct {
    *fixgen.Logon
}

func (cl *CustomLogon) New() messages.LogonBuilder {
    l := cl.New()
    l.SetFieldCounterParty(os.Getenv("COUNTER_PARTY_ID"))
    return l
}

Now you can use your CustomLogon with new field as LogonBuilder in default FIX API pipelines.

Features

  • Add custom fields to protocol
  • Add custom messages to protocol
  • Add custom types to protocol
  • Features for session pipelines
  • Acceptor (server)
  • Initiator (client)
  • Validation of incoming messages
  • Validation of outgoing messages
  • Mock server with testing data
  • Anything you want Just with submit a new issue

simplefix-go's People

Contributors

azzzak avatar crxfoz avatar sdaf47 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.