Add expiration..?

Created at 06 Dec 2013, 15:14
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!
KE

Kevin

Joined 05.12.2013

Add expiration..?
06 Dec 2013, 15:14


How do I add an expiry time of 5 minutes to this:

private void Buy()
        {
            PlaceLimitOrder(TradeType.Buy, Symbol, 10000, Symbol.Bid - 1.5 * Symbol.PipSize);
        }

 

I've toyed around with "DateTime expiry = DateTime.Now.AddMinutes(30);" for ages but i'ts always expecting a "." and extra commands.


@Kevin
Replies

Kevin
06 Dec 2013, 15:16

I have also played around with this:

public TradeResult PlaceLimitOrder(TradeType tradeType, Symbol symbol, long volume, double targetPrice, string label, int? stopLossPips, int? takeProfitPips, DateTime? expiration, string comment)

But keep having the same problem.


@Kevin

Spotware
06 Dec 2013, 16:56

The correct time setting for the expiration should be based on server time instead of local time.

The syntax for the order commands expects the arguments in a certain order. If arguments are to be ommited, a null should be specified in their place.

 DateTime expiry = Server.Time.AddMinutes(5);
 PlaceLimitOrder(TradeType.Buy, Symbol, 10000, Symbol.Bid - 1.5 * Symbol.PipSize, null, null, null, expiry);

See more examples here: /api/robot/placelimitorder-6205


@Spotware

Kevin
06 Dec 2013, 20:35

Aha, I didn't know about the Null bit. It still doesn't like it though:

Error: The type or namespace name 'DateTime' could not be found (are you missing a using directive or an assembly reference?)


@Kevin

Cerunnos
06 Dec 2013, 21:42

RE:

Kevin said:

Aha, I didn't know about the Null bit. It still doesn't like it though:

Error: The type or namespace name 'DateTime' could not be found (are you missing a using directive or an assembly reference?)

Maybe "using system" is missing :-)


@Cerunnos

Kevin
08 Dec 2013, 02:38

Using system..?


@Kevin

Kevin
09 Dec 2013, 00:02

Adding "using System" solves the problem with the buy order, but another fault comes up with the sell order:

 

private void Sell()
        {
            DateTime expiry = Server.Time.AddMinutes(5);
            PlaceLimitOrder(TradeType.Sell, Symbol, 10000, Symbol.Sell + 0.5 * Symbol.PipSize, nullnullnull, expiry);
        }

 

Error: 'cAlgo.API.Internals.Symbol' does not contain a definition for 'Sell" and no extension method 'Sell" accepting a first arguement or type 'cAlgo.API.Internals.Symbol' could not be found (are you missing a using directive o...


@Kevin

Kevin
09 Dec 2013, 00:06

Ahahaha, wow i'm so stupid. Problem solved:

PlaceLimitOrder(TradeType.Sell, Symbol, 10000, Symbol.Sell + 0.5 * Symbol.PipSize, nullnullnull, expiry

I had replaced "Bid" with "Sell" by mistake thinking it said "Buy"


@Kevin