Connection Questions

Created at 29 Mar 2017, 14:10
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
YC

ycomp

Joined 16.10.2013

Connection Questions
29 Mar 2017, 14:10


I have a few questions about making a connection:

  1. how often do I need to send Authorization?
    1. how can I detect when I need to send an authorization request again?
  2. can I log into an account simultaneously with the trading and accounts api? (i.e. 2 or more simultaneous connections)

@ycomp
Replies

Spotware
29 Mar 2017, 14:23

Hi ycomp,

1) You need to get an authorization every time you establish the connection. Then you need to ping the server every ath least ten seconds to keep the connections alive.

2) If you have a trading api token you can access both scopes. 


@Spotware

ycomp
30 Mar 2017, 01:12

RE:

Spotware said:

Hi ycomp,

1) You need to get an authorization every time you establish the connection. Then you need to ping the server every ath least ten seconds to keep the connections alive.

2) If you have a trading api token you can access both scopes. 

what is this heartbeat thing? I assume I can ignore using it if I ping the servers routinely?


@ycomp

ycomp
30 Mar 2017, 06:35

and what is a positionId ? like in ProtoOACreateOrderReq ?

 


@ycomp

ycomp
30 Mar 2017, 08:06

how can I convert an orderID into a positionID so that I can call ProtoOAClosePositionReq ?


@ycomp

Spotware
30 Mar 2017, 09:43

Hi ycomp,

1) what is this heartbeat thing? I assume I can ignore using it if I ping the servers routinely?

Heartbeat is used to keep the communication link alive while there is no activity from the client side. Preferably use heartbeat.

2) and what is a positionId ? like in ProtoOACreateOrderReq ?

The position ID is used when you want the order not to create a new position but merge the deals into an existing position. If for example you create a BUY position of €1000 EURUSD and then send another order request of  €1000 EURUSD with direction BUY and pass the open position's ID, then the position will become €2000 BUY, instead of having two separate positions.

3) how can I convert an orderID into a positionID so that I can call ProtoOAClosePositionReq  

When orders are executed, the positionID is returned. See ProtoOAExecutionEvent


@Spotware

ycomp
30 Mar 2017, 10:41

RE:

Spotware said:

Hi ycomp,

1) what is this heartbeat thing? I assume I can ignore using it if I ping the servers routinely?

Heartbeat is used to keep the communication link alive while there is no activity from the client side. Preferably use heartbeat.

just to confirm.. if I use heartbeat, then I don't need to ping at all ?


@ycomp

ycomp
30 Mar 2017, 10:45

how should I handle the situation where my program:

1. sends a market order request

2. connection drops

3. market order filled

4. response message missed (because not connected)

5. reconnected

so now on the server will be an open trade, that my program doesn't know was opened

 


@ycomp

Spotware
30 Mar 2017, 10:46

RE: RE:

ycomp said:

Spotware said:

Hi ycomp,

1) what is this heartbeat thing? I assume I can ignore using it if I ping the servers routinely?

Heartbeat is used to keep the communication link alive while there is no activity from the client side. Preferably use heartbeat.

just to confirm.. if I use heartbeat, then I don't need to ping at all ?

Yes, for maithaining a live communication, sending heartbeats is adequate.


@Spotware

Spotware
30 Mar 2017, 11:42

RE:

ycomp said:

how should I handle the situation where my program:

1. sends a market order request

2. connection drops

3. market order filled

4. response message missed (because not connected)

5. reconnected

so now on the server will be an open trade, that my program doesn't know was opened

 

You can get an account's history at any time, including orders, positions and deals through Accounts API.

https://connect.spotware.com/docs/api-reference/accounts-api


@Spotware

mindbreaker
30 Mar 2017, 11:55

RE: RE:

Spotware said:

ycomp said:

how should I handle the situation where my program:

1. sends a market order request

2. connection drops

3. market order filled

4. response message missed (because not connected)

5. reconnected

so now on the server will be an open trade, that my program doesn't know was opened

 

You can get an account's history at any time, including orders, positions and deals through Accounts API.

https://connect.spotware.com/docs/api-reference/accounts-api

But in ConnectApi 2s refresh request interval exist (2 secomds in forex reality is eternity) !!!


@mindbreaker

Spotware
30 Mar 2017, 12:10

RE: RE: RE:

mindbreaker said:

Spotware said:

ycomp said:

how should I handle the situation where my program:

1. sends a market order request

2. connection drops

3. market order filled

4. response message missed (because not connected)

5. reconnected

so now on the server will be an open trade, that my program doesn't know was opened

 

You can get an account's history at any time, including orders, positions and deals through Accounts API.

https://connect.spotware.com/docs/api-reference/accounts-api

But in ConnectApi 2s refresh request interval exist (2 secomds in forex reality is eternity) !!!

Yes this is true for subsequent requests, but what ycomp desrcibes is a rare scenario which will not happen every less than two seconds.


@Spotware

ycomp
30 Mar 2017, 13:51

Is there a way to send a close request without specifying the exact volume (and it will just close the entire position)?


@ycomp

Spotware
30 Mar 2017, 14:04

Yes you can use ProtoOAClosePositionReq


@Spotware

ycomp
30 Mar 2017, 14:04

I'm a bit confused as to how to implement heartbeat. I'm gettting heartbeat events, what do I do when I receieve them? 

Do I ever need to actually create a heartbeat event ? I don't really understand why I would need to create one if the server already sends them periodically.

But I don't know how to acknowledge to the server that I recieved the heartbeat event.


@ycomp

ycomp
30 Mar 2017, 14:06

RE:

Spotware said:

Yes you can use ProtoOAClosePositionReq

in the docs it says "volume" is required, what value should I specify for volume to signify that the entire position should be closed? 0 doesn't work.


@ycomp

Spotware
30 Mar 2017, 15:31

1) in the docs it says "volume" is required, what value should I specify for volume to signify that the entire position should be closed? 0 doesn't work.

Yes, indeed. The volume is required. Apologies for the previous answer. 

2) Heartbeat.

You do not need to aknowledge heartbeat receipt to the server. The server just lets you know that it is alive, in case your application needs this info. In a similar way, You will need to send a heartbeat to the server that your application is alive so the server keeps the connection open.


@Spotware

mindbreaker
30 Mar 2017, 15:49

Now you can use FIX with SSL


@mindbreaker

ycomp
30 Mar 2017, 16:57

is there a way to determine if the market is currently tradeable? for instance, market hours is over because it is the weekend ?

if not then what will happen on the weekend? orders just get rejected?


@ycomp

Spotware
31 Mar 2017, 10:02

Hi ycomp,

Currently you cannot determine bedorehand if a symbol is tradable or not. When orders are send for a symbol in non tradable hours, you will receive a rejection message with error code MARKET_CLOSED. Please see https://connect.spotware.com/docs/api-reference/developer-library/common-model-messages


@Spotware