Esempio n. 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);
        }
Esempio n. 2
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)
        {
            if (broker != "Binance")
            {
                throw new ApplicationException("Incorrect broker");
            }
            if (stop != null)
            {
                throw new ApplicationException("Stop needs to be implemented");
            }
            if (limit != null)
            {
                throw new ApplicationException("Limit needs to be implemented");
            }

            var symbol          = GetFullSymbols().First(x => x.Name == market);
            var updatedQuantity = (decimal)((int)(amount / symbol.LotSizeFilter.StepSize)) * symbol.LotSizeFilter.StepSize;

            Log.Info($"{market} Using precision: {symbol.BaseAssetPrecision} and lot size: {symbol.LotSizeFilter.StepSize} updated quantity: {updatedQuantity}");

            var res = _client.Spot.Order.PlaceOrder(
                market,
                direction == TradeDirection.Long ? OrderSide.Buy : OrderSide.Sell,
                OrderType.Market,
                updatedQuantity);

            if (res.Success)
            {
                Log.Info("Market trade created");

                var trade = new Trade
                {
                    Id               = res.Data.OrderId.ToString(),
                    Broker           = Name,
                    CalculateOptions = calculateOptions,
                    Market           = market,
                    BaseAsset        = baseAsset,
                    TradeDirection   = direction,
                    OrderAmount      = updatedQuantity,
                    EntryPrice       = res.Data.AverageFillPrice,
                    EntryDateTime    = res.Data.CreateTime,
                    EntryQuantity    = res.Data.QuantityFilled,
                    Timeframe        = timeframe,
                    Alert            = alert,
                    Comments         = comments,
                    Strategies       = strategies,
                    UpdateMode       = updateMode
                };

                return(trade);
            }
            else
            {
                Log.Info($"Failed to create market trade - {res.Error.Message}");

                return(null);
            }
        }