Пример #1
0
        public Trade CreateMarketEntry(string broker, decimal entryPrice, DateTime entryTime,
                                       TradeDirection direction, decimal amount, string market, string baseAsset,
                                       decimal?stop, decimal?limit,
                                       Timeframe?timeframe = null, string strategies = null, string comments = null, bool alert = false,
                                       CalculateOptions calculateOptions = CalculateOptions.Default,
                                       TradeUpdateMode updateMode        = TradeUpdateMode.Default)
        {
            var trade = new Trade {
                Broker = broker, CalculateOptions = calculateOptions
            };

            if (stop != null)
            {
                trade.AddStopPrice(entryTime, stop.Value);
            }
            if (limit != null)
            {
                trade.AddLimitPrice(entryTime, limit.Value);
            }
            trade.Market         = market;
            trade.BaseAsset      = baseAsset;
            trade.TradeDirection = direction;
            trade.EntryPrice     = entryPrice;
            trade.EntryDateTime  = entryTime;
            trade.EntryQuantity  = amount;
            trade.Timeframe      = timeframe;
            trade.Alert          = alert;
            trade.Comments       = comments;
            trade.Strategies     = strategies;
            trade.UpdateMode     = updateMode;
            return(trade);
        }
Пример #2
0
        public Trade CreateOrder(string broker, decimal entryOrder, Candle latestCandle,
                                 TradeDirection direction, decimal amount, string market, string baseAsset, DateTime?orderExpireTime,
                                 decimal?stop, decimal?limit, CalculateOptions calculateOptions = CalculateOptions.Default)
        {
            var orderDateTime = latestCandle.CloseTime();

            var trade = new Trade {
                CalculateOptions = calculateOptions
            };

            trade.SetOrder(orderDateTime, entryOrder, market, direction, amount, orderExpireTime);
            if (stop != null)
            {
                trade.AddStopPrice(orderDateTime, stop.Value);
            }
            if (limit != null)
            {
                trade.AddLimitPrice(orderDateTime, limit.Value);
            }
            trade.Broker    = broker;
            trade.BaseAsset = baseAsset;

            if (direction == TradeDirection.Long)
            {
                trade.OrderType = (float)entryOrder <= latestCandle.CloseAsk ? OrderType.LimitEntry : OrderType.StopEntry;
            }
            else
            {
                trade.OrderType = (float)entryOrder <= latestCandle.CloseBid ? OrderType.StopEntry : OrderType.LimitEntry;
            }

            return(trade);
        }
        public static void SetTradeLimit(this Trade trade, Candle lastCandle, double price)
        {
            if (trade.CloseDateTime != null)
            {
                MessageBox.Show("Trade is now closed");
                return;
            }

            if (trade.TradeDirection == TradeDirection.Long && ((trade.OrderPrice == null && price < lastCandle.CloseBid) || (trade.OrderPrice != null && trade.EntryPrice == null && (decimal)price < trade.OrderPrice.Value)))
            {
                MessageBox.Show("Invalid limit", "Invalid value", MessageBoxButton.OK);
                return;
            }

            if (trade.TradeDirection == TradeDirection.Short && ((trade.OrderPrice == null && price > lastCandle.CloseAsk) || (trade.OrderPrice != null && trade.EntryPrice == null && (decimal)price > trade.OrderPrice.Value)))
            {
                MessageBox.Show("Invalid limit", "Invalid value", MessageBoxButton.OK);
                return;
            }

            var date = lastCandle.CloseTime();

            if (trade.EntryDateTime != null)
            {
                foreach (var limit in trade.LimitPrices.ToList())
                {
                    if (limit.Date == date)
                    {
                        trade.RemoveLimitPrice(trade.LimitPrices.IndexOf(limit));
                    }
                }

                trade.AddLimitPrice(date, (decimal)price);
            }
            else
            {
                trade.ClearLimitPrices();
                trade.AddLimitPrice(date, (decimal)price);
            }
        }
        public static void ClearLimit(this Trade trade, Candle lastCandle)
        {
            if (trade.CloseDateTime != null)
            {
                MessageBox.Show("Trade is now closed");
                return;
            }

            if (trade.EntryPrice != null)
            {
                MessageBox.Show("Trade is now open so cannot clear limit");
                return;
            }

            if (trade.LimitPrices.Count > 0)
            {
                trade.AddLimitPrice(lastCandle.CloseTime(), null);
            }
        }
Пример #5
0
 public static void AddLimitPrice(this Trade trade, DateTime date, decimal?price)
 {
     trade.AddLimitPrice(string.Empty, date, price);
 }