Ejemplo n.º 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="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>
        /// <returns></returns>
        public async Task<OrderMarketIfTouchedOpen> CreateMarketIfTouchedOrder(string instrument, int units, OandaTypes.Side side, DateTime expiry, float price)
        {
            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.marketIfTouched.ToString());
            properties.Add("expiry", expiry.ToString("o"));
            properties.Add("price", price.ToString());

            OrderMarketIfTouchedOpen orderMarketIfTouchedOpen = await Post<OrderMarketIfTouchedOpen>(routeParams, properties, _ordersRoute);

            return orderMarketIfTouchedOpen;
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
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>
        /// <param name="stopLoss">The stop loss price</param>
        /// <param name="takeProfit">Optional The take profit price</param>
        /// <returns></returns>
        public async Task<OrderMarketOpen> CreateMarketOrder(string instrument, int units, OandaTypes.Side side, float stopLoss, float takeProfit)
        {
            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("stopLoss", stopLoss.ToString());
            properties.Add("takeProfit", takeProfit.ToString());
            properties.Add("type", OandaTypes.OrderType.market.ToString());

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

            return orderMarketOpen;
        }
Ejemplo n.º 4
0
        private Dictionary<string, object> MakeCandle(string instrument, OandaTypes.GranularityType? granularity, int? count, DateTime? start, DateTime? end,
            OandaTypes.CandleFormat? candleFormat, bool? includeFirst, byte? dailyAlignment,
            OandaTypes.WeeklyAlignment? weeklyAlignment)
        {

            Dictionary<string, object> fields = new Dictionary<string, object>();

            if (string.IsNullOrWhiteSpace(instrument))
                throw new Exception("The instrument param can't be empty or null");

            fields.Add("instrument", instrument);

            if (granularity == null)
                granularity = OandaTypes.GranularityType.S5;
            fields.Add("granularity", granularity);

            if (count != null && start == null && end == null)
                fields.Add("count", count);

            if (start != null && end != null)
            {
                fields.Add("start", start.Value.ToString("o"));
                fields.Add("end", end.Value.ToString("o"));
            }
            else if (start != null)
            {
                fields.Add("start", start.Value.ToString("o"));
            }

            if (candleFormat != null)
                fields.Add("candleFormat", candleFormat.ToString());

            if (includeFirst == null)
                includeFirst = true;

            if (start != null)
                fields.Add("includeFirst", includeFirst.ToString().ToLower());

            if (dailyAlignment == null)
            {
                dailyAlignment = 22;
            }
            else if (dailyAlignment > 23)
                throw new Exception("The dailyAlignment must be between 0 and 23");

            fields.Add("dailyAlignment", dailyAlignment);

            if (weeklyAlignment == null)
                weeklyAlignment = OandaTypes.WeeklyAlignment.Friday;
            fields.Add("weeklyAlignment", weeklyAlignment.ToString());

            return fields;

        }