Created
March 2, 2016 20:49
-
-
Save axs/a5ef10a410e2d325fa5c to your computer and use it in GitHub Desktop.
quickfixapp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
[DEFAULT] | |
ConnectionType=initiator | |
ReconnectInterval=60 | |
FileStorePath=store | |
FileLogPath=log | |
StartTime=00:00:00 | |
EndTime=00:00:00 | |
UseDataDictionary=Y | |
DataDictionary=spec/FIX50SP2.xml | |
TransportDataDictionary=spec/FIXT11.xml | |
HttpAcceptPort=9911 | |
ValidateUserDefinedFields=N | |
ResetOnLogout=Y | |
ResetOnLogon=Y | |
DefaultApplVerID=FIX.5.0SP2 | |
# standard config elements | |
[SESSION] | |
# inherit ConnectionType, ReconnectInterval and SenderCompID from default | |
BeginString=FIXT.1.1 | |
SenderCompID=YOUR ID | |
TargetCompID=YOUR PROVIDERS ID | |
SocketConnectHost=fix.test.com | |
SocketConnectPort=11000 | |
HeartBtInt=30 | |
""" | |
import sys | |
import argparse | |
import quickfix as fix | |
class Application(fix.Application): | |
orderID = 0 | |
execID = 0 | |
def gen_ord_id(self): | |
global orderID | |
orderID+=1 | |
return orderID | |
def onCreate(self, sessionID): | |
return | |
def onLogon(self, sessionID): | |
self.sessionID = sessionID | |
print ("Successful Logon to session '%s'." % sessionID.toString()) | |
return | |
def onLogout(self, sessionID): return | |
def toAdmin(self, sessionID, message): | |
print "Sent the Admin following message: %s" % message.toString() | |
return | |
def fromAdmin(self, sessionID, message): | |
print "Received the Admin following message: %s" % message.toString() | |
return | |
def toApp(self, sessionID, message): | |
print "Sent the following message: %s" % message.toString() | |
return | |
def fromApp(self, message, sessionID): | |
print "Received the following message: %s" % message.toString() | |
return | |
def genOrderID(self): | |
self.orderID = self.orderID+1 | |
return `self.orderID` | |
def genExecID(self): | |
self.execID = self.execID+1 | |
return `self.execID` | |
def put_order(self): | |
print("Creating the following order: ") | |
trade = fix.Message() | |
trade.setField(fix.ClOrdID(self.genExecID())) #11=Unique order | |
trade.setField(fix.HandlInst(fix.HandlInst_MANUAL_ORDER_BEST_EXECUTION)) | |
trade.setField(fix.Symbol('SMBL')) | |
trade.setField(fix.Side(fix.Side_BUY)) | |
trade.setField(fix.OrdType(fix.OrdType_LIMIT)) | |
trade.setField(fix.OrderQty(100)) | |
trade.setField(fix.Price(10)) | |
print trade.toString() | |
fix.Session.sendToTarget(trade, self.sessionID) | |
def main(config_file): | |
try: | |
settings = fix.SessionSettings("settings.cfg") | |
application = Application() | |
storeFactory = fix.FileStoreFactory(settings) | |
logFactory = fix.FileLogFactory(settings) | |
initiator = fix.SocketInitiator(application, storeFactory, settings, logFactory) | |
initiator.start() | |
while 1: | |
input = raw_input() | |
if input == '1': | |
print "Putin Order" | |
application.put_order() | |
if input == '2': | |
sys.exit(0) | |
if input == 'd': | |
import pdb | |
pdb.set_trace() | |
else: | |
print "Valid input is 1 for order, 2 for exit" | |
continue | |
except (fix.ConfigError, fix.RuntimeError), e: | |
print e | |
if __name__=='__main__': | |
parser = argparse.ArgumentParser(description='FIX Client') | |
parser.add_argument('file_name', type=str, help='Name of configuration file') | |
args = parser.parse_args() | |
main(args.file_name) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment