示例#1
0
        /// <summary>
        /// Create a new order
        /// </summary>
        /// <param name="instrument">Required Instrument to open the order on</param>
        /// <param name="units">Required The number of units to open order for</param>
        /// <param name="side">Required Direction of the order, either "buy" or "sell"</param>
        /// <param name="type">Required The type of the order "limit", "stop", "marketIfTouched’ or "market"</param>
        /// <param name="expiry">Required If order type is "limit", "stop", or "marketIfTouched". The order expiration time in UTC. The value specified must be in a valid datetime format</param>
        /// <param name="price">Required If order type is "limit", "stop", or "marketIfTouched". The price where the order is set to trigger at</param>
        /// <param name="lowerBound">Optional The minimum execution price</param>
        /// <param name="upperBound">Optional The maximum execution price</param>
        /// <param name="stopLoss">The stop loss price</param>
        /// <param name="takeProfit">Optional The take profit price</param>
        /// <param name="trailingStop">Optional The trailing stop distance in pips, up to one decimal place</param>
        /// <returns></returns>
        public async Task <OrderOpen> CreateOrder(string instrument, int units, OandaTypes.Side side,
                                                  OandaTypes.OrderType type, DateTime?expiry, float?price, float?lowerBound, float?upperBound, float?stopLoss, float?takeProfit, float?trailingStop)
        {
            Dictionary <string, string> routeParams = new Dictionary <string, string>();

            routeParams.Add("accountId", _accountId.ToString());

            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties.Add("instrument", instrument);
            properties.Add("units", units.ToString());
            properties.Add("side", side.ToString());
            properties.Add("type", type.ToString());
            if (expiry != null)
            {
                properties.Add("expiry", expiry.Value.ToString("o"));
            }
            if (price != null)
            {
                properties.Add("price", price.ToString());
            }
            if (lowerBound != null)
            {
                properties.Add("lowerBound", lowerBound.ToString());
            }
            if (upperBound != null)
            {
                properties.Add("upperBound", upperBound.ToString());
            }
            if (stopLoss != null)
            {
                properties.Add("stopLoss", stopLoss.ToString());
            }
            if (takeProfit != null)
            {
                properties.Add("takeProfit", takeProfit.ToString());
            }
            if (trailingStop != null)
            {
                properties.Add("trailingStop", trailingStop.ToString());
            }

            if (type == OandaTypes.OrderType.market)
            {
                OrderMarketOpen orderMarket = await Post <OrderMarketOpen>(routeParams, properties, _ordersRoute);

                return(orderMarket);
            }
            else
            {
                OrderCustumOpen customOrder = await Post <OrderCustumOpen>(routeParams, properties, _ordersRoute);

                return(customOrder);
            }
        }
示例#2
0
        /// <summary>
        /// Create a new market order
        /// </summary>
        /// <param name="instrument">Required Instrument to open the order on</param>
        /// <param name="units">Required The number of units to open order for</param>
        /// <param name="side">Required Direction of the order, either "buy" or "sell"</param>
        /// <returns></returns>
        public async Task <OrderMarketOpen> CreateMarketOrder(string instrument, int units, OandaTypes.Side side)
        {
            Dictionary <string, string> routeParams = new Dictionary <string, string>();

            routeParams.Add("accountId", _accountId.ToString());

            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties.Add("instrument", instrument);
            properties.Add("units", units.ToString());
            properties.Add("side", side.ToString());
            properties.Add("type", OandaTypes.OrderType.market.ToString());

            OrderMarketOpen orderMarketOpen = await Post <OrderMarketOpen>(routeParams, properties, _ordersRoute);

            return(orderMarketOpen);
        }