public static IOrder Create(string type) { IOrder order; switch (type) { case OrderType.Limit: order = new LimitOrder(); break; case OrderType.Market: order = new MarketOrder(); break; case OrderType.MarketIfTouched: order = new MarketIfTouchedOrder(); break; case OrderType.Stop: order = new StopOrder(); break; case OrderType.StopLoss: order = new StopLossOrder(); break; case OrderType.TakeProfit: order = new TakeProfitOrder(); break; case OrderType.TrailingStopLoss: order = new TrailingStopLossOrder(); break; default: order = new Order(); break; } order.type = type; return(order); }
public void Properties() { var user = new Mock <IBinanceApiUser>().Object; var clientOrder = new StopLossOrder(user); Assert.Equal(OrderType.StopLoss, clientOrder.Type); Assert.Equal(0, clientOrder.StopPrice); }
public Trade() { this.Id = new TradeID(); this.Instrument = new InstrumentName(); this.Price = new PriceValue(); this.OpenTime = new DateTime(); this.State = new TradeState(); this.InitialMarginRequired = new AccountUnits(); this.RealizedPL = new AccountUnits(); this.UnrealizedPL = new AccountUnits(); this.MarginUsed = new AccountUnits(); this.AverageClosePrice = new PriceValue(); this.ClosingTransactionIDs = new List <TransactionID>(); this.Financing = new AccountUnits(); this.CloseTime = new DateTime(); this.ClientExtensions = new ClientExtensions(); this.takeProfitOrder = new TakeProfitOrder(); this.StopLossOrder = new StopLossOrder(); this.TrailingStopLossOrder = new TrailingStopLossOrder(); }
public Trade(TradeID id, InstrumentName instrument, PriceValue price, DateTime openTime, TradeState state, double initialUnits, AccountUnits initialMarginRequired, double currentUnits, AccountUnits realizedPL, AccountUnits unrealizedPL, AccountUnits marginUsed, PriceValue averageClosePrice, List <TransactionID> closingTransactionIDs, AccountUnits financing, DateTime closeTime, ClientExtensions clientExtensions, TakeProfitOrder takeProfitOrder, StopLossOrder stopLossOrder, TrailingStopLossOrder trailingStopLossOrder) { this.Id = id; this.Instrument = instrument; this.Price = price; this.OpenTime = openTime; this.State = state; this.InitialUnits = initialUnits; this.InitialMarginRequired = initialMarginRequired; this.CurrentUnits = currentUnits; this.RealizedPL = realizedPL; this.UnrealizedPL = unrealizedPL; this.MarginUsed = marginUsed; this.AverageClosePrice = averageClosePrice; this.ClosingTransactionIDs = closingTransactionIDs; this.Financing = financing; this.CloseTime = closeTime; this.ClientExtensions = clientExtensions; this.takeProfitOrder = takeProfitOrder; this.StopLossOrder = stopLossOrder; this.TrailingStopLossOrder = trailingStopLossOrder; }
public async Task <bool> HandleAsync(string command, CancellationToken token = default) { if (!command.StartsWith("stopLoss ", StringComparison.OrdinalIgnoreCase)) { return(false); } var args = command.Split(' '); if (args.Length < 5) { lock (Program.ConsoleSync) Console.WriteLine("A side, symbol, quantity, and stop price are required."); return(true); } if (!Enum.TryParse(typeof(OrderSide), args[1], true, out var side)) { lock (Program.ConsoleSync) Console.WriteLine("A valid order side is required ('buy' or 'sell')."); return(true); } var symbol = args[2]; if (!decimal.TryParse(args[3], out var quantity) || quantity <= 0) { lock (Program.ConsoleSync) Console.WriteLine("A quantity greater than 0 is required."); return(true); } if (!decimal.TryParse(args[4], out var stopPrice) || stopPrice <= 0) { lock (Program.ConsoleSync) Console.WriteLine("A stop price greater than 0 is required."); return(true); } var clientOrder = new StopLossOrder(Program.User) { Symbol = symbol, Side = (OrderSide)side, Quantity = quantity, StopPrice = stopPrice }; if (Program.IsOrdersTestOnly) { await Program.Api.TestPlaceAsync(clientOrder, token : token); lock (Program.ConsoleSync) { Console.WriteLine($"~ TEST ~ >> STOP LOSS {clientOrder.Side} order (ID: {clientOrder.Id}) placed for {clientOrder.Quantity:0.00000000} {clientOrder.Symbol} @ {clientOrder.StopPrice:0.00000000}"); } } else { var order = await Program.Api.PlaceAsync(clientOrder, token : token); // ReSharper disable once InvertIf if (order != null) { lock (Program.ConsoleSync) { Console.WriteLine($">> STOP LOSS {order.Side} order (ID: {order.Id}) placed for {order.OriginalQuantity:0.00000000} {order.Symbol} @ {order.Price:0.00000000}"); } } } return(true); }