Replies

ctid1980098
21 Aug 2024, 09:18

Hi, 

Yes, you can do this programmatically. When you receive a price info from server with “35=W” fix message then open and order for your current buy or sell position and use orderupdate fix message to change the stop price and it should behave like a trailing stop. 


@ctid1980098

ctid1980098
05 Mar 2024, 12:39

RE: RE: RE: Order ID Not found

jan.schmid said: 

ctid1980098 said: 

jan.schmid said: 

8=FIX.4.4|9=134|35=D|49=demo.ctrader.4136405|56=cServer|57=TRADE|50=TRADE|34=1|52=20240304-07:30:09|11=D|55=22312|54=1|60=20240304-07:30:09|38=1|40=1|10=178|

So this is my message to buy a position.

and this is my try so close the position

8=FIX.4.4|9=94|35=F|49=demo.ctrader.4136405|56=cServer|57=TRADE|50=TRADE|34=1|52=20240304-07:31:56|41=D|11=D|10=069|

Hi. You opened a position using “35=D” (buy position) and cannot close this position with “35=F” as 35=F is only for orders( like pending orders and not for opened positions). To close your position you need to use “35=D” again to close. So you will need to close your buy position with a corresponding sell position. So to close your position it should look something like this…i think: 

8=FIX.4.4|9=?|35=D|34=?|49=demo.ctrader.4136405|56=CSERVER|57=TRADE|50=TRADE|11=D|55=22312|54=2|60=?|38=1|40=1|721={id_of_your_buy_position}|10=?|

You can only close your buy position with a corresponding sell market order. You cannot use tag “35=F” here. Take note 54=2 (sell to close position). Hope it helps

Appreciate it my code worked perfectly now :)

Glad it worked. ;)


@ctid1980098

ctid1980098
05 Mar 2024, 11:09 ( Updated at: 05 Mar 2024, 11:12 )

RE: Order ID Not found

jan.schmid said: 

8=FIX.4.4|9=134|35=D|49=demo.ctrader.4136405|56=cServer|57=TRADE|50=TRADE|34=1|52=20240304-07:30:09|11=D|55=22312|54=1|60=20240304-07:30:09|38=1|40=1|10=178|

So this is my message to buy a position.

and this is my try so close the position

8=FIX.4.4|9=94|35=F|49=demo.ctrader.4136405|56=cServer|57=TRADE|50=TRADE|34=1|52=20240304-07:31:56|41=D|11=D|10=069|

Hi. You opened a position using “35=D” (buy position) and cannot close this position with “35=F” as 35=F is only for orders( like pending orders and not for opened positions). To close your position you need to use “35=D” again to close. So you will need to close your buy position with a corresponding sell position. So to close your position it should look something like this…i think: 

8=FIX.4.4|9=?|35=D|34=?|49=demo.ctrader.4136405|56=CSERVER|57=TRADE|50=TRADE|11=D|55=22312|54=2|60=?|38=1|40=1|721={id_of_your_buy_position}|10=?|

You can only close your buy position with a corresponding sell market order. You cannot use tag “35=F” here. Take note 54=2 (sell to close position). Hope it helps


@ctid1980098

ctid1980098
20 Feb 2024, 14:15

Hi

Shouldn't you be decoding your message received in python. Something like… 

print(response.decode('utf-8')) 


@ctid1980098

ctid1980098
29 Jan 2024, 09:02

RE: RE: RE: RE: Request for Positions - not returning data for all open positions

wiktor.kisielewski said: 

ctid1980098 said: 

response = s.recv(2048)

the line above is is probably an indication that you are not receiving messages in a loop or asynchronously and hence why you are not receiving the multiple messages being sent from server. You would need to rethink how you are writing your code and would also need to read field 9= to determine how much bytes you will need to receive or something along those lines. I have not used simplefix so don't know much about it but I have written application from scratch. 

You will need to rewrite your code so that you can read multiple messages from server in order to see other opened positions. My suggestion is to write from scratch as i found it easier to understand. 

could you share some code snippets of your code? That would be very usefull 

there are many examples online for various languages on how to read continuously from sockets. They are incredibly useful to help get you started. In fact reading previous questions asked on this forum give good code snippets that will help to get you started. 


@ctid1980098

ctid1980098
29 Jan 2024, 08:43

RE: RE: Request for Positions - not returning data for all open positions

response = s.recv(2048)

the line above is is probably an indication that you are not receiving messages in a loop or asynchronously and hence why you are not receiving the multiple messages being sent from server. You would need to rethink how you are writing your code and would also need to read field 9= to determine how much bytes you will need to receive or something along those lines. I have not used simplefix so don't know much about it but I have written application from scratch. 

You will need to rewrite your code so that you can read multiple messages from server in order to see other opened positions. My suggestion is to write from scratch as i found it easier to understand. 


@ctid1980098

ctid1980098
29 Jan 2024, 08:01

Hi,

I don't see any code for how you may be reading from the server but are you sure you are reading all the responses from the server? Like reading in a loop or something? It could be that maybe you are just reading only the first message only? On my end I am able to receive all open positions back from server. tested on my app for up to 8 positions. 


@ctid1980098

ctid1980098
10 Nov 2023, 13:26

"demo.fxpro.10566592"

I don't think Fxpro allows you to connect via FIX API. Try another broker


@ctid1980098

ctid1980098
16 Sep 2023, 13:20

The message i'm sending is the following and it works:

8=FIX.4.49=14535=V34=249=demo.broker.********56=cServer57=QUOTE50=tjYVXFWK552=20230916-09:35:20262=GBPJPY263=1264=1265=1146=155=7267=2269=0269=110=….

check order of your tags and notice you might be missing tag 57?

you can also omit milliseconds from time field. 

hvfixapi[at]gmail.com


@ctid1980098

ctid1980098
04 Jun 2023, 14:31

RE: RE: RE: RE: RE:

adrian.buzatu said:

> I have never used "Open API" and can only speak to "FIX API". 

> I currently have connections to 16 broker accounts via FIX api and the execution is pretty much seamless across all. I am able to buy and sell across all brokers pretty much at the same time. I have never experienced an issue where I have vastly different execution times across brokers, provided you have a vps.... to reduce latency. 

> FIX took me a while to code up and get into the hang of things, but once up and running the system works flawlessly. My client was happy to copy trades across multiple platforms with FIX platform we designed. 

Hi, Thank you for the answer, that is very helpful to show this is possible with FIX, as it is designed to be low level and thus flexibile.

Did you code the FIX code from scratch, or on the top of the FIX API provided by cTrader?

Do you use C# or Python with https://github.com/spotware/cTraderFixPy ? I tried the latter and I can place trades, but I struggle with seeing the list of positions so that I can close them back; I also struggle with TP and SL in FixAPI, I know about the 721 to the main position. I wonder if you would able to help me get started with a hello world?

Do you keep all 16 connnections opened all the time and send heartbeats to them? Or you open and close them after every time the client presses a button in their platform? 

Thank you!

Hi,

You can email me here for the questions you have on fix. hvfixapi@gmail.com and will try to assist. thanks


@ctid1980098

ctid1980098
28 May 2023, 18:43

RE:

Hi, Not that I am aware off. There may be a server limit to prevent some kind of abuse but I have not encountered such a limit. 

I have sent orders exceeding 80 orders to move sl with every tick and all messages get sent fine. I have sent hundreds of requests every second or less 

and have never seen any throttling or any kind of maximum requests message. 

 


@ctid1980098

ctid1980098
09 May 2023, 08:42

RE: RE: RE: RE: RE:

karakayafaruk6@gmail.com said:

ctid1980098 said:

Thank you for the document. I try to close my current position 25% or 50%. or close all LONG  positions at the same time

Yes i think you can close partially by 25 or 50%. For closing a position, the opposite order has to be sent with the same amount or an amount that reduces position by certain percentage.

So tag 38= will contain an amount 50% less than your original position. then it should work. 

To close all long positions you would need to open opposite sell positions with tag 721 containing the ids of the original buy positions and it should all close. 

Thanks for the info. I am still struggling :) still couldn't open a position :) :)

if you need help you can message me here hvfixapi@gmail.com


@ctid1980098

ctid1980098
08 May 2023, 08:38

RE: RE: RE:

Thank you for the document. I try to close my current position 25% or 50%. or close all LONG  positions at the same time

Yes i think you can close partially by 25 or 50%. For closing a position, the opposite order has to be sent with the same amount or an amount that reduces position by certain percentage.

So tag 38= will contain an amount 50% less than your original position. then it should work. 

To close all long positions you would need to open opposite sell positions with tag 721 containing the ids of the original buy positions and it should all close. 


@ctid1980098

ctid1980098
07 May 2023, 19:29

RE: RE: RE:

johnson.fergusaka said:

ctid1980098 said:

That random string was taken from the docs. You can change it to anything you wish. I generate my own random string and store it if need be. The ID can be any random text string. it should work

So I'm guessing it doesn't matter if you use the same string across multiple sessions?
Also, I've created a mapping of symbol:symbolID pairs from the response, and one of the symbol pairs is:
fjkhsdjkfhsdjkaf:22394
I was wondering what this is?

Yes, I have used the same string across multiple sessions and have had no issues except with login strings. But you can just assign a random string so you know that you will not encounter any problems. 

As for the symbol fjkhsdjkfhsdjkaf:22394

this is the first time i see something like this. I have just requested a security list and found no such string in there like the one above. No idea


@ctid1980098

ctid1980098
07 May 2023, 12:22

RE:

Hi,

the only documentation i'm aware of is on the ctrader site and specification here https://help.ctrader.com/fix/specs/cTraderFixApi_v2.18.1.pdf 

Buy and sell orders examples can be found in the above link as a new order single 35=D message. 

Closing positions: To close a buy position you need to open a corresponding sell position that includes the buy position id in the tag 721=.... so as to link the buy with the closing sell position. there is one example of this given below. see tag 721 under "market order to existing position". same is for the reverse case. 

What kind of complex cases are you referring to? 

 


@ctid1980098

ctid1980098
07 May 2023, 12:11

RE:

Without seeing your code I probably would guess that somewhere you are sending a 35=V market request twice and getting the response ALREADY_SUBSCRIBED. 

I send a 35=V market request once and thereafter just receive price updates from the server. 

or maybe you have not logged out of your fix tcp connection or something along those lines. 

 


@ctid1980098

ctid1980098
07 May 2023, 12:08

RE:

That random string was taken from the docs. You can change it to anything you wish. I generate my own random string and store it if need be. The ID can be any random text string. it should work


@ctid1980098

ctid1980098
25 Mar 2023, 19:55 ( Updated at: 21 Dec 2023, 09:23 )

RE:

johnson.fergusaka said:

For example send a message to an endpoint that will return 42 from XAGUSD?
If not is there any mapping that has all the Symbol:ID pairs that i can just copy into my code?
 

Hi johnson.fergusaka,

Will a security list fix message not return the symbol:id pairs? I just tried it now. 

From the docs:

then the example provided in the docs is below:

From the response above you can create a mapping for each symbol and corresponding symbol number unless i have misunderstood you. 

Hope it helps. 

 


@ctid1980098

ctid1980098
20 Mar 2023, 14:51

RE: RE: RE:

iliketurtles said:

ctid1980098 said:

Could you provide your contact, i am interested of this application you built. Thanks

Sure. You can contact me here: hvfixapi@gmail.com


@ctid1980098

ctid1980098
09 Mar 2023, 09:34

RE:

Hi heinrich.munz

As far as i know you cannot change the ctrader windows app to connect to another FIX broker. 

FIX API allows you you design/program your own application and connect to multiple ctrader fix accounts via different brokers. 

As you rightly say the windows app ctrader fix credentials are read only. 

FIX is used to achieve low latency and connect to multiple ctrader broker accounts by programming your own application. 

for example, this is the application i built for a client who wanted the ability to buy across all his accounts simultaneously from one custom interface using FIX API. 


@ctid1980098