internal static void GenerateDayBarMessages(InstrumentOanda instrument, CancellationToken token, GetHistoryDelegate getHistory, Action <QuoteBase> newQuote)
        {
            var param = new HistoryRequestParameters();

            param.Symbol   = instrument.Name.ToUpper();
            param.FromTime = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day).AddDays(-5).AddMilliseconds(-1);
            param.ToTime   = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day);
            GenerateDayBarMessage(param, instrument, token, getHistory, newQuote);
        }
        private static void GenerateDayBarMessage(HistoryRequestParameters param, InstrumentOanda instrument, CancellationToken token, GetHistoryDelegate getHistory, Action <QuoteBase> newQuote)
        {
            try
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }

                param.HistoryType = HistoryDataTypes.Bid;
                param.Period      = (int)HistoryPeriod.Day;

                int count = 5000;
                List <BarHistoryItem> al = getHistory(param, param.FromTime, param.ToTime, (GranularityEnum)GetOandaTimeframe(param.Period), instrument, count);
                if (al == null || al.Count == 0)
                {
                    return;
                }

                if (token.IsCancellationRequested)
                {
                    return;
                }

                InstrumentDayBarMessage msg = new InstrumentDayBarMessage();
                msg.Symbol = param.Symbol;

                var bi0 = al[al.Count - 1];

                if (bi0 == null)
                {
                    return;
                }

                msg.Open  = bi0.Open;
                msg.High  = bi0.High;
                msg.Low   = bi0.Low;
                msg.Ticks = (long)bi0.Volume;

                if (al.Count > 1)
                {
                    msg.PreviousClosePrice = al[al.Count - 2].Close;
                }

                if (token.IsCancellationRequested)
                {
                    return;
                }

                newQuote(msg);
            }
            catch (Exception ex)
            {
            }
        }
        internal static void SetSLTP(Transaction transaction, InstrumentOanda inst, Order order)
        {
            if (transaction.TakeProfitOnFill != null)
            {
                order.TakeProfitPriceType  = CloseOrderPriceType.Absolute;
                order.TakeProfitPriceValue = transaction.TakeProfitOnFill.Price;
            }

            if (transaction.StopLossOnFill != null)
            {
                order.StopLossPriceType  = CloseOrderPriceType.Absolute;
                order.StopLossPriceValue = transaction.StopLossOnFill.Price;
            }

            if (transaction.TrailingStopLossOnFill != null)
            {
                order.StopLossPriceType  = CloseOrderPriceType.TrailingOffset;
                order.StopLossPriceValue = transaction.TrailingStopLossOnFill.Distance / Math.Pow(0.1, inst.DisplayPrecision);
            }
        }