Coder Social home page Coder Social logo

erfaniaa / fix-protocol Goto Github PK

View Code? Open in Web Editor NEW
27.0 3.0 6.0 104 KB

FIX 4.4 session layer implementation for a single pair of initiator (client) and acceptor (server) over TCP

License: GNU General Public License v3.0

C++ 99.82% C 0.18%
cplusplus cpp finance financial financial-markets fix-protocol fixprotocol network socket-programming asio boost data-structures tcp

fix-protocol's Introduction

FIX Protocol

FIX 4.4 session layer implementation for a single pair of initiator (client) and acceptor (server) over TCP (might be helpful for educational purposes)

What is FIX?

The Financial Information eXchange (FIX) protocol is an electronic communications protocol initiated in 1992 for international real-time exchange of information related to securities transactions and markets. With trillions of dollars traded annually on the NASDAQ alone, financial service entities are employing direct market access (DMA) to increase their speed to financial markets. Managing the delivery of trading applications and keeping latency low increasingly requires an understanding of the FIX protocol.

Source: English Wikipedia

Basic FIX Timeline

Source: AQUAQ Analytics

Run

  1. Clone this repository.

  2. Install Boost library. For example, on Ubuntu you can run this command:

    sudo apt-get install libboost-all-dev

  3. Compile the source code with g++ with the following commands:

    1. g++ -O2 -std=c++2a -o bin/server.out mainserver.cpp src/* -I include -L lib -lboost_system -lboost_thread -pthread -fconcepts
    2. g++ -O2 -std=c++2a -o bin/client.out maintestclient.cpp src/* -I include -L lib -lboost_system -lboost_thread -pthread -fconcepts
  4. Run the executable files with the following commands:

    1. bin/server.out
    2. bin/client.out

Configuration

  • If you are running server and client from two different machines, set the host and port in include/constants.h.
  • You can change MAX_MESSAGE_LENGTH and MAX_TAGS_COUNT constants in include/constants.h if you want to transmit larger messages.
  • If you want to use Boost Asio for the socket programming part (instead of C++ classic sockets), set USE_BOOST constant to true in include/constants.h.

Notes

  • Instead of using STL vector, I implemented FixedVector class. It uses C++ classic arrays to handle operations exactly in O(1) (while STL vector handles them in amortized O(1)). Also it prevents large amount of memory fragmentations. It is useful when we know that our messages' size is limited.
  • Instead of using STL string, I implemented FixedString class. It uses C++ classic character arrays to handle operations exactly in O(1) (while STL string handles them in amortized O(1)). Also it prevents large amount of memory fragmentations. It is useful when we know that our messages' size is limited.
  • Instead of using STL unordered_map, I implemented LookupTable class. It uses C++ classic arrays to handle operations exactly in O(1). It doesn't need hashing algorithms and linked-lists, so it's faster.
  • According to my research the median/average size of FIX protocol message's length is not greater than 200. So I set MAX_MESSAGE_LENGTH constant to 256.
  • Both classic sockets and Boost Asio sockets have been implemented in this project. You can switch between them easily.
  • I used -O2 flag for optimization.
  • I used unsigned short data type to reduce the memory usage for integer numbers.
  • I used references and pointers in functions' arguments to reduce the memory and time usage.
  • The Session class is commented based on FIX Protocol 4.4 testcases.
  • C++ OOP concepts like abstract classes have been used in this project.

Benchmarking

  1. Run command bin/server.out > server_output.txt.

  2. Run command time bin/client.out > client_output.txt.

    This will send 5000 messages to the server (session acceptor), and receives some messages. It waits for 50 milliseconds before sending each message. In this case, we added 50 * 5000 milliseconds (250 seconds) to the run-time.

    I tested this on a Lenovo Thinkpad P14s Gen 3 laptop, and it took 253.35 seconds. I had added 250 seconds manually, therefore our algorithm took 3.35 seconds to run (for sending 5000 messages and receiving their responses).

To-do

  • Handle the 14th scenario of FIX Protocol 4.4 testcases.
  • Separate configuration constants from FIX protocol constants. Don't store everything in a single include/constants.h file.
  • Use move semantics to improve efficiency.

fix-protocol's People

Contributors

erfaniaa avatar roozbehsayadi avatar

Stargazers

Levi Schwarzman avatar  avatar  avatar Sippakorn Saeiao avatar  avatar Shabbir Hasan avatar hyb avatar Abhimanyu verma avatar harkhuang avatar Sam Taba avatar trumae avatar dhairya avatar Apoorv Anupam avatar  avatar  avatar Mehrshad avatar Amir Masoud Shaker avatar  avatar  avatar  avatar Hamed Zahedifar avatar Dominus Prime avatar  avatar  avatar Reza Paki avatar  avatar Amir avatar

Watchers

trumae avatar  avatar  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.