Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FIX protocol in Python - implement login and request for streaming quote

I am trying to implement basic FIX requests with python quickfix (FIX 4.2), however the documentation is sparse for me to understand it fully (and i have done quite a bit of research ,links at the end of the question - so please be assured that its not a question without doing any digging up)

Login request --- A

8=FIX.4.2 | 9=108 | 35=A | 34=1 | 49=ACCOUNTXXX | 52=20161116-00:00:15.281 | 56=CNX | 553=ACCOUNTXXXSTR1 | 554=Stater123 | 98=0 | 108=60 | 141=Y | 10=133 |

this will be the expected Login response

8=FIX.4.2 | 9=77 | 35=A | 49=CNX | 34=1 | 52=20161116-00:00:17.928 | 56= ACCOUNTXXXSTR1 | 98=0 | 108=60 | 141=Y | 10=140 |

Request for live/streaming quote in EUR/USD --- B

8=FIX.4.2 | 9=142 | 35=V | 34=8 | 49=ACCOUNTXXX | 52=20161116-12:19:48.269 | 56=CNX | 146=1 | 55=EUR/USD | 262=2016110213351833862 | 263=2 | 264=1 | 265=1 | 266=Y | 267=2 | 269=0 | 269=1 | 10=110 |

Response will come like this and I need to handle it by keeping a socket/stream open --- STREAM

8=FIX.4.2 | 9=227 | 35=X | 49=CNX | 34=241 | 52=20161116-12:20:03.651 | 56=ACCOUNTXXX | 262=2016110213351834170 | 268=2 | 279=0 | 269=0 | 278=141 | 55=EUR/USD | 270=1.76371 | 15=GBP | 271=1000000 | 346=1 | 279=0 | 269=1 | 278=142 | 55=EUR/USD | 270=1.76406 | 15=GBP | 271=1000000 | 346=1 | 10=223 | 

send heartbeat after every 60 seconds - C

8=FIX.4.2 | 9=59 | 35=0 | 34=3 | 49=ACCOUNTXXX | 52=20161116-00:01:15.868 | 56=CNX | 10=054 |

I wanted a bit of advice and some basic code structure on how to set up the Python code to send A, B, C and open a socket/stream to keep reading the data in STREAM and logging it to console

Where have I looked already?

https://github.com/quickfix/quickfix/blob/master/examples/executor/python/executor.py

https://futures.io/matlab-r-project-python/35213-python-quickfix.html

https://github.com/tianyilai/QuickFix-python-client/tree/master/spec

however, the documentation and the examples are sparse and I am struggling to find my way through Thanks

like image 818
dowjones123 Avatar asked Nov 16 '16 17:11

dowjones123


People also ask

What actually happened in my HTTP request?

This breakdown allows you to explore what actually happened in your HTTP Request. Here’s a quick summary of the information Wireshark describes in the middle row from top to bottom: Physical Layer: This row describes the physical interface used to send the request. In your case, this is probably Interface ID 0 (lo) for your loopback interface.

How do I use the quote request message?

The Quote Request <R> message can be used to request quotes on single products or multiple products. Securities quotes can be requested as either market quotes or for a specific quantity and side. If OrderQty <38> and Side <54> are absent, a market-style quote (bid x offer, size x size) will be returned.

What is the FIX protocol?

FIX (Financial Information eXchange) Protocol is a widely-used, text-based protocol for interaction between parties in financial trading. Banks, brokers, clearing firms, exchanges, and other general market participants use FIX protocol for all phases of electronic trading.

What is a quote request (RFQ)?

In some markets it is the practice to request quotes from brokers prior to placement of an order. The Quote Request <R> message is used for this purpose. This message is commonly referred to as an Request For Quote (RFQ)


1 Answers

A -- a login request is sent automatically by QuickFix when you call initiator.start(). The key bit of documentation you need for this is here, with PYTHON example translation:

import quickfix

if len(sys.argv) <  2: return          # FAIL to have a mandatory number of args
fileName = sys.argv[1]                 # .SET fileName ( a configuration file )

try:
        settings     = quickfix.SessionSettings( fileName )
        application  = quickfix.MyApplication()
        storeFactory = quickfix.FileStoreFactory( settings )
        logFactory   = quickfix.FileLogFactory(   settings )
        acceptor     = quickfix.SocketAcceptor(   application, storeFactory, settings, logFactory )
        #                      .SocketInitiator( ... )  # Ref. below
        acceptor.start() #-------------------------------

        # while condition == true: do something
        #
        # pass; # onEoLife:

        acceptor.stop() #--------------------------------

except quickfix.ConfigError, e:
        print e

( Cit.: ) ... sample code above shows how you might start up a FIX-protocol acceptor which listens on a socket. ...
If you rather wanted an initiator ( to setup a session from your side ) you would replace the acceptor in this code fragment with a SocketInitiator.

The line settings = quickfix.SessionSettings(fileName) loads the configuration file, and many of the key fields are taken from there. See config file docs.

B -- In order to request live data you need to send a 35=V message to your counterparty. In order to do this, you define a MarketDataRequest message, which has some variables, and you send that message to your counterparty. See here. Pay attention though, I think that the documentation is wrong here and to send the mssage you need to call fix.Session_sendToTarget(message).

C -- You don't need to worry about this, QuickFix handles heartbeats and logging back on after disconnects etc. automatically. You set the heartbeat interval (e.g. 60 seconds) in the config file fileName. See config file docs.

like image 81
Wapiti Avatar answered Oct 18 '22 20:10

Wapiti