simplefix icon indicating copy to clipboard operation
simplefix copied to clipboard

Add Socket connection?

Open zoakes opened this issue 5 years ago • 27 comments

I've been thinking about adding a socket connection class to a generic FIX IP, was curious if there's anything in beta for this? If not, I'm happy to fork and contribute what I can to it if I have some success -- I was going to connect to IB.

Let me know your thoughts!

Simplefix is INCREDIBLE, so simple -- exactly what I was looking for -- FIX formatting without the overhead mess of QuickFix -- just needs a Socket initiator : )

Zach

zoakes avatar Nov 24 '19 23:11 zoakes

Hi Zach,

At one time I was fairly opposed to this idea. I think it's a slippery slope from adding some sort of socket support, and then maybe some sort of message validation, and suddenly we're back where QuickFIX is.

But I'm maybe less against it than I was, mostly because I think a lot of people end up having to write it themselves, and while that's not terribly hard, it does seem like maybe an off-the-shelf way to do it would be better.

So. This is maybe a little unfair, but I'd kinda be interested in seeing what you come up with, without really promising to merge the PR if I get cold feet. But ... since you're writing it anyway, and since you're kinda volunteering, I'm absolutely happy to look at a PR and work with you on merging it if it seems promising?

da4089 avatar Nov 25 '19 11:11 da4089

Sure. Well mine is very simple, but I’m happy to send.

I have it on a git, in the Socket+ branch (with generic connection now)

https://github.com/zoakes/sFIX-IB/blob/Socket%2B/SFX_Sock.py

Get Outlook for iOShttps://aka.ms/o0ukef


From: David Arnold [email protected] Sent: Monday, November 25, 2019 5:51:27 AM To: da4089/simplefix [email protected] Cc: Zach Mazz [email protected]; Author [email protected] Subject: Re: [da4089/simplefix] Add Socket connection? (#22)

Hi Zach,

At one time I was fairly opposed to this idea. I think it's a slippery slope from adding some sort of socket support, and then maybe some sort of message validation, and suddenly we're back where QuickFIX is.

But I'm maybe less against it than I was, mostly because I think a lot of people end up having to write it themselves, and while that's not terribly hard, it does seem like maybe an off-the-shelf way to do it would be better.

So. This is maybe a little unfair, but I'd kinda be interested in seeing what you come up with, without really promising to merge the PR if I get cold feet. But ... since you're writing it anyway, and since you're kinda volunteering, I'm absolutely happy to look at a PR and work with you on merging it if it seems promising?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fda4089%2Fsimplefix%2Fissues%2F22%3Femail_source%3Dnotifications%26email_token%3DALPUCIEUIL46AETWA7SWCXTQVO337A5CNFSM4JRBVJR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFCEFJY%23issuecomment-558121639&data=02%7C01%7C%7Cdf980eb5c15b4fedf91608d7719dcde3%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637102794878485564&sdata=FqC8p1RV3EcWV1Ec%2Fn9Ttc9XFCvtjOHQLpJA%2Fi3DRnY%3D&reserved=0, or unsubscribehttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FALPUCIEKPYLDVTVDRO6QRYLQVO337ANCNFSM4JRBVJRQ&data=02%7C01%7C%7Cdf980eb5c15b4fedf91608d7719dcde3%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637102794878495563&sdata=MB9bDfg9aRECiuBRO8igHI5E%2Bh3YvCW%2B86GafyIJqRU%3D&reserved=0.

zoakes avatar Nov 25 '19 13:11 zoakes

It’s far from QuickFix haha — I like simple too. QF is just so bloated, and their documentation is terrible. I hate QF.

Also — I realize I need to remove the finally’s to the very bottom to keep connection open (in sendAll) — just was benchmarking and can’t if it’s running continuously.

Goal was the most minimal connection to IB’s FIX protocol.

Zach

Get Outlook for iOShttps://aka.ms/o0ukef


From: Zach Oakes [email protected] Sent: Monday, November 25, 2019 7:36:31 AM To: da4089/simplefix [email protected]; da4089/simplefix [email protected] Cc: Author [email protected] Subject: Re: [da4089/simplefix] Add Socket connection? (#22)

Sure. Well mine is very simple, but I’m happy to send.

I have it on a git, in the Socket+ branch (with generic connection now)

https://github.com/zoakes/sFIX-IB/blob/Socket%2B/SFX_Sock.py

Get Outlook for iOShttps://aka.ms/o0ukef


From: David Arnold [email protected] Sent: Monday, November 25, 2019 5:51:27 AM To: da4089/simplefix [email protected] Cc: Zach Mazz [email protected]; Author [email protected] Subject: Re: [da4089/simplefix] Add Socket connection? (#22)

Hi Zach,

At one time I was fairly opposed to this idea. I think it's a slippery slope from adding some sort of socket support, and then maybe some sort of message validation, and suddenly we're back where QuickFIX is.

But I'm maybe less against it than I was, mostly because I think a lot of people end up having to write it themselves, and while that's not terribly hard, it does seem like maybe an off-the-shelf way to do it would be better.

So. This is maybe a little unfair, but I'd kinda be interested in seeing what you come up with, without really promising to merge the PR if I get cold feet. But ... since you're writing it anyway, and since you're kinda volunteering, I'm absolutely happy to look at a PR and work with you on merging it if it seems promising?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fda4089%2Fsimplefix%2Fissues%2F22%3Femail_source%3Dnotifications%26email_token%3DALPUCIEUIL46AETWA7SWCXTQVO337A5CNFSM4JRBVJR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFCEFJY%23issuecomment-558121639&data=02%7C01%7C%7Cdf980eb5c15b4fedf91608d7719dcde3%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637102794878485564&sdata=FqC8p1RV3EcWV1Ec%2Fn9Ttc9XFCvtjOHQLpJA%2Fi3DRnY%3D&reserved=0, or unsubscribehttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FALPUCIEKPYLDVTVDRO6QRYLQVO337ANCNFSM4JRBVJRQ&data=02%7C01%7C%7Cdf980eb5c15b4fedf91608d7719dcde3%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637102794878495563&sdata=MB9bDfg9aRECiuBRO8igHI5E%2Bh3YvCW%2B86GafyIJqRU%3D&reserved=0.

zoakes avatar Nov 25 '19 13:11 zoakes

I added some stuff that most people would probably want -- like heartbeat, logging, etc. I think for now I'm done, this worked for me today in some preliminary testing, so I'm pretty pleased hah. I expected this fix engine to take like.. weeks-months, so thank you for saving me that : ) End goal is Cython / C++ engine, so I'm going to get started on optimizing tomorrow.

I'm happy to work with you on the PR (pull request?) -- I'm not super familiar with all the github ins and outs, but I'm a solid developer. If it's beginning to feel a bit like QF, no need to merge -- I'm indifferent, really I'm happy I have that makes sense and works well in a few hundred lines. Let me know !

Thank you again for this incredible module.

Zach

zoakes avatar Nov 26 '19 00:11 zoakes

David,

I finished a really clean Python FIX client with simplefix -- I'll attach the current version here. I finally finished up integrating / testing with Interactive Brokers IB CTCI FIX API, they are incredibly particular about what's used, what isn't, what's in header, etc -- but it's ready now! If you'd like to use it, or pull it -- you're welcome to. I currently have it running the heartbeat as a Daemon thread, but I have a few versions of heartbeat that can be used -- this has been the most consistent.

https://github.com/zoakes/sFIX-IB/blob/master/base_hb_v2.0.py

I didn't add any message validation, I'm not quite sure how to aside from just using a listener -- which sounds bloated. If it is something you're interested in I can give it a try though.

zoakes avatar Dec 20 '19 00:12 zoakes

@da4089 @zoakes Hey David,

If Zach, code is worth it, is any possibility to merge it? I see his code help connect to the backend engine.

mecanda12 avatar Apr 04 '23 17:04 mecanda12

I will definitely have a look at this. I'm still unsure how I'd like to integrate it, but at a minimum, it could be in some sort of example code directory. The next couple of weeks are a little busy, but I should get a chance to look at it after that.

Thank you for this!

da4089 avatar Apr 05 '23 14:04 da4089

Thanks, David :)

mecanda12 avatar Apr 05 '23 14:04 mecanda12

My code was pretty minimal — more scaffolding to build out your own spec with if I recall. Honestly, there’s a lot of FIX overhead in maintaining connectivity, and with the new FIX5 / SP stuff (session and transport layer split), it’s even more substantial.

I can run over it again, but I didn’t intend this to be merged into main. If you find use in it, go for it of course :)

I’m guessing something generic that applies + passes cert at various FIX endpoints would be substantially larger — and not really fit with the idea here.

We run FIX at CME on ILink3 and it’s like thousands of lines of code to maintain connectivity, persist messages for reconnect / disconnect / reconciling msg counts, etc. it’s not small.

Get Outlook for iOShttps://aka.ms/o0ukef


From: David Arnold @.> Sent: Wednesday, April 5, 2023 9:07:19 AM To: da4089/simplefix @.> Cc: Zach Mazz @.>; Mention @.> Subject: Re: [da4089/simplefix] Add Socket connection? (#22)

I will definitely have a look at this. I'm still unsure how I'd like to integrate it, but at a minimum, it could be in some sort of example code directory. The next couple of weeks are a little busy, but I should get a chance to look at it after that.

Thank you for this!

— Reply to this email directly, view it on GitHubhttps://github.com/da4089/simplefix/issues/22#issuecomment-1497552286, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALPUCIEQVKBBXHKGDIP4UUTW7V4BPANCNFSM4JRBVJRQ. You are receiving this because you were mentioned.Message ID: @.***>

zoakes avatar Apr 05 '23 14:04 zoakes

For better or worse, there's not a lot of usage of the new session layer stuff that I've seen: most FIX is still using the classic session protocol and some variant of FIX4.x.

But yes, a production quality FIX engine is a heap of work. In most cases, you'd probably be better off starting with the Python QuickFIX or WTFIX if that's what you need.

That said, something that's reasonably resilient and suitable for running regression tests, etc, isn't too much effort.

da4089 avatar Apr 05 '23 14:04 da4089

@da4089 I am looking for a solution for a Non-production environment. Most a Test environment. My question is the same how can I make a network connection using simplefix, QuickFIX, or WTFIX?

mecanda12 avatar Apr 05 '23 15:04 mecanda12

Yep. Even then -- quickfix doesn’t handle the new ‘split layer’ ILink3 stuff, or doesn’t publish anything implying they can.

We ended up building one, but it took months.

For basic stuff, sure – could be fairly minimal. Just a heartbeat, some other minimal overhead. If you want something to truly manage a prod level OMS / MD connection – it will quickly look like QuickFix. If that was the goal, I’d say this probably deviates from the ‘simple’ goal of the library.

Also of note – many of the paid FIX engine players barely have FIX5 / SP stuff working / tested. CME is shifting entirely to ILink3 in 2024, phasing out ILink2 now (FIX4), but no new connections can use FIX4 for example. It’s a bit of a unique time in FIX software where everyone w DMA is preparing to scramble or break.

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows

From: David @.> Sent: Wednesday, April 5, 2023 9:29 AM To: @.> Cc: Zach @.>; @.> Subject: Re: [da4089/simplefix] Add Socket connection? (#22)

For better or worse, there's not a lot of usage of the new session layer stuff that I've seen: most FIX is still using the classic session protocol and some variant of FIX4.x.

But yes, a production quality FIX engine is a heap of work. In most cases, you'd probably be better off starting with the Python QuickFIX or WTFIX if that's what you need.

That said, something that's reasonably resilient and suitable for running regression tests, etc, isn't too much effort.

— Reply to this email directly, view it on GitHubhttps://github.com/da4089/simplefix/issues/22#issuecomment-1497588023, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALPUCICFLYG67APDUWZMB3LW7V6VBANCNFSM4JRBVJRQ. You are receiving this because you were mentioned.Message ID: @.***>

zoakes avatar Apr 05 '23 16:04 zoakes

How can you make a network connection… as in how do you handle it from a software perspective? or how do you get the connectivity?

Software is fairly simple – the connectivity maybe not. DMA will run in the hundreds of thousands. Some brokers offer FIX alternatives to REST stuff, like IB, but that’s sort of FIX – lite.

Just depends, but you’ll likely need to bring some $ to the table for anyone to certify with you.

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows

From: Zach @.> Sent: Wednesday, April 5, 2023 11:23 AM To: @.>; @.> Cc: @.> Subject: RE: [da4089/simplefix] Add Socket connection? (#22)

Yep. Even then -- quickfix doesn’t handle the new ‘split layer’ ILink3 stuff, or doesn’t publish anything implying they can.

We ended up building one, but it took months.

For basic stuff, sure – could be fairly minimal. Just a heartbeat, some other minimal overhead. If you want something to truly manage a prod level OMS / MD connection – it will quickly look like QuickFix. If that was the goal, I’d say this probably deviates from the ‘simple’ goal of the library.

Also of note – many of the paid FIX engine players barely have FIX5 / SP stuff working / tested. CME is shifting entirely to ILink3 in 2024, phasing out ILink2 now (FIX4), but no new connections can use FIX4 for example. It’s a bit of a unique time in FIX software where everyone w DMA is preparing to scramble or break.

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows

From: David @.> Sent: Wednesday, April 5, 2023 9:29 AM To: @.> Cc: Zach @.>; @.> Subject: Re: [da4089/simplefix] Add Socket connection? (#22)

For better or worse, there's not a lot of usage of the new session layer stuff that I've seen: most FIX is still using the classic session protocol and some variant of FIX4.x.

But yes, a production quality FIX engine is a heap of work. In most cases, you'd probably be better off starting with the Python QuickFIX or WTFIX if that's what you need.

That said, something that's reasonably resilient and suitable for running regression tests, etc, isn't too much effort.

— Reply to this email directly, view it on GitHubhttps://github.com/da4089/simplefix/issues/22#issuecomment-1497588023, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALPUCICFLYG67APDUWZMB3LW7V6VBANCNFSM4JRBVJRQ. You are receiving this because you were mentioned.Message ID: @.***>

zoakes avatar Apr 05 '23 16:04 zoakes

@zoakes To make a connection with the backend engine, a socket can be used to communicate with the bundle.

Ip address, Port, Target & Sender comp Id, Target Sub ID, User address and password.

The above information can be used to make a network connection.

mecanda12 avatar Apr 05 '23 17:04 mecanda12

These requirements are all set per endpoint. There’s a certification process involved with most? (All?), all I’ve connected to. Depends on where you are connecting.

I’ll also say the VPN / VPC requirements for many of these aren’t trivial either.

To get access to this whole environment , usually a matter of $$. There’s minimum volumes, or account sizes, etc,

So like… CME connectivity requires I think $1M account size, 10k contracts/mo, something. It may also require membership, unsure. We have membership, unsure if that’s a req.

Easier routes would be broker fix, IB, probably 100k requirement. TT is another one, but that’s like 3k/mo ish.

It’s really just going to require $ in all the US Equities / Futures endpoints I’m familiar with. Maybe there’s some FX or digital stuff that’s ‘free’ and easier, don’t know. I recall darwinex had an endpoint but closed it to new users.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Harry @.> Sent: Wednesday, April 5, 2023 12:34:16 PM To: da4089/simplefix @.> Cc: Zach Mazz @.>; Mention @.> Subject: Re: [da4089/simplefix] Add Socket connection? (#22)

@zoakeshttps://github.com/zoakes To make a connection with the backend engine, a socket can be used to communicate with the bundle.

Ip address, Port, Target & Sender comp Id, Target Sub ID, User address and password

How can you make a network connection… as in how do you handle it from a software perspective? or how do you get the connectivity?

— Reply to this email directly, view it on GitHubhttps://github.com/da4089/simplefix/issues/22#issuecomment-1497869753, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALPUCIEOY7EWUU4CBREQIRDW7WUJRANCNFSM4JRBVJRQ. You are receiving this because you were mentioned.Message ID: @.***>

zoakes avatar Apr 05 '23 17:04 zoakes

@zoakes I do not think regression testing needs that much $$. Keep in mind I am talking about internal-level testing. Which will be happening on the same network.

Do you have a solution for that?

mecanda12 avatar Apr 05 '23 17:04 mecanda12

Sure, you can mock a FIX endpoint. Quickfix has one ready to go, though you'll need to hard code various behaviors into it to sort of 'mock' the behavior you expect wrt resets, rejections, sessions, etc. good example here would be some exchanges seem to elide the 'Ack' with the 'Fill' for marketable orders. Others don't. Some (most?) also permit cancellation with a ClOrdId (pre ack), while others require the venue given OrderId (post ack).

There's lots of nuance, even in mocking expected venue behavior / state.

To connect to a real endpoint (for any form of real testing), I think you will need to pass certification & fully integrate for the given endpoint. In modern fix, that means a multicast VPN, and multiple sessions for various 'cert specific' products.

That's always been the case for me. My SFIX-IB was basically a hacked solution to pass certification with IB, but eventually I used QuickFix to manage the overhead of things like sequence reset, in production. I think I used it in prod for weeks before realizing it was easier to use basic api, and was of no benefit otherwise.

Real fix is complicated, and the certifications require handling a lot of edge cases.
CME has steps like... send 60,000 limit orders, we'll fill / reject them randomly, then cancel any remaining. Now add a disconnect + reset / reconcile halfway through, etc. IB's was exponentially easier, but it's also very manual whereas cme is automated certification, just a testing suite.

I don't really see the point of testing the robustness of a mocked connection, personally, but that's just me.
These multicast, distributed systems are not trivial to test, I find it more efficient to write larger tests that cover as much as possible.
Again -- that's purely my preference.

zoakes avatar May 14 '23 13:05 zoakes

Hello, there! As, I'm new to the FIX protocol I do not understand where I can start and how I can use this if zoakes or anyone else can give me any suggestions or documents to understand this it will be very helpful for me the real fix documentation is really overwhelming and going over my head.

Umair-A avatar Feb 23 '24 10:02 Umair-A

Hello, there! As, I'm new to the FIX protocol I do not understand where I can start and how I can use this if zoakes or anyone else can give me any suggestions or documents to understand this it will be very helpful for me the real fix documentation is really overwhelming and going over my head.

What are you trying to achieve?

da4089 avatar Feb 23 '24 11:02 da4089

My end goal is to create a connection with the mt5 server or you can say a liquidity provider. For it, I must have a clear understanding of FIX API and how it will work.

Umair-A avatar Feb 23 '24 11:02 Umair-A

Not following... I don't think MT5 has FIX, I don't know why they would. Fix would be more for connecting directly to venues -- cme, nyse, Nasdaq, bzx, edga, edgx etc.

Some brokers provide endpoints that can then route to many venues -- trading technologies, interactive brokers.

I don't know where a trading platform would come in. FIX is just a messaging protocol.

I see no mention of mt5 offering a fix endpoint, don't see what purpose it would serve their users.

zoakes avatar Feb 23 '24 12:02 zoakes

Exactly, I will get an endpoint from the broker. I wanted to get market feed data and other order sending on it etc. If you could please look into this repository it is what exactly I want but it is an old repository which is not working now. https://github.com/rinleit/quickfix-python-samples

Umair-A avatar Feb 23 '24 12:02 Umair-A

Python quickfix works fine. I've used it for drop copy from dozens of exchanges, and used it to hit TT, IB.

FIX is complicated, and very not generic -- if it doesn't work you're likely not meeting their spec, or aren't permissioned to hit the endpoint. It's whatever the provider (acceptor, in QF parlance) says it is.

Most brokers have a UAT environment, and onboarding process to use it that you must pass. Contact them, is my suggestion -- they'll provide all this.

Of note -- this is not quickfix. Please direct quickfix related issues to quickfix.

This repo is more 'I want to build my own fix client, to replace Quickfix, and just don't want to do the message parsing / creation myself'

Also of note -- 9/10 times I hear this, someone is interested in latency. Fix is NOT inherently faster, and unless in newer binary formats it's most likely going to offer SLOWER execution speed, particularly with new unrefined implementations in things like quickfix, w basic network setup etc. So much of latency will be network, hardware, and has nothing to do w connectivity method -- but there's not much that's naturally fast about the enormous parsing overhead of FIX.

Like... making a fix parser as fast as possible, will get you a couple us faster, but your network jitter alone is likely in the ms.... what was the purpose?

If this is a latency play -- this won't fix anything. Been there, done that.

zoakes avatar Feb 23 '24 12:02 zoakes

Thanks for the kind response. The problem with QuickFix Python it is not working and giving this error while installing it on a Windows machine image And I got your point thanks

Umair-A avatar Feb 26 '24 10:02 Umair-A

And If you can please give me steps on how can I achieve a connection with any server using quickfix or fix API. Please mention some steps or material if it is possible.

Umair-A avatar Feb 26 '24 11:02 Umair-A

Again — this is not a quickfix issue forum. Please direct any quickfix build issues to Quickfix. \

Just to cut to the chase, if running Quickfix is a struggle building your own replacement is going to be orders of magnitude more challenging.
I would likely revisit why this is of importance, and focus on your use cases -- plenty of ways to connect to a broker

Get Outlook for iOShttps://aka.ms/o0ukef


From: Umair Ahmad @.> Sent: Monday, February 26, 2024 5:36:13 AM To: da4089/simplefix @.> Cc: Zach Mazz @.>; Mention @.> Subject: Re: [da4089/simplefix] Add Socket connection? (#22)

And If you can please give me steps on how can I achieve a connection with any server using quickfix or fix API. Please mention some steps or material if it is possible.

— Reply to this email directly, view it on GitHubhttps://github.com/da4089/simplefix/issues/22#issuecomment-1963937986, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALPUCIAJ2TBDJN5WRHM2G4TYVRXS3AVCNFSM4JRBVJR2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJWGM4TGNZZHA3A. You are receiving this because you were mentioned.Message ID: @.***>

zoakes avatar Feb 26 '24 12:02 zoakes

And If you can please give me steps on how can I achieve a connection with any server using quickfix or fix API. Please mention some steps or material if it is possible.

@Umair-A it sounds like your best option would be to ask the QuickFIX folks for some help, probably a pointer to an example or tutorial.

The steps involved in making a FIX connection include

  • Getting the required "Rules of Engagement" document
  • Getting the connectivity details
  • Establishing and maintaining TCP connectivity
  • Establishing and maintaining FIX connectivity
    • Including implementing FIX recovery
  • Implementing the messages you need for your application (quotes, orders, symbol lists, positions, etc)

In some of these steps, there are decisions to make about how you'd like to implement them. Network programming in Python has a number of possible approaches; message and session state persistence can also be done various ways.

And if your ultimate goal is integration with MT5, that is itself a pretty large project (and completely unrelated to SimpleFIX).

SimpleFIX would, at most, only be a very small part of all this. I'm happy to help you with that bit of the project, but the rest of it is your own responsibility.

da4089 avatar Feb 27 '24 13:02 da4089