Replies

olegchubukov
28 Sep 2021, 21:28

RE:

Found the answer. There are methods addAllSymbolId() and addSymbolId() for this purpose that take symbol id.


@olegchubukov

olegchubukov
21 Sep 2021, 14:57

RE: RE: RE: RE:

amusleh said:

olegchubukov said:

amusleh said:

Hi,

You shouldn't use ProtoOAReconcileReq to keep your app up to date with account orders, use it only once and then use execution event to remove/modify/add new account orders.

Regarding Heatbeats, its a response to sending heartbeat, if you don't send any heartbeat you will not receive back an heartbeat message.

You should use a queue to send messages on a specific time interval so you will not reach maximum allowed messages number per second, otherwise you will receive an error message.

Please check our WPF sample code, there we have all of what I just said.

Well, I need to start with saying that I was accidently sending ProtoOAReconcileReq instead of ProtoHeartbeatEvent. Copy/paste... My bad. Is it that's why you commented about ProtoOAReconcileReq?

I have now changed my scheduler to send ProtoHeartbeatEvent and I see ProtoHeartbeatEvent comes every 30 secs again.

But you said that "if you don't send any heartbeat you will not receive back an heartbeat message." This is not true on my side. Even if I dont send a hearbeat, I still receive ProtoHeartbeatEvent every 30 seconds for some period. Sometimes it's 5 minutes, sometimes a couple of hours. But my key point is that ProtoHeartbeatEvent comes without me sending ProtoHeartbeatEvent.

Regarding exceeding the limits, I dont send that many messages to be able to exceed the limits. My application only listens for events.

What is WPF? Is it this source https://github.com/spotware/ctrader-open-api-v2-java-example? If so, that was exactly the code I used.

Here is our WPF sample: OpenAPI.Net/src/WPF.Sample at master · spotware/OpenAPI.Net (github.com)

I was sending a heartbeat every 10 seconds, but connection was lost after two hours and ProtoHeartbeatEvent stopped coming from the API.

 

Is something wrong in the setup or is this a normal behaviour and I just need to reconnect the netty client?


@olegchubukov

olegchubukov
21 Sep 2021, 10:07 ( Updated at: 21 Sep 2021, 10:08 )

RE: RE:

amusleh said:

Hi,

You shouldn't use ProtoOAReconcileReq to keep your app up to date with account orders, use it only once and then use execution event to remove/modify/add new account orders.

Regarding Heatbeats, its a response to sending heartbeat, if you don't send any heartbeat you will not receive back an heartbeat message.

You should use a queue to send messages on a specific time interval so you will not reach maximum allowed messages number per second, otherwise you will receive an error message.

Please check our WPF sample code, there we have all of what I just said.

Well, I need to start with saying that I was accidently sending ProtoOAReconcileReq instead of ProtoHeartbeatEvent. Copy/paste... My bad. Is it that's why you commented about ProtoOAReconcileReq?

I have now changed my scheduler to send ProtoHeartbeatEvent and I see ProtoHeartbeatEvent comes every 30 secs again.

But you said that "if you don't send any heartbeat you will not receive back an heartbeat message." This is not true on my side. Even if I dont send a hearbeat, I still receive ProtoHeartbeatEvent every 30 seconds for some period. Sometimes it's 5 minutes, sometimes a couple of hours. But my key point is that ProtoHeartbeatEvent comes without me sending ProtoHeartbeatEvent.

Regarding exceeding the limits, I dont send that many messages to be able to exceed the limits. My application only listens for events.

What is WPF? Is it this source https://github.com/spotware/ctrader-open-api-v2-java-example? If so, that was exactly the code I used.


@olegchubukov

olegchubukov
17 Sep 2021, 10:18

RE:

amusleh said:

Hi,

The response for order filled contains both relative stop loss and relative take profit, here is an actual response for order filled Type:

{
   {
      "ctidTraderAccountId":"532255",
      "executionType":"ORDER_FILLED",
      "position":{
         "positionId":"239668487",
         "tradeData":{
            "symbolId":"1",
            "volume":"100000",
            "tradeSide":"BUY",
            "openTimestamp":"1631861204356",
            "guaranteedStopLoss":false
         },
         "positionStatus":"POSITION_STATUS_OPEN",
         "swap":"0",
         "price":1.1774,
         "utcLastUpdateTimestamp":"1631861204356",
         "commission":"-4",
         "marginRate":1.1774,
         "mirroringCommission":"0",
         "guaranteedStopLoss":false,
         "usedMargin":"235",
         "moneyDigits":2
      },
      "order":{
         "orderId":"359826732",
         "tradeData":{
            "symbolId":"1",
            "volume":"100000",
            "tradeSide":"BUY",
            "openTimestamp":"1631861204118",
            "guaranteedStopLoss":false
         },
         "orderType":"MARKET",
         "orderStatus":"ORDER_STATUS_FILLED",
         "executionPrice":1.1774,
         "executedVolume":"100000",
         "utcLastUpdateTimestamp":"1631861204356",
         "closingOrder":false,
         "clientOrderId":"ctd-1fa7f52eaa5946f0a79b1f18ec6b413d",
         "timeInForce":"IMMEDIATE_OR_CANCEL",
         "positionId":"239668487",
         "relativeStopLoss":"150",
         "relativeTakeProfit":"150",
         "trailingStopLoss":false
      },
      "deal":{
         "dealId":"330052413",
         "orderId":"359826732",
         "positionId":"239668487",
         "volume":"100000",
         "filledVolume":"100000",
         "symbolId":"1",
         "createTimestamp":"1631861204118",
         "executionTimestamp":"1631861204356",
         "utcLastUpdateTimestamp":"1631861204356",
         "executionPrice":1.1774,
         "tradeSide":"BUY",
         "dealStatus":"FILLED",
         "marginRate":1.1774,
         "commission":"-4",
         "baseToUsdConversionRate":1.1774,
         "moneyDigits":2
      },
      "isServerEvent":false
   }
}

You see the order has two fields, one for relative stop loss and another for relative take profit.

Oh, those ones! Great! A bit math and here we go. Didn't get that those numbers were points, not pips. Thank you!


@olegchubukov

olegchubukov
17 Sep 2021, 09:21

RE:

amusleh said:

Try to use Execution event when the type is either OrderFilled or OrderPartialFill, those response types will have stop loss and take profit of the filled order (position).

 

That's exactly the problem. Stoplosses and takeprofits do not come in the ORDER_FILLED event, but in ORDER_ACCEPTED event under order type STOP_LOSS_TAKE_PROFIT.


@olegchubukov

olegchubukov
13 Sep 2021, 10:59 ( Updated at: 21 Dec 2023, 09:22 )

RE:

PanagiotisCharalampous said:

Hi olegchubukov,

Closed trades have nothing to do with historical orders. They can be retrieved using ProtoOADealListReq

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Well, that's what I tried before I asked and got nothing in the deals field. Tried for accountId: 22723160, accountNumber: 3561073

The request is to pick up deals 10 days back from now

 

Result. Deals lsit is empty

 

Positions in cTrader


@olegchubukov

olegchubukov
13 Sep 2021, 10:13

RE:

PanagiotisCharalampous said:

Hi olegchubukov,

No you cannot retrieve historical orders. What kind of statistics would you like to calculate that require you retrieve historical orders?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

For example, create a list with closed trades showing close time, pips and so on.

10.09.2021 09:19:58 #NZDJPY -66 PIPs
11.09.2021 09:21:47 #EURJPY +38 PIPs
12.09.2021 10:26:44 #EURJPY +20 PIPs
13.09.2021 10:50:52 #NZDUSD +20 PIPs
14.09.2021 15:17:52 #EURJPY 0 PIPs


@olegchubukov

olegchubukov
11 Sep 2021, 21:52 ( Updated at: 11 Sep 2021, 21:54 )

 

 


@olegchubukov

olegchubukov
11 Sep 2021, 21:46

RE:

PanagiotisCharalampous said:

Hi BenjaminR,

Historical orders are not available via the Open API. You can only retrieve the pending orders.

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi, Panagiotis

Is this still true that there is no way to retrieve historical orders?

How can I then calculate statistic for a certain period?


@olegchubukov

olegchubukov
09 Sep 2021, 15:05 ( Updated at: 09 Sep 2021, 15:06 )

RE:

amusleh said:

Hi,

Before sending a ProtoOANewOrderReq/ProtoOAClosePositionReq you must be subscribed to ProtoOAExecutionEvent, there is no individual response messages for trading requests, everything related to trading operations will go to the ProtoOAExecutionEvent.

When you receive a ProtoOAExecutionEvent you can check the deal field, this filed is of type ProtoOADeal which has the executionPrice of close price.

For more information regarding closed position you can use the ProtoOADeal closePositionDetail field.

Regarding calculation of P/L, once you got the position volume, entry and close price, you have to calculate each symbol tick value to calculate a position P/L.

You can check our new WPF trading UI Demo, the sample has all these features.

For a tutorial you can check our new documentation symbol data tutorial.

Hi! GitHub url for WPF trading UI Demo, is not found.


@olegchubukov

olegchubukov
26 Aug 2019, 11:48

It works now.

 


@olegchubukov