Coder Social home page Coder Social logo

dendisuhubdy / fixpp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from abc-arbitrage/fixpp

0.0 1.0 0.0 1.31 MB

fixpp - A modern C++ FIX library

License: MIT License

CMake 0.75% Makefile 0.59% M4 0.58% C++ 86.56% C 0.42% Python 10.49% Shell 0.61%

fixpp's Introduction

Fixpp

Travis Build Status

Fixpp is a modern C++ FIX parser distributed as a header-only library. Fixpp is entirely written in pure C++11 and uses last features of C++11 and C++14 like variadic templates or using aliases. Primary goal of fixpp is to provide an entire type-safe FIX frame parser (visitor) as well as a fully featured serializer.

Fixpp does not aim to be a fully-featured FIX Engine able to connect and receive frames for FIX providers through a TCP or UDP connection. It does not handle any transport at all.

API Usage

using namespace Fix;

Fixpp provides a type-safe API, meaning that everything in the FIX world is represented as a C++ type in the API. For example, a Logon message is represented as an instance of the Fix::v42::Message::Logon class. Also note that FIX versions are represented as sub-namespaces of the root Fix namespace.

Getting/setting fields

Fixpp provides getters and setters to get and set fields inside a specific Message.

Use Fix::set<T> to set fields:

Fix::v42::Message::Logon logon;
Fix::set<Fix::Tag::EncryptMethod>(logon, 0);
Fix::set<Fix::Tag::HeartBtInt>(logon, 60);

Use Fix::get<T> to get fields:

auto heartbeat = Fix::get<Fix::Tag::HeartBtInt>(logon);

Type-safety

As stated above, everything in fixpp is represented as a C++ type. This allows to

  • Check that a tag is valid when attempting to set/get it from a message
  • Check the type validity when attempting to set the value of a tag

For example, attempting to set an invalid value for a tag will trigger a compile-time error through a static assertion

Fix::v42::Message::Logon logon;
Fix::set<Fix::Tag::HeartBtInt>(logon, "60s");
fixpp/include/fixpp/dsl/message.h:116:9: error: static assertion failed: Invalid data type for given Tag

Attempting to retrieve an invalid tag from a Message will also trigger a compile-time error.

Extending messages

While message types provided by fixpp do not provide any custom tags, you can provide your own custom tags by extending existing messages.

using MyTag = Fix::TagT<10876, Fix::Type::Int>;
using MyLogon = Fix::ExtendedMessage<Fix::v42::Message::Logon, MyTag>;

Will define and create a new MyLogon message with a custom MyTag tag. MyTag can then be manipulated through the MyLogon type:

MyLogon logon;
Fix::set<MyTag>(logon, 12);
assert(Fix::get<MyTag>(logon) == 12);

For more complicated customizations of an existing message, Fix::MessageOverwrite<T> can be used. Fix::MessageOverwrite<T> provides a bunch of operations that can be applied to a Message:

  • ChangeType<Tag, NewType> to change the type of an existing tag
  • AddTag<Tag> to add a tag like ExtendedMessage<T>
  • ExtendGroup<GroupTag, Tags...> to extend a specific repeating group
using MyTag = Fix::TagT<10876, Fix::Type::Int>;
using MyGroupTag = Fix::TagT<10676, Fix::Type::String>;

struct MyOverwrite : public Fix::MessageOverwrite<Fix::v42::Message::Logon>
{
    using Changes = ChangeSet<
         ChangeType<Of<Fix::Tag::HeartBtInt>, To<Fix::Type::String>>,
         AddTag<MyTag>,
         ExtendGroup<Fix::Tag::NoMsgTypes, MyGroupTag>
    >;
};

using MyLogon = MyOverwrite::Changes::Apply;

Frame parsing

Fixpp uses the Visitor pattern. If you are familiar with boost::variant or std::variant, fixpp features the exact same pattern. To visit a FIX frame, first define a Callable object that accepts every possible message that you want to handle:

struct MyVisitor
{
     void operator()(const Fix::v42::Header& header, const Fix::v42::Message::Heartbeat& heartbeat)
     {
         // ...
     }
     
     void operator()(const Fix::v42::Header& header, const Fix::v42::Message::MarketDataSnapshot& snapshot)
     {
         // ...
     }
     
     template<typename HeaderT, typename MessageT> void operator()(HeaderT, MessageT)
     {
     }
};

A generic, templated operator() must also be provided. Every non-handled Message will fall through this special overload. This is the equivalent of the default case of a switch case except that it is needed for the visitor to compile correctly.

fixpp's People

Contributors

oktal avatar techabc avatar ybainier avatar

Watchers

 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.