Exemplo n.º 1
0
        public static Trade CreateOrder(string broker, decimal entryOrder, Candle latestCandle,
                                        TradeDirection direction, decimal amount, string market, 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;

            if (direction == Basics.TradeDirection.Long)
            {
                trade.OrderType = (float)entryOrder <= latestCandle.CloseAsk ? Basics.OrderType.LimitEntry : Basics.OrderType.StopEntry;
            }
            else
            {
                trade.OrderType = (float)entryOrder <= latestCandle.CloseBid ? Basics.OrderType.StopEntry : Basics.OrderType.LimitEntry;
            }
            return(trade);
        }
Exemplo 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)
        {
            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);
        }
Exemplo n.º 3
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)
        {
            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");
            }
            if (orderExpireTime != null)
            {
                throw new ApplicationException("Expire time needs to be implemented");
            }

            var res = _client.Spot.Order.PlaceOrder(
                market,
                direction == TradeDirection.Long ? OrderSide.Buy : OrderSide.Sell,
                OrderType.Limit,
                amount,
                timeInForce: TimeInForce.GoodTillCancel,
                price: entryOrder);

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

                var trade = new Trade
                {
                    Broker           = broker,
                    CalculateOptions = calculateOptions,
                    Market           = market,
                    BaseAsset        = baseAsset,
                    TradeDirection   = direction,
                    Id = res.Data.OrderId.ToString()
                };

                trade.SetOrder(res.Data.CreateTime, entryOrder, market, direction,
                               amount, orderExpireTime);

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

                return(null);
            }
        }
Exemplo n.º 4
0
        public WeeklyReportConfig(string userAgent, long workspaceId, DateTime?since = null,
                                  BillableOptions?billableOptions = null, IList <int> clientIds        = null, IList <int> projectIds         = null,
                                  IList <int> userIds             = null, IList <int> memberOfGroupIds = null, IList <int> orMemberOfGroupIds = null,
                                  IList <int> tagIds        = null, IList <int> taskIds     = null, IList <int> timeEntryIds     = null,
                                  string description        = null, bool withoutDescription = false, WeeklyOrderField?orderField = null,
                                  bool orderDescending      = false, bool distinctRates     = false, bool rounding = false,
                                  DisplayHours?displayHours = null, CalculateOptions calculateOptions = CalculateOptions.Time)
            : base(ReportType.Weekly, userAgent, workspaceId, since, null, billableOptions, clientIds, projectIds,
                   userIds, memberOfGroupIds, orMemberOfGroupIds, tagIds, taskIds, timeEntryIds, description,
                   withoutDescription, orderField?.UrlRepresentation(), orderDescending, distinctRates, rounding,
                   displayHours)
        {
            if (typeof(T).GetCustomAttribute(typeof(ToggleApiUrlValueAttribute)) is ToggleApiUrlValueAttribute
                groupingAttribute)
            {
                UrlParameters.Add("grouping", groupingAttribute.UrlValue);
            }

            UrlParameters.Add("calculate", calculateOptions.UrlRepresentation());
        }
Exemplo n.º 5
0
 public static string UrlRepresentation(this CalculateOptions options)
 {
     return(Enum.GetName(typeof(CalculateOptions), options).ToLowerInvariant());
 }
Exemplo n.º 6
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);
            }
        }