How do I check if Trade.ModifyPosition() was successful?

Created at 22 Oct 2012, 19:54
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!
SC

scalptastic

Joined 15.10.2012

How do I check if Trade.ModifyPosition() was successful?
22 Oct 2012, 19:54


hi upon testing Trade.ModifyPosition(); I see that the call took 1millis; which indicate this method is asynch.

 

so how do I find out if the position was modified successfully; and if not; how do I check for errors?

 

 

 


@scalptastic
Replies

admin
23 Oct 2012, 09:46

The event OnError is triggered if the operation is not successful.

e.g.

protected override void OnError(Error error)

{

Print("There has been an Error");

 

}

 


@admin

scalptastic
23 Oct 2012, 11:32

RE:
admin said:

The event OnError is triggered if the operation is not successful.

e.g.

protected override void OnError(Error error)

{

Print("There has been an Error");

 

}

 

how do I know if the error is related to the modify request and not something else.
 
is there other ways of checking that the order was modified successfully? i.e. will the order characterstics (SL, TP) change after I submit the modify request; or after the modify request has been accepted?
 
for a serious trading system; it is important you provide acks for new orders, modify request and cancel request; and also rejects for each.
 
otherwise; i must say that it is impossible to write a trading system using this platform.

 


@scalptastic

admin
23 Oct 2012, 12:15

Error is an Enum type and you can use it to identify which was the error.

For example you can use this statement:

            switch (error.Code)

            {

                    case ErrorCode.BadVolume: Print("Bad Volume");

                    break;

                    case ErrorCode.TechnicalError:Print("Technical Error");

                    break;

                    case ErrorCode.NoMoney: Print("No Money");

                    break;

                    case ErrorCode.Disconnected: Print("Disconnected");

                    break;

                    case ErrorCode.MarketClosed: Print("Market Closed");

                    break;

            }

If the error is technical then there is a problem with ModifyPosition.

We will add more event handlers very soon, including one to handle the position having been modified. Stay tuned!

 

 


@admin

scalptastic
24 Oct 2012, 18:49

RE:
admin said:

Error is an Enum type and you can use it to identify which was the error.

For example you can use this statement:

            switch (error.Code)

            {

                    case ErrorCode.BadVolume: Print("Bad Volume");

                    break;

                    case ErrorCode.TechnicalError:Print("Technical Error");

                    break;

                    case ErrorCode.NoMoney: Print("No Money");

                    break;

                    case ErrorCode.Disconnected: Print("Disconnected");

                    break;

                    case ErrorCode.MarketClosed: Print("Market Closed");

                    break;

            }

If the error is technical then there is a problem with ModifyPosition.

We will add more event handlers very soon, including one to handle the position having been modified. Stay tuned!

 

 

good to hear thanks; i am waiting :)
 
i think it is also important to block the modify, cancel and close position calls; until they come back. otherwise; we; developers have to write plenty of code to do the same thing.
 
or perhaps provide an option to block the call or not.
 
 
 

@scalptastic

admin
26 Oct 2012, 13:12

If you mean prevent any new requests from the server if there is a current request like to modify or open a position, then you can use this statement:

if (Trade.IsExecuting) return; This will exit the method call each time until the server has responded and thus prevent any further requests from the server.

Otherwise can you give me an example of what you mean? 

 

 


@admin