internal void ParseFromMarketOrderPriceZero(OrderSide side) { var order = new OrderUpdate( orderId: 0, tradeId: 0, orderType: Market, orderStatus: New, createdTimestamp: 0, setPrice: 0.4M, side: side, pair: TradingPair.Parse("EOSETH"), setQuantity: 40M) { AverageFilledPrice = 0M, FilledQuantity = 10M, }; var exec = TradeExecution.FromOrder(order); Assert.Equal(exec.From.Locked, decimal.Zero); if (side == OrderSide.Sell) { Assert.Equal(10M, exec.From.Free); Assert.Equal(decimal.Zero, exec.To.Free); } else { Assert.Equal(decimal.Zero, exec.From.Free); Assert.Equal(10M, exec.To.Free); } Assert.Equal(exec.To.Locked, decimal.Zero); }
internal void ParseFromNonMarketBuyOrderForeignCommission(OrderUpdate.OrderTypes type) { var order = new OrderUpdate( orderId: 0, tradeId: 0, orderType: type, orderStatus: Filled, createdTimestamp: 0, setPrice: 0.2M, side: OrderSide.Buy, pair: TradingPair.Parse("EOSETH"), setQuantity: 100M) { FilledQuantity = 100M, AverageFilledPrice = 0.15M, LastFillIncrement = 100M, LastFillPrice = 0.15M, Commission = 96.42M, CommissionAsset = new Currency("BNB"), }; var exec = TradeExecution.FromOrder(order); Assert.Equal(0M, exec.From.Free); Assert.Equal(100M * 0.2M, exec.From.Locked); Assert.Equal(100M, exec.To.Free); Assert.Equal(0M, exec.To.Locked); }
public void ExecuteMarketOrderPartialSellMoreThanOne() { var trading = GetTradingProvider <ExecuteMarketOrderHappyFlowImplementation>(); Assert.Throws <ArgumentOutOfRangeException>( () => trading.ExecutePartialMarketOrderSell(TradingPair.Parse("EOSETH"), 1.00000001M)); }
public void GetFilledBuyStoplossOrderUnMutated() { var order = new OrderUpdate( orderId: 9, tradeId: 8, orderStatus: OrderUpdate.OrderStatus.New, orderType: OrderTypes.StopLoss, createdTimestamp: 302, setPrice: 2.1M, side: OrderSide.Buy, pair: TradingPair.Parse("TRXETH"), setQuantity: 18.6M) { StopPrice = 1.9M, }; var candle = new BacktestingCandle(0, 1, 1, 2, 1, 0, "EOSETH"); GetFilledOrder(order, candle, 434424233); Assert.Equal(OrderStatus.Filled, order.Status); Assert.Equal(OrderTypes.StopLoss, order.OrderType); Assert.Equal(1.9M, order.AverageFilledPrice); Assert.Equal(1.9M, order.LastFillPrice); Assert.Equal(18.6M, order.FilledQuantity); Assert.Equal(18.6M, order.LastFillIncrement); Assert.Equal(434424233, order.FilledTimestamp); }
internal void ParseFromMarketSellOrderNewHappyFlow() { var order = new OrderUpdate( orderId: 0, tradeId: 0, orderType: Market, orderStatus: New, createdTimestamp: 0, setPrice: 0.4M, side: OrderSide.Sell, pair: TradingPair.Parse("EOSETH"), setQuantity: 40M) { FilledQuantity = 40M, AverageFilledPrice = 0.401M, }; var exec = TradeExecution.FromOrder(order); Assert.Equal(order.Pair.Left, exec.From.Symbol); Assert.Equal(order.Pair.Right, exec.To.Symbol); Assert.Equal(40M, exec.From.Free); Assert.Equal(0, exec.From.Locked); Assert.Equal(40M * 0.401M, exec.To.Free); Assert.Equal(0, exec.To.Locked); }
internal void ParseFromNonMarketSellOrderCancelledHappyFlow(OrderUpdate.OrderTypes orderType) { var order = new OrderUpdate( orderId: 0, tradeId: 0, orderType: orderType, orderStatus: Cancelled, createdTimestamp: 0, setPrice: 0.2M, side: OrderSide.Sell, pair: TradingPair.Parse("EOSETH"), setQuantity: 100M); var exec = TradeExecution.FromOrder(order); Assert.NotNull(exec); var symbol = new Currency("EOS"); Assert.Equal(symbol, exec.From.Symbol); Assert.Equal(symbol, exec.To.Symbol); Assert.Equal(0M, exec.From.Free); Assert.Equal(100M, exec.From.Locked); Assert.Equal(100M, exec.To.Free); Assert.Equal(0M, exec.To.Locked); }
public void PlaceLimitPartialBuyNotZero() { var trading = GetTradingProvider <PlaceLimitOrderHappyFlowImplementation>(); Assert.Throws <ArgumentOutOfRangeException>( () => trading.PlacePartialLimitOrderBuy(TradingPair.Parse("EOSETH"), 10M, 0M)); }
public void PlaceLimitOrderNeverConfirmed() { var trading = GetTradingProvider <PlaceLimitOrderNeverConfirmedImplementation>(); Assert.Throws <OrderFailedException>( () => trading.PlaceLimitOrderBuy(TradingPair.Parse("EOSETH"), 10, 1)); }
public void ExecuteMarketOrderNeverFilled() { var trading = GetTradingProvider <ExecuteMarketOrderNeverFilledImplementation>(); Assert.Throws <OrderFailedException>( () => trading.ExecuteMarketOrderBuy(TradingPair.Parse("EOSETH"), 10)); }
public void PlaceLimitPartialSellNotNegative() { var trading = GetTradingProvider <PlaceLimitOrderHappyFlowImplementation>(); Assert.Throws <ArgumentOutOfRangeException>( () => trading.PlacePartialLimitOrderSell(TradingPair.Parse("EOSETH"), 10M, -1M)); }
/// <summary> /// Initializes a new instance of the <see cref="IndicatorCommand{T}"/> class. /// </summary> /// <param name="indicator">The indicator method.</param> /// <param name="inputs">The candles to use indicator over.</param> protected IndicatorCommand(Func <IEnumerable <BacktestingCandle>, T> indicator, params string[] inputs) { _indicator = indicator; if (inputs.Length != 4) { throw new InvalidCommandException($"{GetType().Name} needs exactly 3 arguments"); } try { _pair = TradingPair.Parse(inputs[1]); } catch (Exception) { throw new InvalidCommandException($"{inputs[1]} is not a valid trading pair."); } if (!(long.TryParse(inputs[2], out _epoch) && DateTimeOffset.FromUnixTimeMilliseconds(_epoch) != null)) { throw new InvalidCommandException($"{_epoch} is not a valid ms epoch"); } if (!(int.TryParse(inputs[3], out _n) && _n > 0)) { throw new InvalidCommandException($"{_n} is not a valid value for n"); } }
public void ExecuteMarketOrderPartialBuyNotNegative() { var trading = GetTradingProvider <ExecuteMarketOrderHappyFlowImplementation>(); Assert.Throws <ArgumentOutOfRangeException>( () => trading.ExecutePartialMarketOrderBuy(TradingPair.Parse("EOSETH"), -1M)); }
public CallResult <BinancePlacedOrder> PlaceOrder(string symbol, OrderSide side, OrderType type, decimal quantity, string newClientOrderId = null, decimal?price = null, TimeInForce?timeInForce = null, decimal?stopPrice = null, decimal?icebergQty = null, OrderResponseType?orderResponseType = null, int?receiveWindow = null) { var order = _implementation.PlaceTestOrder(symbol, side, type, quantity, newClientOrderId, price, timeInForce, stopPrice, icebergQty, orderResponseType, receiveWindow); if (order.Success) { var data = order.Data; data.OrderId = _orderIdGenerator.Next(); // PlaceTestOrder does not propagate this data, set it manually. data.Type = type; data.Side = side; var ev = new OrderUpdate( orderId: data.OrderId, tradeId: 0, orderStatus: data.Type == OrderType.Market ? OrderUpdate.OrderStatus.Filled : OrderUpdate.OrderStatus.New, orderType: BinanceUtilities.ToInternal(data.Type), createdTimestamp: 0, setPrice: data.Price, side: BinanceUtilities.ToInternal(data.Side), pair: TradingPair.Parse(symbol), setQuantity: data.OriginalQuantity); _parent.ScheduleObserverEvent(ev); } return(order); }
public void PriceLastTradeNonZero(string input) { var pair = TradingPair.Parse(input); var data = _container.DataProvider; var query = data.GetCurrentPriceTopAsk(pair); Assert.True(query > 0, $"{query} is not a valid price ({pair})"); }
public void PlaceStoplossOrderRefused() { var trading = GetTradingProvider<PlaceStoplossOrderHappyFlowImplementation>(); var c1 = new Currency(TestAllocationManager.RefuseCoin); var c2 = new Currency("ETH"); Assert.Throws<OrderRefusedException>(() => trading.PlaceStoplossSell(TradingPair.Parse(c1, c2), 10, 1)); }
public void LowestAskHigherThanHighestBid(string input) { var pair = TradingPair.Parse(input); var data = _container.DataProvider; var topAsk = data.GetCurrentPriceTopAsk(pair); var topBid = data.GetCurrentPriceTopBid(pair); Assert.True(topAsk >= topBid, $"Top bid is higher than lowest ask (bid: {topBid}, ask: {topAsk}"); }
public void ExecuteMarketOrderRefused() { var trading = GetTradingProvider <ExecuteMarketOrderHappyFlowImplementation>(); var c1 = new Currency(TestAllocationManager.RefuseCoin); var c2 = new Currency("ETH"); Assert.Throws <OrderRefusedException>(() => trading.ExecuteMarketOrderSell(TradingPair.Parse(c1, c2), 10)); }
public void ParsingWithWhitspace() { var pair = GetTradingPair("BNB", "ETH"); TradingPair.AddParseEntry("BNBETH", pair); var parsed = TradingPair.Parse(" BNB ETH "); Assert.Equal(pair.Left, parsed.Left); Assert.Equal(pair.Right, parsed.Right); Assert.Equal(pair.PriceDecimals, parsed.PriceDecimals); }
// [InlineData(1200)] public void GetCandlesHappyFlow(int limit) { var candles = _container.DataProvider.GetCandles( TradingPair.Parse("EOSETH"), limit); Assert.Equal(limit, candles.Length); Assert.All(candles, x => { var unused = x ?? throw new Exception("Some candles where null"); }); }
public void GetCustomCandlesIdentity() { const string source = @" TradingPairs: [EOSETH] CandleWidth: 5 "; var config = ParseAlgorithmConfiguration(source); var data = GetDataProviderWithTimer <DataProviderImplementation, TimerProviderHappyFlowImplementation>(config); var candles = data.GetCandles(TradingPair.Parse("EOSETH"), 1); Assert.Equal(6.6M, candles[0].Close); }
public void ParsingHappyFlow() { var pair = GetTradingPair("BNB", "ETH", 2); TradingPair.AddParseEntry("BNBETH", pair); var parsed = TradingPair.Parse("BNBETH"); Assert.Equal(pair.Left, parsed.Left); Assert.Equal(pair.Right, parsed.Right); Assert.Equal(pair.QuantityDecimals, parsed.QuantityDecimals); Assert.Equal(pair.PriceDecimals, parsed.PriceDecimals); }
public void GetCustomCandlesCorrectAmountPartial() { const string source = @" TradingPairs: [EOSETH] CandleWidth: 15 "; var config = ParseAlgorithmConfiguration(source); var data = GetDataProviderWithTimer <DataProviderImplementation, TimerProviderNoPivotImplementation>(config); var candles = data.GetCandles(TradingPair.Parse("EOSETH"), 3); Assert.Equal(3, candles.Length); }
public void StandardMovingAverageFourCandles() { const string source = @" TradingPairs: [EOSETH] CandleWidth: 15 "; var config = ParseAlgorithmConfiguration(source); var data = GetDataProviderWithTimer <DataProviderImplementation, TimerProviderNoPivotImplementation>(config); var candles = data.GetCandles(TradingPair.Parse("EOSETH"), 4); var sma = candles.StandardMovingAverage(); Assert.Equal(6.5525M, sma); }
public void GetCustomCandlesNoPivotThirtyMinutes() { const string source = @" TradingPairs: [EOSETH] CandleWidth: 30 "; var config = ParseAlgorithmConfiguration(source); var data = GetDataProviderWithTimer <DataProviderImplementation, TimerProviderNoPivotImplementation>(config); var candles = data.GetCandles(TradingPair.Parse("EOSETH"), 2); Assert.Equal(5.6M, candles[0].Close); Assert.Equal(5.7M, candles[1].Close); }
public void AverageTrueRangeSingleEdge() { const string source = @" TradingPairs: [EOSETH] CandleWidth: 25 "; var config = ParseAlgorithmConfiguration(source); var data = GetDataProviderWithTimer <DataProviderImplementation, TimerProviderNoPivotImplementation>(config); var candles = data.GetCandles(TradingPair.Parse("EOSETH"), 2); var atr = candles.AverageTrueRange(); Assert.Equal(2.6M, atr); }
private static OrderUpdate GetSomeOrder(OrderTypes type, decimal setPrice = 0) { return(new OrderUpdate( orderId: 0, tradeId: 0, orderStatus: OrderUpdate.OrderStatus.Filled, orderType: type, createdTimestamp: 0, setPrice: setPrice, side: OrderSide.Buy, pair: TradingPair.Parse("EOSETH"), setQuantity: 0)); }
public void GetCandlesTimestampIncreasing(int limit) { var candles = _container.DataProvider.GetCandles( TradingPair.Parse("EOSETH"), limit); var increment = (long)TimeSpan.FromMinutes((int)Configuration.Instance.CandleWidth).TotalMilliseconds; var diffs = candles.Pairwise((a, b) => b.OpenTimestamp - a.OpenTimestamp); foreach (var diff in diffs) { Assert.Equal(increment, diff); } }
public void LowestLowIsMaximumOfCandleLows() { const string source = @" TradingPairs: [EOSETH] CandleWidth: 5 "; var config = ParseAlgorithmConfiguration(source); var data = GetDataProvider <DataProviderGetCandlesImplementation>(config); var pair = TradingPair.Parse("EOSETH"); var candles = data.GetCandles(pair, 1300); var lowestLow = data.GetLowestLow(pair, 1300); Assert.Equal(candles.Min(x => x.Low), lowestLow); }
public void HighestHighIsMaximumOfCandleHighs() { const string source = @" TradingPairs: [EOSETH] CandleWidth: 5 "; var config = ParseAlgorithmConfiguration(source); var data = GetDataProvider <DataProviderGetCandlesImplementation>(config); var pair = TradingPair.Parse("EOSETH"); var candles = data.GetCandles(pair, 1300); var highestHigh = data.GetHighestHigh(pair, 1300); Assert.Equal(candles.Max(x => x.High), highestHigh); }
public void AddParseEntryOverwrites() { var pre = GetTradingPair("BNB", "ETH", 0, 0); TradingPair.AddParseEntry("BNBETH", pre); var post = GetTradingPair("BNB", "ETH", 1, 1); TradingPair.AddParseEntry("BNBETH", post); var postParse = TradingPair.Parse("BNBETH"); Assert.NotEqual(pre.QuantityDecimals, postParse.QuantityDecimals); Assert.NotEqual(pre.PriceDecimals, postParse.PriceDecimals); }