Giter Club home page Giter Club logo

quickfix-python-samples's Introduction

QuickFIX Python Samples

Requirements

Installing Requirements

pip install -r requirements.txt

Run Project

With Docker

Please edit file initiator/client.cfg: Tag SocketConnectHost=acceptor

cd ./docker
docker-compose up --build

Without Docker

Please edit file initiator/client.cfg: Tag SocketConnectHost=127.0.0.1
You must launch the server side first, then launch the client side for the quickfix to establish a standard FIX protocol connection.

Run Server

cd ./acceptor
python server.py server.cfg

Run Client

cd ./initiator
python client.py client.cfg

quickfix-python-samples's People

Contributors

henryurlo avatar rinleit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

quickfix-python-samples's Issues

Executing mock order

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?

implementing executor.py to provide execution report

Per out previous discussion on execution report implementation I tried the quickfix github documentation. I was hoping if you have a moment you might be able to assist me in bridging the provided acceptor with an active fix session that I am connected to.

I am trying to implement executor.py to provide execution report details for orders I am passing to the exchange and market data requests. I have a successful session connection with the exchange on a UAT session. I place an order successfully and run python executor.py executor.cfg in a seperate terminal to try to capture the return message but nothing happens:

U:\quickfix-python-samples\initiator>python executor.py executor.cfg
<20210520-15:07:49.000000000, FIX.4.2:KWESTFUT42->WELLSFUT42, event>
(Created session)

This is my config file:
[DEFAULT]
DefaultApplVerID=FIX.4.2
FileStorePath=./Sessions/
ConnectionType=acceptor
StartTime=00:00:00
EndTime=00:00:00
ReconnectInterval=5
ValidOrderTypes=1,2,F
SenderCompID=******
TargetCompID=******
UseDataDictionary=Y
DefaultMarketPrice=12.30

[SESSION]
BeginString=FIX.4.2
SocketAcceptPort=9000
DataDictionary=./spec/FIX42.xml
FileLogPath=./Logs/
FileStorePath=./Sessions/
SenderCompID=******
TargetCompID=******
DeliverToCompID=******
HeartBtInt=30
SocketConnectPort=******
SocketConnectHost=******

executor.py:
import sys
import time
import quickfix as fix

class Application(fix.Application):
orderID = 0
execID = 0

def onCreate(self, sessionID): return
def onLogon(self, sessionID): return
def onLogout(self, sessionID): return
def toAdmin(self, sessionID, message): return
def fromAdmin(self, sessionID, message): return
def toApp(self, sessionID, message): return
def fromApp(self, message, sessionID):
	beginString = fix.BeginString()
	msgType = fix.MsgType()
	message.getHeader().getField( beginString )
	message.getHeader().getField( msgType )

	symbol = fix.Symbol()
	side = fix.Side()
	ordType = fix.OrdType()
	orderQty = fix.OrderQty()
	price = fix.Price()
	clOrdID = fix.ClOrdID()

	message.getField( ordType )
	if ordType.getValue() != fix.OrdType_LIMIT:
		raise fix.IncorrectTagValue( ordType.getField() )

	message.getField( symbol )
	message.getField( side )
	message.getField( orderQty )
	message.getField( price )
	message.getField( clOrdID )

	executionReport = fix.Message()
	executionReport.getHeader().setField( beginString )
	executionReport.getHeader().setField( fix.MsgType(fix.MsgType_ExecutionReport) )

	executionReport.setField( fix.OrderID(self.genOrderID()) )
	executionReport.setField( fix.ExecID(self.genExecID()) )
	executionReport.setField( fix.OrdStatus(fix.OrdStatus_FILLED) )
	executionReport.setField( symbol )
	executionReport.setField( side )
	executionReport.setField( fix.CumQty(orderQty.getValue()) )
	executionReport.setField( fix.AvgPx(price.getValue()) )
	executionReport.setField( fix.LastShares(orderQty.getValue()) )
	executionReport.setField( fix.LastPx(price.getValue()) )
	executionReport.setField( clOrdID )
	executionReport.setField( orderQty )

	if beginString.getValue() == fix.BeginString_FIX40 or beginString.getValue() == fix.BeginString_FIX41 or beginString.getValue() == fix.BeginString_FIX42:
		executionReport.setField( fix.ExecTransType(fix.ExecTransType_NEW) )

	if beginString.getValue() >= fix.BeginString_FIX41:
		executionReport.setField( fix.ExecType(fix.ExecType_FILL) )
		executionReport.setField( fix.LeavesQty(0) )

	try:
		fix.Session.sendToTarget( executionReport, sessionID )
	except fix.SessionNotFound as e:
		return

def genOrderID(self):
	self.orderID = self.orderID+1
	return self.orderID
def genExecID(self):
	self.execID = self.execID+1
	return self.execID

try:
file = sys.argv[1]
settings = fix.SessionSettings( file )
application = Application()
storeFactory = fix.FileStoreFactory( settings )
logFactory = fix.ScreenLogFactory( settings )
acceptor = fix.SocketAcceptor( application, storeFactory, settings, logFactory )
acceptor.start()

while 1:
      time.sleep(1)

except (fix.ConfigError, fix.RuntimeError) as e:
print(e)

Can you assist me in implementing a successful execution report to pair with my client?

I am attaching the code for the client here:

#!/usr/bin/env python

import configparser
import logging
from time import sleep

import click
from modules.client import (Client, delete_order, fix, new_order,
replace_order, send)
from modules.utils import setup_logging

@click.command(
context_settings=dict(help_option_names=["-h", "--help"]),
options_metavar="[options...]",
)
@click.argument(
"client_config", type=click.Path(exists=True), metavar="[client config]"
)
@click.option(
"-d",
"--debug",
is_flag=True,
default=False,
show_default=True,
help="Print debug messages.",
)
def main(client_config="configs/client1.cfg", debug=None):
"""FIX client

Sends new order over a FIX session.

"""
if debug:
logger.setLevel(logging.DEBUG)
logger.info(f"Logging set to debug.")
else:
logger.setLevel(logging.INFO)
logger.info(f"Logging set to info.")

config = configparser.ConfigParser()

config.read(client_config)

sender_compid = config["SESSION"]["SenderCompID"]
target_compid = config["SESSION"]["TargetCompID"]

settings = fix.SessionSettings(client_config)
store = fix.FileStoreFactory(settings)
app = Client()

app.set_logging(logger)

initiator = fix.SocketInitiator(app, store, settings)

initiator.start()

sleep(1)

while True:
try:
sleep(1)
choice = int(
input(
"Enter choice :- "
"\n1. New order"
"\n2. Replace order"
"\n3. Delete order"
"\n> "
)
)
if choice == 1:
print("Enter order :- ")
symbol = input("Symbol: ")
price = input("Price: ")
quantity = input("Quantity: ")
side = input("Side: ")
order_type = input("Type: ")

        message = new_order(
            sender_compid,
            target_compid,
            symbol,
            quantity,
            price,
            side,
            order_type,
        )

        print("Sending new order...")
        send(message)
    elif choice == 2:
        order_id = input("Enter OrderID: ")
        price = input("Price: ")
        quantity = input("Quantity: ")

        message = replace_order(
            sender_compid, target_compid, quantity, price, order_id
        )

        print("Sending replace order...")
        send(message)
    elif choice == 3:
        order_id = input("Enter OrderID: ")

        message = delete_order(sender_compid, target_compid, order_id)

        print("Sending delete order...")
        send(message)

except KeyboardInterrupt:
    initiator.stop()
    print("Goodbye... !\n")

if name == "main":
logger = setup_logging("logs/", "client")
main()

ExecType_FILL not valid in execution report

ExecType_FILL is used in the execution report.

if beginString.getValue() >= fix.BeginString_FIX41:
            executionReport.setField( fix.ExecType(fix.ExecType_FILL) )
            executionReport.setField( fix.LeavesQty(0) )

But this field value is not included in the FIX4.4 spec:

<field number='150' name='ExecType' type='CHAR'>
   <value enum='0' description='NEW' />
   <value enum='3' description='DONE_FOR_DAY' />
   <value enum='4' description='CANCELED' />
   <value enum='5' description='REPLACE' />
   <value enum='6' description='PENDING_CANCEL' />
   <value enum='7' description='STOPPED' />
   <value enum='8' description='REJECTED' />
   <value enum='9' description='SUSPENDED' />
   <value enum='A' description='PENDING_NEW' />
   <value enum='B' description='CALCULATED' />
   <value enum='C' description='EXPIRED' />
   <value enum='D' description='RESTATED' />
   <value enum='E' description='PENDING_REPLACE' />
   <value enum='F' description='TRADE' />
   <value enum='G' description='TRADE_CORRECT' />
   <value enum='H' description='TRADE_CANCEL' />
   <value enum='I' description='ORDER_STATUS' />
  </field>

Is this intended?

ValueError: invalid null reference in 'Session_sendToTarget'

Hi! When I run the application, I get an error.
Before running the fix.Session.sendToTarget(message, self.sessionID), I've printed the self.sessionID and I've got None value. When does the sessionID changes after assigning sessionID=None in Application class?
I'm getting the following error:

Traceback (most recent call last):
File "client.py", line 30, in
main(args.file_name)
File "client.py", line 17, in main
application.run()
File "/home/ubuntu/test/quickfix-python-samples/initiator/application.py", line 89, in run
self.put_new_order()
File "/home/ubuntu/test/quickfix-python-samples/initiator/application.py", line 82, in put_new_order
fix.Session.sendToTarget(message, self.sessionID)
ValueError: invalid null reference in method 'Session_sendToTarget', argument 2 of type 'FIX::SessionID const &'
Segmentation fault (core dumped)

'Application' object has no attribute 'sessionID'

Hi, I am trying to run the application and receive this error.

Traceback (most recent call last):
File "client.py", line 29, in
main(args.file_name)
File "client.py", line 17, in main
application.run()
File "C:\Users\Admin\Downloads\quickfix-python-samples-master\initiator\application.py", line 87, in run
if options == '1':
File "C:\Users\Admin\Downloads\quickfix-python-samples-master\initiator\application.py", line 80, in put_new_order

File "C:\ProgramData\Anaconda3\lib\site-packages\quickfix.py", line 39558, in
getattr = lambda self, name: _swig_getattr(self, Application, name)
File "C:\ProgramData\Anaconda3\lib\site-packages\quickfix.py", line 83, in _swig_getattr
raise AttributeError("'%s' object has no attribute '%s'" % (class_type.name, name))
AttributeError: 'Application' object has no attribute 'sessionID'
(base) PS C:\Users\Admin\Downloads\quickfix-python-samples-master\initiator>

Could you please kindly help me out with this error?

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.