In progress/POC cTrader FIX plugin

Posted By: Veratyr

In progress/POC cTrader FIX plugin - 05/07/18 15:17

I've got something somewhat usable so I figured I'd share it in case anyone has any feedback before I make the code even shittier grin

Here's the source code.

Here's the DLL.

How to use:

  • Put a ctfix.ini in your Plugins directory. There's a sample configuration here. You should only need to change SocketConnectHost, SenderCompID, Username and Password, all of which you can find in the cTrader platform your broker provides in one of the menus labeled "FIX Credentials".
  • Set up your assets. cTrader's FIX API has numeric codes for all assets rather than names. There's a mapping of symbol -> FIX ID here but unlike other plugins, for the moment at least, you must add an account specific prefix with a dash to your assets. Where you'd write "1" (for EURUSD), you must instead write "broker-1" or "Oanda-1" or "FXCM-1" etc. My code is written to require a dash in all asset names.


What's working:


  • Connecting
  • Logging in
  • Multiple accounts
  • Subscribing to assets
  • Receiving data for assets


What's not working (yet):

  • Trading
  • Good, readable code


What will never work:

  • Account balances
  • Price history


I understand that without trading this is of limited use, I'm more putting it out there for anyone who cares to play with it to research arbitrage or something and so I can point people to code when I need help after breaking something.

I'll also add that this code is tailored specifically to cTrader. If you want it to work with another broker, more likely than not, you'll have to modify the code to do what your broker wants.
Posted By: AndrewAMD

Re: In progress/POC cTrader FIX plugin - 05/07/18 17:02

If you don't mind me asking, have you had good experiences with QuickFix?

I ask because while implementing the DTC plugin, I stumbled across this complaint from the Sierra Chart staff:
https://www.sierrachart.com/SupportBoard.php?ThreadID=15382
Quote:
We have a very poor impression of Quick FIX and consider it very substandard quality and buggy.
I'm not sure what kind of bugs they are talking about. They do appear to have strong opinions and think highly of their programming ability.
Posted By: Veratyr

Re: In progress/POC cTrader FIX plugin - 05/07/18 19:14

Originally Posted By: AndrewAMD
If you don't mind me asking, have you had good experiences with QuickFix?

I ask because while implementing the DTC plugin, I stumbled across this complaint from the Sierra Chart staff:
https://www.sierrachart.com/SupportBoard.php?ThreadID=15382
Quote:
We have a very poor impression of Quick FIX and consider it very substandard quality and buggy.
I'm not sure what kind of bugs they are talking about. They do appear to have strong opinions and think highly of their programming ability.


Frankly I came across two open source C++ FIX engines: fix8 and QuickFIX.

fix8's docs were horrible and hidden in a wiki that needed an account and even with access to them, it was a bitch to get anything working. I gave it a go on Mac at first, where C++ dev is a little less shitty but even there it was horrible. The thought of getting all its dependencies working on Windows put me right off it. I never actually got fix8 to work.

QuickFix had nice clear docs, only depended on OpenSSL (which I already had installed on Mac) and took very minimal effort to get successfully connected to a broker. On Windows, I installed OpenSSL binaries, built QuickFix itself with cmake and got it working with few problems.

I didn't want to pay for one of the commercial options. I'm sure they have better performance and if you buy a support contract they'll do whatever you need but this is a hobby for me, not a profession. Plus, I think anything super low latenc will be wasted on a Zorro plugin; I don't think Zorro can compete with a proper C++ implementation, which for arbitrage at least is pretty trivial.

Anyhow, I'm pretty happy with QuickFix. It's easy to install, easy to use, I haven't run into any bugs, the docs are easy to read and the code I've looked at (mainly session management and settings code) has been pretty clear and tidy.

I think the Sierra Chart people are full of themselves. There's some more feedback here, which is mostly positive: https://quant.stackexchange.com/questions/557/how-fast-is-quickfix
Posted By: AndrewAMD

Re: In progress/POC cTrader FIX plugin - 05/07/18 19:25

I appreciate the insight. Thanks! laugh
Posted By: Sphin

Re: In progress/POC cTrader FIX plugin - 05/09/18 22:56

Some basic questions:

1. In general a cTrader account is required for the plugin? A 'pure' FIX API account does not work or at least not out of the box?

2. Using your example AssetsCT.csv what do you mean concerning the dash in the assets names? AUD/USD e.g. has the symbol 5 there, selecting it in the strategy must be with asset("FXCM-5") or asset("5") or must the symbol be written as "FXCM-5" in the assets.csv?

Thanks, Sphin
Posted By: Veratyr

Re: In progress/POC cTrader FIX plugin - 05/13/18 10:34

Originally Posted By: Sphin

1. In general a cTrader account is required for the plugin? A 'pure' FIX API account does not work or at least not out of the box?


Yes. As far as I can tell, there's no such thing as a functional "pure" FIX implementation, so this one targets cTrader specifically.

Originally Posted By: Sphin

2. Using your example AssetsCT.csv what do you mean concerning the dash in the assets names? AUD/USD e.g. has the symbol 5 there, selecting it in the strategy must be with asset("FXCM-5") or asset("5") or must the symbol be written as "FXCM-5" in the assets.csv?


The symbol being passed to the plugin (the one in the last column) must be "FXCM-5". You can name it whatever you want in Zorro and use asset() with the Zorro name.
Posted By: Sphin

Re: In progress/POC cTrader FIX plugin - 05/21/18 02:28

Trying to get some prices ...

Code:
function run() {
  BarPeriod = 1;
  LookBack = 0;
  set(TICKS+LOGFILE);
  plot(Asset, priceClose(), NEW, BLUE);
}


selected "EUR/USD" in the asset box, click "Trade" and get these messages:

Click to reveal..
CheckAsset
Login 0 CTFIX..
!Logging in
!Not initialized, logging in
!Loading session settings
!Session settings loaded
!Found 1 accounts
!Starting initiator
!Initiator started
!Not logged in yet...
!Logged in!
at UTC 05-21 01:18
V 1.830 on Mon 18-05-21 03:18:17
!CurrentAccount empty
!Couldn't find session
!CurrentAccount empty
!Couldn't find session
!CurrentAccount empty
!Couldn't find session
Trade: CheckAsset EUR/USD 2018-05-21
Assets AssetscT
!CurrentAccount empty
!Couldn't find session
!CurrentAccount empty
!Couldn't find session
[...]
[fast repeating until click on Stop button]

Directly selecting the asset in the code with

asset("EUR/USD")

the messages slightly differ:

Click to reveal..
CheckAsset
Login 0 CTFIX..
!Logging in
!Not initialized, logging in
!Loading session settings
!Session settings loaded
!Found 1 accounts
!Starting initiator
!Initiator started
!Not logged in yet...
!Logged in!
at UTC 05-21 01:34
!CurrentAccount empty
!Couldn't find session
!CurrentAccount empty
!Couldn't find session
- EUR/USD history unavailable!
V 1.830 on Mon 18-05-21 03:34:00
Error 055: No bars generated
Logout..
!Logging out...
ok

Maybe this is a mapping problem because adjusting your example my AssetscT.csv just looks like:

EUR/USD,1.13795,0.00005,-0.02,0.01,0.0001,0.0871,10,0,100000,0.6,Broker-1

But there are several liquidity streams available and so their assets are called:

EURUSD.aaa
EURUSD.bbb
EURUSD.ccc

Do you know wherefrom getting a valid mapping? In cTrader at least I couldn't find some.

BTW: The connects from above work only once without restarting Zorro. Trying it twice I get:
Quote:
CheckAsset
Login 0 CTFIX..
!Logging in
!Account not valid: [acc. number that worked before]
Can't connect!
Posted By: AndrewAMD

Re: In progress/POC cTrader FIX plugin - 05/21/18 13:17

Originally Posted By: Sphin
BTW: The connects from above work only once without restarting Zorro.
Dear plugin writers: please don't forget to clean up memory between login calls. Thank you! laugh
Posted By: Sphin

Re: In progress/POC cTrader FIX plugin - 06/22/18 16:10

Is this project still alive?
Posted By: Veratyr

Re: In progress/POC cTrader FIX plugin - 08/09/18 21:50

Originally Posted By: Sphin
Is this project still alive?


I haven't had the time/motivation to work on it recently.

If anyone else wants to try to pick it up they're welcome to fork it.
© 2024 lite-C Forums