public void AllowsOneActiveOrderPerSymbol(OrderTestParameters parameters) { // tradier's api gets special with zero holdings crossing in that they need to fill the order // before the next can be submitted, so we just limit this impl to only having on active order // by symbol at a time, new orders will issue cancel commands for the existing order bool orderFilledOrCanceled = false; var order = parameters.CreateLongOrder(1); EventHandler <OrderEvent> brokerageOnOrderStatusChanged = (sender, args) => { // we expect all orders to be cancelled except for market orders, they may fill before the next order is submitted if (args.OrderId == order.Id && args.Status == OrderStatus.Canceled || (order is MarketOrder && args.Status == OrderStatus.Filled)) { orderFilledOrCanceled = true; } }; Brokerage.OrderStatusChanged += brokerageOnOrderStatusChanged; // starting from zero initiate two long orders and see that the first is canceled PlaceOrderWaitForStatus(order, OrderStatus.Submitted); PlaceOrderWaitForStatus(parameters.CreateLongMarketOrder(1)); Brokerage.OrderStatusChanged -= brokerageOnOrderStatusChanged; Assert.IsTrue(orderFilledOrCanceled); }
public void LongFromZero(OrderTestParameters parameters) { Log.Trace(""); Log.Trace("LONG FROM ZERO"); Log.Trace(""); PlaceZerodhaOrderWaitForStatus(parameters.CreateLongOrder(GetDefaultQuantity()), parameters.ExpectedStatus); }
public virtual void CloseFromShort(OrderTestParameters parameters) { Log.Trace(""); Log.Trace("CLOSE FROM SHORT"); Log.Trace(""); // first go short PlaceZerodhaOrderWaitForStatus(parameters.CreateShortMarketOrder(GetDefaultQuantity()), OrderStatus.Filled); // now close it PlaceZerodhaOrderWaitForStatus(parameters.CreateLongOrder(GetDefaultQuantity()), parameters.ExpectedStatus); }
public void ReturnLongOrderTakerFees(OrderTestParameters parameters) { IFeeModel feeModel = new BitfinexFeeModel(); Order order = parameters.CreateLongOrder(Quantity); var price = order.Type == OrderType.Limit ? ((LimitOrder)order).LimitPrice : HighPrice; Assert.AreEqual( BitfinexFeeModel.TakerFee * price * Math.Abs(Quantity), feeModel.GetOrderFee(Security, order)); }
public void ReturnLongOrderTakerFees(OrderTestParameters parameters) { IFeeModel feeModel = new BinanceFeeModel(); var order = parameters.CreateLongOrder(Quantity); var price = order.Type == OrderType.Limit ? ((LimitOrder)order).LimitPrice : HighPrice; var fee = feeModel.GetOrderFee(new OrderFeeParameters(Security, order)); Assert.AreEqual( BinanceFeeModel.TakerTier1Fee * price * Math.Abs(Quantity), fee.Value.Amount); Assert.AreEqual("USDT", fee.Value.Currency); }
public void ReturnLongOrderCustomTakerFees(decimal mFee, decimal tFee, OrderTestParameters parameters) { IFeeModel feeModel = new BinanceFeeModel(mFee, tFee); var order = parameters.CreateLongOrder(Quantity); var price = order.Type == OrderType.Limit ? ((LimitOrder)order).LimitPrice : HighPrice; var fee = feeModel.GetOrderFee(new OrderFeeParameters(Security, order)); Assert.AreEqual( tFee * Math.Abs(Quantity), fee.Value.Amount); Assert.AreEqual("ETH", fee.Value.Currency); }
public void ReturnLongFiatCoinFees(OrderTestParameters parameters) { IFeeModel feeModel = new KrakenFeeModel(); Order order = parameters.CreateLongOrder(Quantity); var price = order.Type == OrderType.Limit ? ((LimitOrder)order).LimitPrice : HighPrice; var fee = feeModel.GetOrderFee(new OrderFeeParameters(FiatSecurity, order)); Assert.AreEqual( KrakenFeeModel.Tier1FxFee * price * Math.Abs(Quantity), fee.Value.Amount); Assert.AreEqual(Currencies.USD, fee.Value.Currency); }
public virtual void LongFromShort(OrderTestParameters parameters) { Log.Trace(""); Log.Trace("LONG FROM SHORT"); Log.Trace(""); // first fo short PlaceZerodhaOrderWaitForStatus(parameters.CreateShortMarketOrder(-GetDefaultQuantity()), OrderStatus.Filled); // now go long var order = PlaceZerodhaOrderWaitForStatus(parameters.CreateLongOrder(2 * GetDefaultQuantity()), parameters.ExpectedStatus); if (parameters.ModifyUntilFilled) { ModifyOrderUntilFilled(order, parameters); } }
public void AllowsOneActiveOrderPerSymbol(OrderTestParameters parameters) { // tradier's api gets special with zero holdings crossing in that they need to fill the order // before the next can be submitted, so we just limit this impl to only having on active order // by symbol at a time, new orders will issue cancel commands for the existing order bool orderFilledOrCanceled = false; var order = parameters.CreateLongOrder(1); EventHandler<OrderEvent> brokerageOnOrderStatusChanged = (sender, args) => { // we expect all orders to be cancelled except for market orders, they may fill before the next order is submitted if (args.OrderId == order.Id && args.Status == OrderStatus.Canceled || (order is MarketOrder && args.Status == OrderStatus.Filled)) { orderFilledOrCanceled = true; } }; Brokerage.OrderStatusChanged += brokerageOnOrderStatusChanged; // starting from zero initiate two long orders and see that the first is canceled PlaceOrderWaitForStatus(order, OrderStatus.Submitted); PlaceOrderWaitForStatus(parameters.CreateLongMarketOrder(1)); Brokerage.OrderStatusChanged -= brokerageOnOrderStatusChanged; Assert.IsTrue(orderFilledOrCanceled); }
public void CancelOrders(OrderTestParameters parameters) { const int secondsTimeout = 20; Log.Trace(""); Log.Trace("CANCEL ORDERS"); Log.Trace(""); var order = PlaceZerodhaOrderWaitForStatus(parameters.CreateLongOrder(GetDefaultQuantity()), parameters.ExpectedStatus); var canceledOrderStatusEvent = new ManualResetEvent(false); EventHandler <OrderEvent> orderStatusCallback = (sender, fill) => { if (fill.Status == OrderStatus.Canceled) { canceledOrderStatusEvent.Set(); } }; Brokerage.OrderStatusChanged += orderStatusCallback; var cancelResult = false; try { cancelResult = Brokerage.CancelOrder(order); } catch (Exception exception) { Log.Error(exception); } Assert.AreEqual(IsCancelAsync() || parameters.ExpectedCancellationResult, cancelResult); if (parameters.ExpectedCancellationResult) { // We expect the OrderStatus.Canceled event canceledOrderStatusEvent.WaitOneAssertFail(1000 * secondsTimeout, "Order timedout to cancel"); } var openOrders = Brokerage.GetOpenOrders(); var cancelledOrder = openOrders.FirstOrDefault(x => x.Id == order.Id); Assert.IsNull(cancelledOrder); //canceledOrderStatusEvent.Reset(); //var cancelResultSecondTime = false; //try //{ // cancelResultSecondTime = Brokerage.CancelOrder(order); //} //catch (Exception exception) //{ // Log.Error(exception); //} //Assert.AreEqual(IsCancelAsync(), cancelResultSecondTime); //// We do NOT expect the OrderStatus.Canceled event //Assert.IsFalse(canceledOrderStatusEvent.WaitOne(new TimeSpan(0, 0, 10))); //Brokerage.OrderStatusChanged -= orderStatusCallback; }