Python and QuickFIX - Matlab, R project and Python | futures io social day trading
futures io futures trading


Python and QuickFIX
Updated: Views / Replies:11,986 / 39
Created: by Branzol Attachments:1

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 1  
 
Thread Tools Search this Thread
 

Python and QuickFIX

  #21 (permalink)
Trading Apprentice
London + England/UK
 
Futures Experience: Intermediate
Platform: NP3
Favorite Futures: gold
 
Posts: 9 since May 2015
Thanks: 1 given, 3 received


pearljam100 View Post
Thanks for the reply, I will give it a try and see what happens

From what i can see so far:

In initiator.py I have done the following (playing around with settings)

trade.getHeader().setField(fix.TransactTime())
trade.getHeader().setField(fix.TradeDate())
.....
.....
.....
trade.setField(fix.StringField(60,(datetime.utcnow ().strftime ("%Y%m%d-%H:%M:%S.%f"))[:-3]))
trade.setField(fix.StringField(75,(datetime.utcnow ().strftime ("%Y%m%d"))))

acceptor now ok but I get following:
(8=FIX.4.29=15935=D34=249=BANZAI52=20150602-10:04:14.15456=FIXSIM60=20150602-10:04:1475=11=121=338=10040=244=1054=155=VOD.L60=20150602-10:04:14.15475=2015060210=222)
<20150602-10:04:14.154, FIX.4.2:FIXSIM->BANZAI, event>
(Message 2 Rejected: Tag appears more than once:60)

which makes sense....

<20150602-10:04:14.154, FIX.4.2:FIXSIM->BANZAI, outgoing>
(8=FIX.4.29=10335=334=249=FIXSIM52=20150602-10:04:14.15456=BANZAI45=258=Tag appears more than once371=60372=D10=231)

To avoid duplicates....

If I comment:
#trade.getHeader().setField(fix.TransactTime())
#trade.getHeader().setField(fix.TradeDate())

but keep
trade.setField(fix.StringField(60,(datetime.utcnow ().strftime ("%Y%m%d-%H:%M:%S.%f"))[:-3]))
trade.setField(fix.StringField(75,(datetime.utcnow ().strftime ("%Y%m%d"))))

OR

trade.getHeader().setField(fix.StringField(60,(datetime.utcnow ().strftime ("%Y%m%d-%H:%M:%S.%f"))[:-3]))
trade.getHeader().setField(fix.StringField(75,(datetime.utcnow ().strftime ("%Y%m%d"))))

#trade.setField(fix.StringField(60,(datetime.utcnow ().strftime ("%Y%m%d-%H:%M:%S.%f"))[:-3]))
#trade.setField(fix.StringField(75,(datetime.utcnow ().strftime ("%Y%m%d"))))


I get err in acceptor.py:
Traceback (most recent call last):
File "acceptor.py", line 48, in fromApp
executionReport.setField( fix.OrderID(self.genOrderID()) )
File "C:\Users\jsainz\AppData\Local\Continuum\Anaconda\lib\site-packages\quickfix.py", line 37611, in __init__
quickfix.StringField.__init__(self, 37, data)
File "C:\Users\jsainz\AppData\Local\Continuum\Anaconda\lib\site-packages\quickfix.py", line 678, in __init__
this = _quickfix.new_StringField(*args)
NotImplementedError: Wrong number or type of arguments for overloaded function 'new_StringField'.
Possible C/C++ prototypes are:
FIX::StringField::StringField(int,std::string const &)
FIX::StringField::StringField(int)


So, Im stuck...just not sure what to change here...thanks for any advice

Reply With Quote
 
  #22 (permalink)
Elite Member
Baltimore Maryland/United States
 
Futures Experience: Advanced
Platform: Custom
Broker/Data: IB
Favorite Futures: Asian Stocks / Indexes
 
Branzol's Avatar
 
Posts: 39 since May 2014
Thanks: 43 given, 60 received


pearljam100 View Post
So, Im stuck...just not sure what to change here...thanks for any advice

I have some time this week, I'll take a look at this. I've been on vacation, so sorry for the delay have not been responding to much on here. Going to attempt to recreate exactly what you have going on and we can go from there. Being that you use the acceptor and initiator I'll have to set that up as I only use it as an initiator in my solution. Shooting to have you some answers by Thursday with my current schedule.

Reply With Quote
The following user says Thank You to Branzol for this post:
 
  #23 (permalink)
Trading Apprentice
New York
 
Futures Experience: None
Platform: TradeStation
Favorite Futures: stocks
 
Posts: 1 since Aug 2015
Thanks: 0 given, 0 received

Getting no messages from the fromApp method


Hi Branzol,

This is a helpful thread.

I am able to connect via quickfix python and see heartbeats but I do not see any actual execution messages coming through the "fromApp" method and don't see any errors thrown. Do you have any suggestions as to why that might be the case?

Regards,

JC

Reply With Quote
 
  #24 (permalink)
Trading Apprentice
London + England/UK
 
Futures Experience: Intermediate
Platform: NP3
Favorite Futures: gold
 
Posts: 9 since May 2015
Thanks: 1 given, 3 received

Got this to work and thanks for all your help on it....

changes I made:


initiator
trade.setField(fix.StringField(60,(datetime.utcnow ().strftime ("%Y%m%d-%H:%M:%S.%f"))[:-3]))
trade.setField(fix.StringField(75,(datetime.utcnow ().strftime ("%Y%m%d"))))

acceptor
def genOrderID(self):
self.orderID = self.orderID+1
return str(self.orderID)
def genExecID(self):
self.execID = self.execID+1
return str(self.execID)
all looks good:
1
Putin Order
Creating the following order:
Sent the following message: FIX.4.2:BANZAI->FIXSIM
Received the following message: 8=FIX.4.29=21435=834=449=FIXSIM52=20150904-16:59:59.97856=BANZAI6=21911=214=1000000000017=220=031=21932=1000000000037=238=1000000000039=254=155=VOD.L60=20150904-16:59:59.97675=20150904-16:59:59.976150=2151=010=039
2
Putin Order
Creating the following order:
Sent the following message: FIX.4.2:BANZAI->FIXSIM
Received the following message: 8=FIX.4.29=21435=834=549=FIXSIM52=20150904-17:00:00.79556=BANZAI6=21911=314=1000000000017=320=031=21932=1000000000037=338=1000000000039=254=255=VOD.L60=20150904-17:00:00.79375=20150904-17:00:00.793150=2151=010=210


Reply With Quote
 
  #25 (permalink)
Trading Apprentice
London + England/UK
 
Futures Experience: Intermediate
Platform: NP3
Favorite Futures: gold
 
Posts: 9 since May 2015
Thanks: 1 given, 3 received

Python Quickfix

My experience and hopefully this helps anyone trying this...

1. To easily install Quickfix i.e. "import quickfix as fix" and i had no issues to get it to work. I used wheels *.whl, Unofficial Windows Binaries for Python Extension Packages. I did not use pip install.

2. I read and read and found QuickFIX/n - Configuration very useful. Most people will use FIX to send orders and listen to get fills in my idea. Therefore, you are the Initiator i.e. the client and not the acceptor. Yet, it is very useful to start learning both acceptor (server) and initiator and how the two talk to each other.

3. Branzol's attachment is perfect to understand it. At first, it seems, whjat? i have no idea what is happening but basically in this case you are both acceptor and initiator. Play around with it and read the C++ errors to get Transaction date in right format, ClOrdIds as strings, etc. How the code is written comes from QuickFIX Documentation and examples on sending new orders, cancels, and how to listen to acks.

4. Hardest part in my opinion will be config files and that is just trial and error but again loads of examples.

Hope this helps because it took me quite a while but it can be done.

Good luck

Reply With Quote
The following 2 users say Thank You to pearljam100 for this post:
 
  #26 (permalink)
Trading Apprentice
London
 
Futures Experience: Intermediate
Platform: TS
Favorite Futures: ccy
 
Posts: 4 since Oct 2015
Thanks: 4 given, 0 received


Branzol View Post
I have some time this week, I'll take a look at this. I've been on vacation, so sorry for the delay have not been responding to much on here. Going to attempt to recreate exactly what you have going on and we can go from there. Being that you use the acceptor and initiator I'll have to set that up as I only use it as an initiator in my solution. Shooting to have you some answers by Thursday with my current schedule.

Hi Branzol,

Brand new to this, earlier you said that initiator is us, and acceptor is the exchange, so by running acceptor, we are just simulating the fix server right?

I am using pycharm, anyone know how to run a .py with an argument in pycharm?

Many thanks in advance,
kr

Reply With Quote
 
  #27 (permalink)
Administrator: Retired Backtester
 Vendor: speedytradingservers.com 
Rennes France
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: IB/Kinetick
Favorite Futures: Futures
 
sam028's Avatar
 
Posts: 3,346 since Jun 2009
Thanks: 3,554 given, 3,964 received


krive12 View Post
Hi Branzol,

Brand new to this, earlier you said that initiator is us, and acceptor is the exchange, so by running acceptor, we are just simulating the fix server right?

I am using pycharm, anyone know how to run a .py with an argument in pycharm?

Many thanks in advance,
kr

In PyCharm: Run -> Edit Configurations... -> Script Parameters:

Success requires no deodorant! (Sun Tzu)
Reply With Quote
The following 2 users say Thank You to sam028 for this post:
 
  #28 (permalink)
Trading Apprentice
London
 
Futures Experience: Intermediate
Platform: TS
Favorite Futures: ccy
 
Posts: 4 since Oct 2015
Thanks: 4 given, 0 received


sam028 View Post
In PyCharm: Run -> Edit Configurations... -> Script Parameters:


Thank you Sam028! it worked, and when i try to do it again, acceptor.py gave an error

EDIT: solved


Last edited by krive12; October 30th, 2015 at 05:28 PM.
Reply With Quote
 
  #29 (permalink)
Trading Apprentice
London
 
Futures Experience: Intermediate
Platform: TS
Favorite Futures: ccy
 
Posts: 4 since Oct 2015
Thanks: 4 given, 0 received

Hi Branzol,

thank you for this - finally figured out that if i have a FIX access, i should be using this code instead of the zip file.

When i run the code below, the log file just showed "Created Session" and nothing else, and nothing written in the Message log file. I have seen what it is supposed to contain in the zip file program that you very kindly attached a couple of posts down.

Did i miss anything? I have looked at the settings.cfg and linked to the correct xml file.

Thank you in advance!


Branzol View Post
After searching what now feels like the entire web for a proper example, I was able to find a handful of examples that did not work and were riddle with errors. I tore a few of them apart, and would love to give credit to the original creators, but at this point I don't know what came from what.

The basic code I'm posting below will make a connection, and give you a option to place an order. You can switch out the order message for any type of FIX compliant message. At that point just take a FIX message format, and send the message in that manner. I've tried the Market-Data requests and they are working now. When I finish my final code of allowing you to enter a symbol list, and start streaming data to a database. And external input from my other scripts for automated ordering and closing of orders I'll post that.

I just wanted to ensure anyone else who's having issues with QuickFIX and Python has a good starting point.

 
Code
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)
You'll also need the system "settings.cfg" file in the same directory as the script. Here's an example one I deleted out my information and put generic items.

 
Code
[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


Reply With Quote
 
  #30 (permalink)
Trading Apprentice
Bangkok
 
Futures Experience: Intermediate
Platform: OldSchool
Favorite Futures: FX
 
Posts: 1 since Mar 2016
Thanks: 0 given, 0 received

Wow, i'm so happy to find this thread!


Thank you to you all for the improvements and especially to Branzol for posting up the zip files which i'm working my way through now.

I managed to establish a fix connection many a year ago with a broking house which was super useful, but now i'm trying to make my simple webserver online respond to basic client pricing requests all using python. Nothing too time sensitive. I thought fix was a good way to go but now i'm not too sure! I'm pondering if i should just go back to POST on HTTP!

Anyway i've got this example running under a virtualenv (installed QuickFix using PIP seems okay)
I start the session with the acceptor.py and that works fine.
Next i try $python initiator.py initiatorsettings.cfg but i get the following back...

Runtime error: Unable to create, bind, or listen to port 9911

Excuse my low level of programming as i'm poor hack at best. Any suggestions or help would be greatly appreciated...
Thank you and best of luck to you all in the future.

Reply With Quote

Reply



futures io > > > > Python and QuickFIX

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

FuturesTrader71: TBA

Elite only

Al Brooks: TBA

Elite only

Jigsaw Trading: TBA

Oct 19

RandBots: TBA

Oct 24
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
CQG API and Python Branzol Elite Automated Trading 2 December 6th, 2016 08:37 PM
IB with Python jamesico Matlab, R project and Python 2 September 9th, 2014 07:19 AM
Tradier with R and or Python Keith Leesus Matlab, R project and Python 2 September 5th, 2014 12:23 AM
Python Help Wanted $ wlblount Hire a Consultant or Programmer 0 December 25th, 2013 09:14 AM
QuickFIX "layer" for Ninja? heech NinjaTrader Programming 11 April 8th, 2010 08:44 PM


All times are GMT -4. The time now is 03:12 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-09-26 in 0.09 seconds with 19 queries on phoenix via your IP 54.162.10.211