rinlevan/quickfix-python-samples

Executing mock order

Closed this issue · 2 comments

I have the client and server functioning properly. Could you kindly walk me through how to execute a sample buy order once the sessions are both initiated?

Hi there,

You can see a sample buy order via website: https://fixparser.targetcompid.com/.
Screenshot 2021-05-14 212049
That website show you full script for a session message send by client and respond by server.
I pick a example for you:

Client: NewOrderSingle - Side Buy Order: MsgType <35> = D (NewOrderSingle) and Side <54> = 1 (Buy)

| 8=FIX.4.1 | 9=103 | 35=D | 34=3 | 49=BANZAI | 52=20121105-23:24:42 | 56=EXEC | 11=1352157882577 | 21=1 | 38=10000 | 40=1 | 54=1 | 55=MSFT | 59=0 | 10=062 |

Server: EXECUTION REPORT MsgType <35> = 8 (ER) and OrderStatus <39> = 0 (NEW)

| 8=FIX.4.1 | 9=139 | 35=8 | 34=3 | 49=EXEC | 52=20121105-23:24:42 | 56=BANZAI | 6=0 | 11=1352157882577 | 14=0 | 17=1 | 20=0 | 31=0| 32=0 | 37=1| 38=10000 | 39=0 | 54=1 | 55=MSFT | 150=2 | 151=0 | 10=059 |

This message report that your order went to exchange system and the order hasn't been executed to fill yet.

A sample client code in python

from quickfix import *

def sendNewOrderSingle(Session):
        message = quickfix.Message();
        header = message.getHeader();

        header.setField(quickfix.BeginString("FIX.4.1"))
        header.setField(quickfix.SenderCompID("BANZAI"))
        header.setField(quickfix.TargetCompID("EXEC"))
        header.setField(quickfix.MsgType("D"))
        message.setField(quickfix.ClOrdID("1352157882577"))
        message.setField(quickfix.Symbol("MSFT"))
        message.setField(quickfix.OrderQty(10000))
        message.setField(quickfix.OrdType(1))
        message.setField(quickfix.Side(1))
        message.setField(quickfix.TimeInForce(0))
        message.setField(quickfix.HandlInst(1))
        message.setField(quickfix.Text("NewOrderSingle"))

        Session.sendToTarget(message)

For execution report, you need processing in server application method and repond to client by FIX message corresponding to the message sent from client.
Note: The common fields you are configed on config.cfg file don't need define in code.
I hope it would help you!

For more info: